1 parent
dfd27a34b6
commit
d4c3994102
8 files changed
+123
-28
No files matched your search
@@ -127,6 +127,40 @@ type MailPorts struct {
|
||||
POP3 int
|
||||
}
|
||||
|
||||
type MailDomains struct {
|
||||
Primary string
|
||||
Accepted []string
|
||||
}
|
||||
|
||||
func CurrentMailDomains() MailDomains {
|
||||
manager := CurrentManager()
|
||||
if manager != nil {
|
||||
runtime := manager.Snapshot()
|
||||
if runtime.Generation != 0 {
|
||||
return MailDomains{
|
||||
Primary: runtime.Root.Domains.Primary,
|
||||
Accepted: append([]string(nil), runtime.Root.Domains.Accepted...),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cfg := CurrentConfig()
|
||||
if cfg == nil {
|
||||
return MailDomains{}
|
||||
}
|
||||
domains := MailDomains{
|
||||
Primary: cfg.Domain,
|
||||
Accepted: append([]string(nil), cfg.Domains...),
|
||||
}
|
||||
if domains.Primary == "" && len(domains.Accepted) > 0 {
|
||||
domains.Primary = domains.Accepted[0]
|
||||
}
|
||||
if len(domains.Accepted) == 0 && domains.Primary != "" {
|
||||
domains.Accepted = []string{domains.Primary}
|
||||
}
|
||||
return domains
|
||||
}
|
||||
|
||||
type SMTPRuntimeSettings struct {
|
||||
Relay SMTPConfig
|
||||
Password string
|
||||
|
||||
@@ -129,6 +129,47 @@ func TestCurrentMailPortsUsesDefaultsForUnavailableSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurrentMailDomainsReadsPartitionSnapshot(t *testing.T) {
|
||||
previousManager := CurrentManager()
|
||||
defer SetRuntimeManager(previousManager)
|
||||
|
||||
runtime := validRuntimeConfig()
|
||||
runtime.Root.Domains = DomainConfig{
|
||||
Primary: "partition.example.com",
|
||||
Accepted: []string{"partition.example.com", "alias.example.com"},
|
||||
}
|
||||
SetRuntimeManager(&ConfigManager{snapshots: runtimeAccessSnapshotStore{runtime: runtime}})
|
||||
|
||||
got := CurrentMailDomains()
|
||||
if got.Primary != "partition.example.com" || len(got.Accepted) != 2 || got.Accepted[1] != "alias.example.com" {
|
||||
t.Fatalf("mail domains = %+v, want partition snapshot", got)
|
||||
}
|
||||
|
||||
got.Accepted[0] = "changed.example.com"
|
||||
if runtime.Root.Domains.Accepted[0] != "partition.example.com" {
|
||||
t.Fatal("mail domain snapshot leaked mutable accepted domains")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurrentMailDomainsFallsBackToLegacyConfig(t *testing.T) {
|
||||
previousManager := CurrentManager()
|
||||
previousInstance := Instance
|
||||
defer func() {
|
||||
SetRuntimeManager(previousManager)
|
||||
Instance = previousInstance
|
||||
PublishConfigSnapshot(previousInstance)
|
||||
}()
|
||||
SetRuntimeManager(nil)
|
||||
|
||||
Instance = &Config{Domain: "legacy.example.com"}
|
||||
PublishConfigSnapshot(Instance)
|
||||
|
||||
got := CurrentMailDomains()
|
||||
if got.Primary != "legacy.example.com" || len(got.Accepted) != 1 || got.Accepted[0] != got.Primary {
|
||||
t.Fatalf("legacy mail domains = %+v, want normalized fallback", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurrentSMTPRuntimeSettingsReadsPartitionSnapshot(t *testing.T) {
|
||||
previousManager := CurrentManager()
|
||||
defer SetRuntimeManager(previousManager)
|
||||
|
||||
Reference in new issue
Block a user