Compare commits
2 Commits
81bb792ba7
...
d9d99a2318
| Author | SHA1 | Date | |
|---|---|---|---|
| d9d99a2318 | |||
| 833aac2fbb |
@ -439,6 +439,7 @@ func TestConfigManagerMailSectionAppliesBothPartitionsWithoutMailFile(t *testing
|
||||
t.Fatal(err)
|
||||
}
|
||||
runtime.SMTP.Relay = SMTPConfig{
|
||||
RelayEnabled: true,
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 587,
|
||||
Username: "relay-user",
|
||||
@ -1046,11 +1047,12 @@ func TestConfigManagerSecretClearRequiresExplicitConfirmation(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
runtime := validRuntimeConfig()
|
||||
runtime.SMTP.Relay = SMTPConfig{
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 587,
|
||||
Security: "starttls",
|
||||
From: "no-reply@example.com",
|
||||
FromDomain: "example.com",
|
||||
RelayEnabled: true,
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 587,
|
||||
Security: "starttls",
|
||||
From: "no-reply@example.com",
|
||||
FromDomain: "example.com",
|
||||
}
|
||||
writeRuntimeFixture(t, root, runtime)
|
||||
options := ConfigLoaderOptions{Validation: RuntimeValidationOptions{HasSuperAdmin: true, Production: true}}
|
||||
|
||||
@ -258,6 +258,7 @@ func TestCurrentSMTPRuntimeSettingsReadsPartitionSnapshot(t *testing.T) {
|
||||
|
||||
runtime := validRuntimeConfig()
|
||||
runtime.SMTP.Relay = SMTPConfig{
|
||||
RelayEnabled: true,
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 587,
|
||||
Security: "starttls",
|
||||
@ -300,6 +301,7 @@ func TestCurrentSMTPRuntimeSettingsOpensPartitionPassword(t *testing.T) {
|
||||
}
|
||||
runtime := validRuntimeConfig()
|
||||
runtime.SMTP.Relay = SMTPConfig{
|
||||
RelayEnabled: true,
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 465,
|
||||
Username: "relay-user",
|
||||
@ -350,7 +352,7 @@ func TestCurrentSMTPRuntimeSettingsFallsBackToLegacyConfig(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Password != "relay-password" || got.Relay.Username != "relay-user" || got.Relay.From != "no-reply@example.com" {
|
||||
if got.Password != "relay-password" || got.Relay.RelayEnabled || got.Relay.Username != "relay-user" || got.Relay.From != "no-reply@example.com" {
|
||||
t.Fatalf("legacy SMTP settings = %+v, password=%q", got.Relay, got.Password)
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,10 +168,6 @@ func validateSMTP(smtp SMTPConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func smtpRelayFieldsConfigured(smtp SMTPConfig) bool {
|
||||
return smtp.RelayHost != "" || smtp.Username != "" || smtp.Password.Configured() || smtp.From != ""
|
||||
}
|
||||
|
||||
func smtpRelayConfigured(smtp SMTPConfig) bool {
|
||||
return smtp.RelayEnabled
|
||||
}
|
||||
|
||||
@ -195,21 +195,23 @@ func TestValidateSMTPKeepsLoginVerificationIndependentFromRelay(t *testing.T) {
|
||||
{
|
||||
name: "partially configured relay",
|
||||
smtp: SMTPConfig{
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 587,
|
||||
Security: "starttls",
|
||||
LoginPolicy: "new_device",
|
||||
RelayEnabled: true,
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 587,
|
||||
Security: "starttls",
|
||||
LoginPolicy: "new_device",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "complete relay",
|
||||
smtp: SMTPConfig{
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 587,
|
||||
Security: "starttls",
|
||||
From: "no-reply@example.com",
|
||||
FromDomain: "example.com",
|
||||
LoginPolicy: "new_device",
|
||||
RelayEnabled: true,
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 587,
|
||||
Security: "starttls",
|
||||
From: "no-reply@example.com",
|
||||
FromDomain: "example.com",
|
||||
LoginPolicy: "new_device",
|
||||
},
|
||||
valid: true,
|
||||
},
|
||||
|
||||
@ -43,7 +43,7 @@ func TestVerificationDeliveryDoesNotHidePartialRelayConfiguration(t *testing.T)
|
||||
projectCalled := false
|
||||
delivery := newVerificationDeliveryWithDependencies(
|
||||
func() (config.SMTPRuntimeSettings, error) {
|
||||
return config.SMTPRuntimeSettings{Relay: config.SMTPConfig{RelayHost: "smtp.example.com"}}, nil
|
||||
return config.SMTPRuntimeSettings{Relay: config.SMTPConfig{RelayEnabled: true, RelayHost: "smtp.example.com"}}, nil
|
||||
},
|
||||
func(config.SMTPRuntimeSettings, verification.Challenge, string) error { return expected },
|
||||
func(verification.Challenge, string) error {
|
||||
|
||||
@ -309,7 +309,7 @@ export function updateFormConfig(text, section, path, value) {
|
||||
config.relay.security = relaySecurityForMail(config)
|
||||
config.relay.relayPort = smtpPorts.get(config.relay.security)
|
||||
}
|
||||
if (key.startsWith('relay.') && key !== 'relay.security' && key !== 'relay.enabled' && relayConfigured(config) && ['both', 'starttls', 'implicit_tls'].includes(mailSecurity(config))) {
|
||||
if (key.startsWith('relay.') && key !== 'relay.security' && key !== 'relay.enabled' && config.relay?.enabled === true && relayConfigured(config) && ['both', 'starttls', 'implicit_tls'].includes(mailSecurity(config))) {
|
||||
config.relay.security = relaySecurityForMail(config)
|
||||
if (!validPort(config.relay.relayPort)) config.relay.relayPort = smtpPorts.get(config.relay.security)
|
||||
}
|
||||
@ -368,8 +368,7 @@ export function validateFormConfig(section, config) {
|
||||
}
|
||||
if (section === 'mail') {
|
||||
const relay = config.relay || {}
|
||||
const configured = relayConfigured(config)
|
||||
const enabled = relay.enabled === true || (relay.enabled === undefined && configured)
|
||||
const enabled = relay.enabled === true
|
||||
if (!['both', 'starttls', 'implicit_tls'].includes(mailSecurity(config))) {
|
||||
errors['listener.security'] = '请选择全部启用、STARTTLS / STLS 或隐式 TLS'
|
||||
}
|
||||
|
||||
@ -530,7 +530,7 @@ export function usePage(pageKey = 'base') {
|
||||
delete payload.relay
|
||||
}
|
||||
}
|
||||
if (payload.relay && relayConfigured(payload) && !payload.relay.security) {
|
||||
if (payload.relay && payload.relay.enabled === true && relayConfigured(payload) && !payload.relay.security) {
|
||||
payload.relay.security = relaySecurityForMail(payload)
|
||||
}
|
||||
}
|
||||
|
||||
@ -430,7 +430,7 @@ test('统一加密方式同步切换 SMTP、IMAP、POP3 与已配置中继', ()
|
||||
['starttls', { relay: 587, relaySecurity: 'starttls', smtpStartTLS: 587, smtpTLS: 0, imap: 143, pop3: 110, pop3TLS: 0 }],
|
||||
['implicit_tls', { relay: 465, relaySecurity: 'implicit_tls', smtpStartTLS: 0, smtpTLS: 465, imap: 993, pop3: 0, pop3TLS: 995 }]
|
||||
]) {
|
||||
const config = { generation: 9, listener: { port: 2525, starttlsPort: 2587, tlsPort: 2465 }, imap: { tlsPort: 2993 }, pop3: { port: 2110, tlsPort: 2995 }, relay: { relayHost: 'smtp.example.com', relayPort: 2525, from: 'sender@example.com', fromDomain: 'example.com', future: true } }
|
||||
const config = { generation: 9, listener: { port: 2525, starttlsPort: 2587, tlsPort: 2465 }, imap: { tlsPort: 2993 }, pop3: { port: 2110, tlsPort: 2995 }, relay: { enabled: true, relayHost: 'smtp.example.com', relayPort: 2525, from: 'sender@example.com', fromDomain: 'example.com', future: true } }
|
||||
let text = JSON.stringify(config)
|
||||
getFieldGroups('mail', config)
|
||||
assert.equal(JSON.stringify(config), text)
|
||||
@ -454,12 +454,12 @@ test('统一加密方式同步切换 SMTP、IMAP、POP3 与已配置中继', ()
|
||||
const text = JSON.stringify(untouched)
|
||||
getFieldGroups('mail', untouched)
|
||||
assert.equal(JSON.stringify(untouched), text)
|
||||
const configured = readFormConfig(updateFormConfig(JSON.stringify({ listener: { security: 'starttls' }, relay: {} }), 'mail', ['relay', 'relayHost'], 'smtp.example.com'))
|
||||
const configured = readFormConfig(updateFormConfig(JSON.stringify({ listener: { security: 'starttls' }, relay: { enabled: true } }), 'mail', ['relay', 'relayHost'], 'smtp.example.com'))
|
||||
assert.equal(configured.relay.security, 'starttls')
|
||||
assert.equal(configured.relay.relayPort, 587)
|
||||
assert.deepEqual(validateFormConfig('mail', {
|
||||
listener: { security: 'tls', port: 25, starttlsPort: 0, tlsPort: 465 },
|
||||
relay: { relayHost: 'smtp.example.com', relayPort: 465, security: 'tls', from: 'sender@example.com', fromDomain: 'example.com' },
|
||||
relay: { enabled: true, relayHost: 'smtp.example.com', relayPort: 465, security: 'tls', from: 'sender@example.com', fromDomain: 'example.com' },
|
||||
imap: { tlsPort: 993 }, pop3: { port: 0, tlsPort: 995 }
|
||||
}), {})
|
||||
const defaultsOnly = readFormConfig(updateFormConfig(JSON.stringify({ listener: {}, relay: { fromDomain: 'example.com' } }), 'mail', ['listener', 'security'], 'starttls'))
|
||||
@ -498,9 +498,9 @@ test('加密配置校验拦截监听冲突和未统一的中继加密方式', ()
|
||||
assert.ok(validateFormConfig('base', { http: { port, httpsEnabled: true, httpsPort: 80 } })['http.httpsPort'])
|
||||
}
|
||||
const unified = { ...listeners, listener: { ...listeners.listener, security: 'starttls', tlsPort: 0 }, imap: { tlsPort: 143 }, pop3: { port: 110, tlsPort: 0 } }
|
||||
const errors = validateFormConfig('mail', { ...unified, relay: { relayHost: 'smtp.example.com', security: 'starttls', relayPort: 0, from: 'sender@example.com', fromDomain: 'example.com' } })
|
||||
const errors = validateFormConfig('mail', { ...unified, relay: { enabled: true, relayHost: 'smtp.example.com', security: 'starttls', relayPort: 0, from: 'sender@example.com', fromDomain: 'example.com' } })
|
||||
assert.ok(errors['relay.relayPort'])
|
||||
assert.deepEqual(validateFormConfig('mail', { ...unified, relay: {} }), {})
|
||||
assert.deepEqual(validateFormConfig('mail', { ...unified, relay: { security: 'starttls', relayPort: 2525, relayHost: 'smtp.example.com', from: 'sender@example.com', fromDomain: 'example.com' } }), {})
|
||||
assert.ok(validateFormConfig('mail', { ...unified, relay: { security: 'implicit_tls', relayPort: 465, relayHost: 'smtp.example.com', from: 'sender@example.com', fromDomain: 'example.com' } })['listener.security'])
|
||||
assert.deepEqual(validateFormConfig('mail', { ...unified, relay: { enabled: true, security: 'starttls', relayPort: 2525, relayHost: 'smtp.example.com', from: 'sender@example.com', fromDomain: 'example.com' } }), {})
|
||||
assert.ok(validateFormConfig('mail', { ...unified, relay: { enabled: true, security: 'implicit_tls', relayPort: 465, relayHost: 'smtp.example.com', from: 'sender@example.com', fromDomain: 'example.com' } })['listener.security'])
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user