生产部署整改阶段检查点
This commit is contained in:
1 parent
f3348cf95d
commit
92d4b3d398
56 files changed
+4178
-240
No files matched your search
@@ -2,6 +2,7 @@ package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -83,6 +84,37 @@ func TestStatusReturnsApplicationAndConfigVersions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicStatusDoesNotExposeInternalConfiguration(t *testing.T) {
|
||||
cfg := readyTestConfig(t.TempDir())
|
||||
cfg.Database.Driver = "mysql"
|
||||
cfg.Server.HTTPSMode = "proxy"
|
||||
server := New(Dependencies{Config: cfg, Repository: &stubDomainRepository{}})
|
||||
response := httptest.NewRecorder()
|
||||
server.Handler().ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/api/v1/status", nil))
|
||||
if response.Code != http.StatusOK {
|
||||
t.Fatalf("公开状态接口响应错误:%d", response.Code)
|
||||
}
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("解析公开状态响应失败:%v", err)
|
||||
}
|
||||
for _, key := range []string{"database_driver", "https_mode", "reset_url"} {
|
||||
if _, exists := payload[key]; exists {
|
||||
t.Fatalf("公开状态接口不应返回内部字段 %s:%s", key, response.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPServerUsesProductionTimeoutsAndTLSMinimum(t *testing.T) {
|
||||
server := newHTTPServer("127.0.0.1:0", http.NewServeMux())
|
||||
if server.ReadHeaderTimeout != 10*time.Second || server.ReadTimeout != 30*time.Second || server.WriteTimeout != 30*time.Second || server.IdleTimeout != 60*time.Second {
|
||||
t.Fatalf("HTTP 服务超时配置不正确:%+v", server)
|
||||
}
|
||||
if server.TLSConfig == nil || server.TLSConfig.MinVersion != tls.VersionTLS12 {
|
||||
t.Fatalf("TLS 最低版本应为 TLS 1.2:%+v", server.TLSConfig)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDomainAPIValidatesSANAndHidesInternalErrors(t *testing.T) {
|
||||
cfg := readyTestConfig(t.TempDir())
|
||||
repo := &stubDomainRepository{}
|
||||
|
||||
Reference in new issue
Block a user