+20
−8
+1
−8
+24
−11
+39
−0
| Original line number | Diff line number | Diff line |
|---|---|---|
package main
|
||
import (
|
||
"reflect"
|
||
"strings"
|
||
"testing"
|
||
"felis.lolicon.best/internal/config"
|
||
"felis.lolicon.best/internal/mail"
|
||
"sigs.k8s.io/yaml"
|
||
)
|
||
| @@ -35,3 +38,39 @@ func TestSMTPSecretManifestCarriesTargetNamespace(t *testing.T) { | ||
}
|
||
}
|
||
}
|
||
// TestSMTPRelayCarriesTLSPosture: the relay felis api, the reaper and the
|
||
// watchdog send through refuses plaintext for a remote host and allows it for
|
||
// one on this host, as [smtp] says.
|
||
func TestSMTPRelayCarriesTLSPosture(t *testing.T) {
|
||
remote := smtpRelay(config.SMTPConfig{Host: "smtp.example.net", Port: 587, From: "[email protected]", Username: "felis"}, "pw")
|
||
want := &mail.SMTP{Host: "smtp.example.net", Port: 587, From: "[email protected]", Username: "felis", Password: "pw", RequireTLS: true}
|
||
if !reflect.DeepEqual(remote, want) {
|
||
t.Errorf("remote relay = %+v, want %+v", remote, want)
|
||
}
|
||
if local := smtpRelay(config.SMTPConfig{Host: "127.0.0.1", Port: 25, From: "[email protected]"}, ""); local.RequireTLS {
|
||
t.Error("a relay on this host must not require TLS by default")
|
||
}
|
||
}
|
||
// TestSetupSMTPConfigKeepsHandSetKeys: re-running the email screen replaces the
|
||
// relay but keeps require_tls and max_per_hour, which only an operator sets.
|
||
func TestSetupSMTPConfigKeepsHandSetKeys(t *testing.T) {
|
||
off := false
|
||
prev := config.SMTPConfig{Host: "old.example.net", Port: 25, From: "[email protected]", MaxPerHour: 500, RequireTLS: &off}
|
||
in := smtpInputs{host: "smtp.example.net", from: "[email protected]", username: "felis"}
|
||
got := setupSMTPConfig(in, 465, prev)
|
||
if got.Host != "smtp.example.net" || got.Port != 465 || got.From != "[email protected]" ||
|
||
got.Username != "felis" || got.PasswordRef != "FELIS_SMTP_PASSWORD" {
|
||
t.Errorf("relay fields = %+v", got)
|
||
}
|
||
if got.MaxPerHour != 500 {
|
||
t.Errorf("max_per_hour = %d, want 500", got.MaxPerHour)
|
||
}
|
||
if got.RequireTLS == nil || *got.RequireTLS {
|
||
t.Errorf("require_tls = %v, want the operator's false", got.RequireTLS)
|
||
}
|
||
if fresh := setupSMTPConfig(in, 587, config.SMTPConfig{}); fresh.RequireTLS != nil || fresh.MaxPerHour != 0 {
|
||
t.Errorf("first setup = %+v, want require_tls and max_per_hour unset", fresh)
|
||
}
|
||
} |
||
+1
−2
Loading