summaryrefslogtreecommitdiff
path: root/internal/cache/domain/domain_test.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-01-09 13:12:43 +0000
committerLibravatar GitHub <noreply@github.com>2024-01-09 13:12:43 +0000
commitdfc7656579349bda98d3097c473efbb6000e233b (patch)
tree804e32acb98d8a92d90a8f67ab40b9fa70bd120a /internal/cache/domain/domain_test.go
parentBump follow-redirects from 1.15.3 to 1.15.4 in /web/source (#2512) (diff)
downloadgotosocial-dfc7656579349bda98d3097c473efbb6000e233b.tar.xz
[bugfix] fix higher-level explicit domain rules causing issues with lower-level domain blocking (#2513)
* fix the sort direction of domain cache child nodes ... * add more domain cache test cases * add specific test for this bug to database domain test suite (thanks for writing this @tsmethurst!) * remove unused field (this was a previous attempt at a fix) * remove debugging println statements :innocent:
Diffstat (limited to 'internal/cache/domain/domain_test.go')
-rw-r--r--internal/cache/domain/domain_test.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/internal/cache/domain/domain_test.go b/internal/cache/domain/domain_test.go
index 9e091e1d0..974425b7c 100644
--- a/internal/cache/domain/domain_test.go
+++ b/internal/cache/domain/domain_test.go
@@ -28,9 +28,13 @@ func TestCache(t *testing.T) {
c := new(domain.Cache)
cachedDomains := []string{
- "google.com",
- "google.co.uk",
- "pleroma.bad.host",
+ "google.com", //
+ "mail.google.com", // should be ignored since covered above
+ "dev.mail.google.com", // same again
+ "google.co.uk", //
+ "mail.google.co.uk", //
+ "pleroma.bad.host", //
+ "pleroma.still.a.bad.host", //
}
loader := func() ([]string, error) {
@@ -38,22 +42,25 @@ func TestCache(t *testing.T) {
return cachedDomains, nil
}
- // Check a list of known cached domains.
+ // Check a list of known matching domains.
for _, domain := range []string{
"google.com",
"mail.google.com",
+ "dev.mail.google.com",
"google.co.uk",
"mail.google.co.uk",
"pleroma.bad.host",
"dev.pleroma.bad.host",
+ "pleroma.still.a.bad.host",
+ "dev.pleroma.still.a.bad.host",
} {
t.Logf("checking domain matches: %s", domain)
if b, _ := c.Matches(domain, loader); !b {
- t.Errorf("domain should be matched: %s", domain)
+ t.Fatalf("domain should be matched: %s", domain)
}
}
- // Check a list of known uncached domains.
+ // Check a list of known unmatched domains.
for _, domain := range []string{
"askjeeves.com",
"ask-kim.co.uk",
@@ -61,10 +68,11 @@ func TestCache(t *testing.T) {
"mail.google.ie",
"gts.bad.host",
"mastodon.bad.host",
+ "akkoma.still.a.bad.host",
} {
t.Logf("checking domain isn't matched: %s", domain)
if b, _ := c.Matches(domain, loader); b {
- t.Errorf("domain should not be matched: %s", domain)
+ t.Fatalf("domain should not be matched: %s", domain)
}
}
@@ -80,6 +88,6 @@ func TestCache(t *testing.T) {
t.Log("load: returning known error")
return nil, knownErr
}); !errors.Is(err, knownErr) {
- t.Errorf("matches did not return expected error: %v", err)
+ t.Fatalf("matches did not return expected error: %v", err)
}
}