运行时配置清理阶段检查点
This commit is contained in:
1 parent
2851a7a3ff
commit
7d86d01318
80 files changed
+422
-368
No files matched your search
@@ -45,7 +45,7 @@ func TestBuildSetupSSLResponseUsesConfiguredProxyPorts(t *testing.T) {
|
||||
TLSMode: config.HTTPSTLSModeProxy,
|
||||
HTTPSEnabled: false,
|
||||
},
|
||||
"xuans.com",
|
||||
"example.com",
|
||||
true,
|
||||
)
|
||||
|
||||
@@ -55,7 +55,7 @@ func TestBuildSetupSSLResponseUsesConfiguredProxyPorts(t *testing.T) {
|
||||
if response.TLSMode != config.HTTPSTLSModeProxy || response.HTTPSEnabled {
|
||||
t.Fatalf("unexpected proxy settings: mode=%q enabled=%v", response.TLSMode, response.HTTPSEnabled)
|
||||
}
|
||||
if response.WebDomain != "xuans.com" || !response.Ready {
|
||||
if response.WebDomain != "example.com" || !response.Ready {
|
||||
t.Fatalf("unexpected setup response identity: domain=%q ready=%v", response.WebDomain, response.Ready)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ func TestSameOriginUsesTrustedForwardedProto(t *testing.T) {
|
||||
oldManager := config.CurrentManager()
|
||||
config.SetRuntimeManager(nil)
|
||||
config.Instance = &config.Config{
|
||||
WebDomain: "xuans.com",
|
||||
WebDomain: "example.com",
|
||||
TLSMode: config.HTTPSTLSModeProxy,
|
||||
TrustedProxyCIDRs: []string{"127.0.0.1/32"},
|
||||
}
|
||||
@@ -233,11 +233,11 @@ func TestSameOriginUsesTrustedForwardedProto(t *testing.T) {
|
||||
config.SetRuntimeManager(oldManager)
|
||||
})
|
||||
|
||||
request := httptest.NewRequest(http.MethodPost, "http://xuans.com/api/settings", nil)
|
||||
request.Host = "xuans.com"
|
||||
request := httptest.NewRequest(http.MethodPost, "http://example.com/api/settings", nil)
|
||||
request.Host = "example.com"
|
||||
request.RemoteAddr = "127.0.0.1:15184"
|
||||
request.Header.Set("X-Forwarded-Proto", "https")
|
||||
request.Header.Set("Origin", "https://xuans.com")
|
||||
request.Header.Set("Origin", "https://example.com")
|
||||
if requestScheme(request) != "https" || !sameOriginRequest(request) {
|
||||
t.Fatal("trusted HTTPS proxy request was rejected")
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func TestSameOriginDoesNotTrustForwardedProtoFromUntrustedClient(t *testing.T) {
|
||||
oldManager := config.CurrentManager()
|
||||
config.SetRuntimeManager(nil)
|
||||
config.Instance = &config.Config{
|
||||
WebDomain: "xuans.com",
|
||||
WebDomain: "example.com",
|
||||
TLSMode: config.HTTPSTLSModeProxy,
|
||||
TrustedProxyCIDRs: []string{"127.0.0.1/32"},
|
||||
}
|
||||
@@ -257,11 +257,11 @@ func TestSameOriginDoesNotTrustForwardedProtoFromUntrustedClient(t *testing.T) {
|
||||
config.SetRuntimeManager(oldManager)
|
||||
})
|
||||
|
||||
request := httptest.NewRequest(http.MethodPost, "http://xuans.com/api/settings", nil)
|
||||
request.Host = "xuans.com"
|
||||
request := httptest.NewRequest(http.MethodPost, "http://example.com/api/settings", nil)
|
||||
request.Host = "example.com"
|
||||
request.RemoteAddr = "192.0.2.10:15184"
|
||||
request.Header.Set("X-Forwarded-Proto", "https")
|
||||
request.Header.Set("Origin", "https://xuans.com")
|
||||
request.Header.Set("Origin", "https://example.com")
|
||||
if requestScheme(request) != "http" || sameOriginRequest(request) {
|
||||
t.Fatal("untrusted client controlled the forwarded protocol")
|
||||
}
|
||||
@@ -272,7 +272,7 @@ func TestSameOriginRejectsAmbiguousForwardedProto(t *testing.T) {
|
||||
oldManager := config.CurrentManager()
|
||||
config.SetRuntimeManager(nil)
|
||||
config.Instance = &config.Config{
|
||||
WebDomain: "xuans.com",
|
||||
WebDomain: "example.com",
|
||||
TLSMode: config.HTTPSTLSModeProxy,
|
||||
TrustedProxyCIDRs: []string{"127.0.0.1/32"},
|
||||
}
|
||||
@@ -281,11 +281,11 @@ func TestSameOriginRejectsAmbiguousForwardedProto(t *testing.T) {
|
||||
config.SetRuntimeManager(oldManager)
|
||||
})
|
||||
|
||||
request := httptest.NewRequest(http.MethodPost, "http://xuans.com/api/settings", nil)
|
||||
request.Host = "xuans.com"
|
||||
request := httptest.NewRequest(http.MethodPost, "http://example.com/api/settings", nil)
|
||||
request.Host = "example.com"
|
||||
request.RemoteAddr = "127.0.0.1:15184"
|
||||
request.Header.Set("X-Forwarded-Proto", "https, http")
|
||||
request.Header.Set("Origin", "https://xuans.com")
|
||||
request.Header.Set("Origin", "https://example.com")
|
||||
if requestScheme(request) != "http" || sameOriginRequest(request) {
|
||||
t.Fatal("ambiguous forwarded protocol was trusted")
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func TestHttpsStartSkipsListenerInProxyMode(t *testing.T) {
|
||||
oldManager := config.CurrentManager()
|
||||
config.SetRuntimeManager(nil)
|
||||
config.Instance = &config.Config{
|
||||
WebDomain: "xuans.com",
|
||||
WebDomain: "example.com",
|
||||
TLSMode: config.HTTPSTLSModeProxy,
|
||||
HttpsEnabled: 1,
|
||||
HttpsPort: 443,
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestProxyHTTPHandlerServesBusinessRoutesWithoutRedirect(t *testing.T) {
|
||||
oldManager := config.CurrentManager()
|
||||
oldSession := session.Instance
|
||||
config.SetRuntimeManager(nil)
|
||||
config.Instance = &config.Config{WebDomain: "xuans.com", TLSMode: config.HTTPSTLSModeProxy}
|
||||
config.Instance = &config.Config{WebDomain: "example.com", TLSMode: config.HTTPSTLSModeProxy}
|
||||
session.Instance = scs.New()
|
||||
t.Cleanup(func() {
|
||||
config.Instance = oldConfig
|
||||
@@ -45,7 +45,7 @@ func TestProxyHTTPHandlerServesBusinessRoutesWithoutRedirect(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
recorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "http://xuans.com/", nil))
|
||||
handler.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "http://example.com/", nil))
|
||||
if recorder.Code == http.StatusPermanentRedirect || recorder.Code == http.StatusTemporaryRedirect {
|
||||
t.Fatalf("proxy HTTP handler redirected the request: %d", recorder.Code)
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func TestDirectHTTPHandlerKeepsHTTPSRedirect(t *testing.T) {
|
||||
oldConfig := config.Instance
|
||||
oldManager := config.CurrentManager()
|
||||
config.SetRuntimeManager(nil)
|
||||
config.Instance = &config.Config{WebDomain: "xuans.com", HttpsEnabled: 1, HttpsPort: 443}
|
||||
config.Instance = &config.Config{WebDomain: "example.com", HttpsEnabled: 1, HttpsPort: 443}
|
||||
t.Cleanup(func() {
|
||||
config.Instance = oldConfig
|
||||
config.SetRuntimeManager(oldManager)
|
||||
@@ -66,8 +66,8 @@ func TestDirectHTTPHandlerKeepsHTTPSRedirect(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
recorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "http://xuans.com/inbox", nil))
|
||||
if recorder.Code != http.StatusPermanentRedirect || recorder.Header().Get("Location") != "https://xuans.com/inbox" {
|
||||
handler.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "http://example.com/inbox", nil))
|
||||
if recorder.Code != http.StatusPermanentRedirect || recorder.Header().Get("Location") != "https://example.com/inbox" {
|
||||
t.Fatalf("unexpected direct HTTP redirect: status=%d location=%q", recorder.Code, recorder.Header().Get("Location"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,13 +99,13 @@ func TestResolveIdentifierFallbackToConfiguredDomainUser(t *testing.T) {
|
||||
config.Instance = &config.Config{
|
||||
DbType: config.DBTypeSQLite,
|
||||
DbDSN: filepath.Join(t.TempDir(), "domain_fallback.db"),
|
||||
Domain: "solit.cn",
|
||||
Domains: []string{"solit.cn"},
|
||||
Domain: "example.com",
|
||||
Domains: []string{"example.com"},
|
||||
}
|
||||
if err := db.Init(""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, err := NormalizeProtocolIdentifier(" Bob@Solit.cn "); err != nil || got != "bob@solit.cn" {
|
||||
if got, err := NormalizeProtocolIdentifier(" Bob@Example.com "); err != nil || got != "bob@example.com" {
|
||||
t.Fatalf("normalized protocol identifier = %q, err = %v", got, err)
|
||||
}
|
||||
for _, identifier := range []string{"bob", "bob@other.com"} {
|
||||
@@ -129,11 +129,11 @@ func TestResolveIdentifierFallbackToConfiguredDomainUser(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
identity, err := ResolveIdentifier(" Bob@Solit.cn ")
|
||||
identity, err := ResolveIdentifier(" Bob@Example.com ")
|
||||
if err != nil {
|
||||
t.Fatalf("resolve configured domain user failed: %v", err)
|
||||
}
|
||||
if identity.Kind != IdentifierEmail || identity.UserID != user.ID || identity.Account != "bob" || identity.LoginAddress != "bob@solit.cn" {
|
||||
if identity.Kind != IdentifierEmail || identity.UserID != user.ID || identity.Account != "bob" || identity.LoginAddress != "bob@example.com" {
|
||||
t.Fatalf("unexpected resolved identity: %+v", identity)
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func TestResolveIdentifierFallbackToConfiguredDomainUser(t *testing.T) {
|
||||
if _, err := db.Instance.Insert(&disabledUser); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ResolveIdentifier("charlie@solit.cn"); err == nil {
|
||||
if _, err := ResolveIdentifier("charlie@example.com"); err == nil {
|
||||
t.Fatal("disabled domain user must not be resolved")
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,13 @@ func TestWildcardCertificateDomains(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "configured domain",
|
||||
config: &config.Config{Domain: "xuans.com", WebDomain: "web.xuans.com", Domains: []string{"xuans.com", "other.example"}},
|
||||
want: []string{"xuans.com", "*.xuans.com"},
|
||||
config: &config.Config{Domain: "example.com", WebDomain: "web.example.com", Domains: []string{"example.com", "other.example"}},
|
||||
want: []string{"example.com", "*.example.com"},
|
||||
},
|
||||
{
|
||||
name: "trimmed wildcard domain",
|
||||
config: &config.Config{Domain: " *.xuans.com. "},
|
||||
want: []string{"xuans.com", "*.xuans.com"},
|
||||
config: &config.Config{Domain: " *.example.com. "},
|
||||
want: []string{"example.com", "*.example.com"},
|
||||
},
|
||||
{
|
||||
name: "case normalized domain",
|
||||
@@ -57,9 +57,9 @@ func TestWildcardCertificateDomains(t *testing.T) {
|
||||
|
||||
func TestCertificateDomainsFollowChallengeMode(t *testing.T) {
|
||||
cfg := &config.Config{
|
||||
Domain: "xuans.com",
|
||||
WebDomain: "web.xuans.com",
|
||||
Domains: []string{"xuans.com"},
|
||||
Domain: "example.com",
|
||||
WebDomain: "web.example.com",
|
||||
Domains: []string{"example.com"},
|
||||
}
|
||||
|
||||
cfg.SSLType = config.SSLTypeAutoHTTP
|
||||
@@ -67,13 +67,13 @@ func TestCertificateDomainsFollowChallengeMode(t *testing.T) {
|
||||
if len(httpDomains) != 5 {
|
||||
t.Fatalf("got %d HTTP domains, want 5: %v", len(httpDomains), httpDomains)
|
||||
}
|
||||
if httpDomains[0] != "web.xuans.com" || httpDomains[1] != "xuans.com" || httpDomains[2] != "smtp.xuans.com" {
|
||||
if httpDomains[0] != "web.example.com" || httpDomains[1] != "example.com" || httpDomains[2] != "smtp.example.com" {
|
||||
t.Fatalf("unexpected HTTP domains: %v", httpDomains)
|
||||
}
|
||||
|
||||
cfg.SSLType = config.SSLTypeAutoDNS
|
||||
dnsDomains := certificateDomains(cfg)
|
||||
if len(dnsDomains) != 2 || dnsDomains[0] != "xuans.com" || dnsDomains[1] != "*.xuans.com" {
|
||||
if len(dnsDomains) != 2 || dnsDomains[0] != "example.com" || dnsDomains[1] != "*.example.com" {
|
||||
t.Fatalf("unexpected DNS domains: %v", dnsDomains)
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func TestDNSWildcardIgnoresLegacyAdminRecoveryDomain(t *testing.T) {
|
||||
|
||||
func TestDNSChallengeWildcardProducesSingleRecord(t *testing.T) {
|
||||
challenge := &DNSChallenge{authInfo: map[string]*authInfo{}}
|
||||
if err := challenge.Present("*.xuans.com", "token", "key-auth"); err != nil {
|
||||
if err := challenge.Present("*.example.com", "token", "key-auth"); err != nil {
|
||||
t.Fatalf("Present returned an error: %v", err)
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ func TestDNSChallengeWildcardProducesSingleRecord(t *testing.T) {
|
||||
if records[0].Type != "TXT" {
|
||||
t.Fatalf("got record type %q, want TXT", records[0].Type)
|
||||
}
|
||||
if strings.TrimSuffix(records[0].Host, ".") != "_acme-challenge.xuans.com" {
|
||||
t.Fatalf("got record host %q, want _acme-challenge.xuans.com", records[0].Host)
|
||||
if strings.TrimSuffix(records[0].Host, ".") != "_acme-challenge.example.com" {
|
||||
t.Fatalf("got record host %q, want _acme-challenge.example.com", records[0].Host)
|
||||
}
|
||||
if records[0].Value == "" {
|
||||
t.Fatal("DNS record value must not be empty")
|
||||
|
||||
@@ -114,15 +114,15 @@ func TestAllowUnsafeSMTPRequiresExplicitLoopbackTestTarget(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIsConfiguredMailDomain(t *testing.T) {
|
||||
accepted := []string{"cdis.cn", "alias.cdis.cn"}
|
||||
accepted := []string{"example.com", "alias.example.com"}
|
||||
tests := []struct {
|
||||
name string
|
||||
domain string
|
||||
want bool
|
||||
}{
|
||||
{name: "primary domain", domain: "cdis.cn", want: true},
|
||||
{name: "case insensitive domain", domain: "CDIS.CN", want: true},
|
||||
{name: "accepted alias", domain: "alias.cdis.cn", want: true},
|
||||
{name: "primary domain", domain: "example.com", want: true},
|
||||
{name: "case insensitive domain", domain: "EXAMPLE.COM", want: true},
|
||||
{name: "accepted alias", domain: "alias.example.com", want: true},
|
||||
{name: "external domain", domain: "example.com"},
|
||||
{name: "empty domain"},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user