|
@@ -39,6 +39,12 @@ var blockMalicious = []string{
|
|
|
"- spammer@",
|
|
|
}
|
|
|
|
|
|
+func filterExpect(t *testing.T, address string, expect bool) {
|
|
|
+ if isAddressAllowed(address) != expect {
|
|
|
+ t.Fatalf("Address %q block: expected %t got %t", address, expect, !expect)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// Writes the filters to a file in the specified custom directory. This file needs to
|
|
|
// be cleaned up afterwards. Returns the full path to the written file as string.
|
|
|
func writeCustomDirFilterFile(t *testing.T, filters []string) string {
|
|
@@ -78,18 +84,11 @@ func TestAllowGNodeFilter(t *testing.T) {
|
|
|
defer os.Remove(ffile)
|
|
|
|
|
|
for _, address := range emails {
|
|
|
- if isAddressAllowed(address) {
|
|
|
- t.Fatalf("Address %q should be blocked but was allowed", address)
|
|
|
- }
|
|
|
+ filterExpect(t, address, false)
|
|
|
}
|
|
|
|
|
|
- if !isAddressAllowed("me@g-node.org") {
|
|
|
- t.Fatalf("G-Node address blocked but should be allowed")
|
|
|
- }
|
|
|
-
|
|
|
- if isAddressAllowed("malicious@g-node.org@piracy.tk") {
|
|
|
- t.Fatalf("Malicious address should be blocked but was allowed")
|
|
|
- }
|
|
|
+ filterExpect(t, "me@g-node.org", true)
|
|
|
+ filterExpect(t, "malicious@g-node.org@piracy.tk", false)
|
|
|
}
|
|
|
|
|
|
func TestEverythingFilters(t *testing.T) {
|
|
@@ -104,20 +103,14 @@ func TestEverythingFilters(t *testing.T) {
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
|
|
for idx := 0; idx < 100; idx++ {
|
|
|
- randress := randAddress()
|
|
|
- if !isAddressAllowed(randAddress()) {
|
|
|
- t.Fatalf("Address %q should be allowed but was blocked", randress)
|
|
|
- }
|
|
|
+ filterExpect(t, randAddress(), true)
|
|
|
}
|
|
|
|
|
|
ffile = writeCustomDirFilterFile(t, blockEverythingFilter)
|
|
|
defer os.Remove(ffile)
|
|
|
|
|
|
for idx := 0; idx < 100; idx++ {
|
|
|
- randress := randAddress()
|
|
|
- if isAddressAllowed(randAddress()) {
|
|
|
- t.Fatalf("Address %q should be blocked but was allowed", randress)
|
|
|
- }
|
|
|
+ filterExpect(t, randAddress(), false)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -131,25 +124,12 @@ func TestBlockDomainFilter(t *testing.T) {
|
|
|
defer os.Remove(ffile)
|
|
|
|
|
|
// 0, 3 should be allowed; 1, 2 should be blocked
|
|
|
- if address := emails[0]; !isAddressAllowed(address) {
|
|
|
- t.Fatalf("Address %q should be allowed but was blocked", address)
|
|
|
- }
|
|
|
-
|
|
|
- if address := emails[1]; isAddressAllowed(address) {
|
|
|
- t.Fatalf("Address %q should be blocked but was allowed", address)
|
|
|
- }
|
|
|
-
|
|
|
- if address := emails[2]; isAddressAllowed(address) {
|
|
|
- t.Fatalf("Address %q should be blocked but was allowed", address)
|
|
|
- }
|
|
|
-
|
|
|
- if address := emails[3]; !isAddressAllowed(address) {
|
|
|
- t.Fatalf("Address %q should be allowed but was blocked", address)
|
|
|
- }
|
|
|
+ filterExpect(t, emails[0], true)
|
|
|
+ filterExpect(t, emails[1], false)
|
|
|
+ filterExpect(t, emails[2], false)
|
|
|
+ filterExpect(t, emails[3], true)
|
|
|
}
|
|
|
|
|
|
func TestFiltersNone(t *testing.T) {
|
|
|
- if address := emails[3]; !isAddressAllowed(address) {
|
|
|
- t.Fatalf("Address %q should be allowed but was blocked", address)
|
|
|
- }
|
|
|
+ filterExpect(t, emails[3], true)
|
|
|
}
|