1 parent
fd2e703b2c
commit
2e4813ec92
11 files changed
+660
-34
No files matched your search
@@ -42,6 +42,9 @@ func configErrorDetails(err error) (string, int, string, map[string]string) {
|
||||
status := http.StatusBadRequest
|
||||
message := "配置请求未完成"
|
||||
fields := map[string]string(nil)
|
||||
if issue, ok := config.SSLValidationIssue(err); ok {
|
||||
return issue.Code, http.StatusUnprocessableEntity, issue.Message, nil
|
||||
}
|
||||
|
||||
var denial *access.Denial
|
||||
switch {
|
||||
|
||||
@@ -2,6 +2,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
@@ -14,6 +15,15 @@ import (
|
||||
"git.pcux.cn/xuans/Smail/services/dbmigration"
|
||||
)
|
||||
|
||||
func TestConfigSSLErrorUsesSafeSpecificMessage(t *testing.T) {
|
||||
for _, failure := range []error{config.ErrSSLFileUnavailable, config.ErrSSLCertificateMismatch, config.ErrSSLCertificateExpired, config.ErrSSLCertificateDomain, config.ErrInvalidSSLReference} {
|
||||
code, status, message, _ := configErrorDetails(fmt.Errorf("%w: /private/internal-path", failure))
|
||||
if code != "SSL_INVALID" || status != http.StatusUnprocessableEntity || message == "" || strings.Contains(message, "/private/") || strings.Contains(message, "配置校验未通过") {
|
||||
t.Fatalf("证书错误未正确脱敏或区分: %s %d %s", code, status, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteConfigErrorKeepsStableAuthorizationCode(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
writeConfigError(recorder, &access.Denial{Code: access.CodeRecoveryCodeRequired})
|
||||
|
||||
Reference in new issue
Block a user