补充 DNS 验证等待测试
This commit is contained in:
1 parent
ddbf3b2d29
commit
519a538755
6 files changed
+149
-18
No files matched your search
@@ -55,10 +55,10 @@ func TestAdminDNSTestReturnsVerificationResult(t *testing.T) {
|
||||
t.Fatalf("DNS 在线测试失败:%d %s", response.Code, response.Body.String())
|
||||
}
|
||||
var payload struct {
|
||||
Verified bool `json:"verified"`
|
||||
CredentialRef string `json:"credential_ref"`
|
||||
VerificationToken string `json:"verification_token"`
|
||||
TestReport setup.DNSVerificationReport `json:"test_report"`
|
||||
Verified bool `json:"verified"`
|
||||
CredentialRef string `json:"credential_ref"`
|
||||
VerificationToken string `json:"verification_token"`
|
||||
TestReport setup.DNSVerificationReport `json:"test_report"`
|
||||
VerificationTimeoutSecs int `json:"verification_timeout_secs"`
|
||||
}
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &payload); err != nil {
|
||||
@@ -80,4 +80,7 @@ func TestAdminDNSTestRejectsUnavailableService(t *testing.T) {
|
||||
if response.Code != http.StatusServiceUnavailable {
|
||||
t.Fatalf("DNS 服务未初始化时应返回 503,实际为 %d:%s", response.Code, response.Body.String())
|
||||
}
|
||||
if !strings.Contains(response.Body.String(), `"verification_timeout_secs":930`) {
|
||||
t.Fatalf("DNS 服务未初始化响应应包含当前最大等待时间:%s", response.Body.String())
|
||||
}
|
||||
}
|
||||
@@ -159,12 +159,12 @@ func (s *Server) testAdminDNS(c *gin.Context) {
|
||||
func (s *Server) testDNS(c *gin.Context) {
|
||||
verificationTimeoutSecs := int(s.dnsVerificationTimeout().Seconds())
|
||||
if s.setupDNS == nil {
|
||||
s.writeError(c, http.StatusServiceUnavailable, "DNS 在线验证服务尚未初始化", nil)
|
||||
s.writeDNSTestError(c, http.StatusServiceUnavailable, "DNS 在线验证服务尚未初始化", nil, verificationTimeoutSecs)
|
||||
return
|
||||
}
|
||||
var request dnsTestRequest
|
||||
if err := bindJSON(c, &request, setupRequestLimit); err != nil {
|
||||
s.writeError(c, http.StatusBadRequest, "DNS 测试请求参数无效", err)
|
||||
s.writeDNSTestError(c, http.StatusBadRequest, "DNS 测试请求参数无效", err, verificationTimeoutSecs)
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), s.dnsVerificationTimeout())
|
||||
@@ -206,6 +206,16 @@ func (s *Server) testDNS(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) writeDNSTestError(c *gin.Context, status int, message string, err error, verificationTimeoutSecs int) {
|
||||
if s.logger != nil {
|
||||
s.logger.Error(message, "error", err)
|
||||
}
|
||||
c.JSON(status, gin.H{
|
||||
"error": message,
|
||||
"verification_timeout_secs": verificationTimeoutSecs,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) dnsVerificationTimeout() time.Duration {
|
||||
s.configMu.RLock()
|
||||
cfg := s.config
|
||||
|
||||
@@ -527,6 +527,9 @@ func TestSetupDNSTestRejectsRemoteAndOversizedRequests(t *testing.T) {
|
||||
if oversizedResponse.Code != http.StatusBadRequest {
|
||||
t.Fatalf("超大 DNS 测试请求应被拒绝:%d %s", oversizedResponse.Code, oversizedResponse.Body.String())
|
||||
}
|
||||
if !strings.Contains(oversizedResponse.Body.String(), `"verification_timeout_secs":930`) {
|
||||
t.Fatalf("DNS 参数错误响应应包含当前最大等待时间:%s", oversizedResponse.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupDNSTestReturnsNotImplementedForUnavailableProvider(t *testing.T) {
|
||||
@@ -544,6 +547,9 @@ func TestSetupDNSTestReturnsNotImplementedForUnavailableProvider(t *testing.T) {
|
||||
if strings.Contains(response.Body.String(), "access_key_secret") || strings.Contains(response.Body.String(), "secret") {
|
||||
t.Fatal("未开放 Provider 响应不应包含提交的凭据")
|
||||
}
|
||||
if !strings.Contains(response.Body.String(), `"verification_timeout_secs":930`) {
|
||||
t.Fatalf("未开放 Provider 响应应包含当前最大等待时间:%s", response.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupValidationFailureDoesNotConsumeDNSToken(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user