1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

policy: Implement store domain policy for #51

- Update docs, change log, status.html
This commit is contained in:
James Hillyerd
2018-04-01 19:46:44 -07:00
parent a7d2b00a9c
commit 064549f576
9 changed files with 91 additions and 53 deletions

View File

@@ -50,10 +50,14 @@ func (a *Addressing) ShouldAcceptDomain(domain string) bool {
return false
}
// ShouldStoreDomain indicates if Inbucket stores email destined for the specified domain.
// ShouldStoreDomain indicates if Inbucket stores mail destined for the specified domain.
func (a *Addressing) ShouldStoreDomain(domain string) bool {
if a.Config.StoreMessages {
return strings.ToLower(domain) != strings.ToLower(a.Config.DomainNoStore)
domain = strings.ToLower(domain)
if a.Config.DefaultStore && !stringutil.SliceContains(a.Config.DiscardDomains, domain) {
return true
}
if !a.Config.DefaultStore && stringutil.SliceContains(a.Config.StoreDomains, domain) {
return true
}
return false
}

View File

@@ -65,24 +65,24 @@ func TestShouldStoreDomain(t *testing.T) {
// Test with storage enabled.
ap := &policy.Addressing{
Config: config.SMTP{
DomainNoStore: "Foo.Com",
StoreMessages: true,
DefaultStore: false,
StoreDomains: []string{"store.com", "a.store.com"},
},
}
testCases := []struct {
domain string
want bool
}{
{domain: "bar.com", want: true},
{domain: "foo.com", want: false},
{domain: "FOO.com", want: false},
{domain: "bar.foo.com", want: true},
{domain: "STORE.com", want: true},
{domain: "a.store.com", want: true},
{domain: "b.store.com", want: false},
}
for _, tc := range testCases {
t.Run(tc.domain, func(t *testing.T) {
got := ap.ShouldStoreDomain(tc.domain)
if got != tc.want {
t.Errorf("Got %v for %q, want: %v", got, tc.domain, tc.want)
t.Errorf("Got store %v for %q, want: %v", got, tc.domain, tc.want)
}
})
@@ -90,23 +90,24 @@ func TestShouldStoreDomain(t *testing.T) {
// Test with storage disabled.
ap = &policy.Addressing{
Config: config.SMTP{
StoreMessages: false,
DefaultStore: true,
DiscardDomains: []string{"discard.com", "a.discard.com"},
},
}
testCases = []struct {
domain string
want bool
}{
{domain: "bar.com", want: false},
{domain: "foo.com", want: false},
{domain: "FOO.com", want: false},
{domain: "bar.foo.com", want: false},
{domain: "foo.com", want: true},
{domain: "DISCARD.com", want: false},
{domain: "a.discard.com", want: false},
{domain: "b.discard.com", want: true},
}
for _, tc := range testCases {
t.Run(tc.domain, func(t *testing.T) {
got := ap.ShouldStoreDomain(tc.domain)
if got != tc.want {
t.Errorf("Got %v for %q, want: %v", got, tc.domain, tc.want)
t.Errorf("Got store %v for %q, want: %v", got, tc.domain, tc.want)
}
})