[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 😇
This commit is contained in:
kim
2024-01-09 13:12:43 +00:00
committed by GitHub
parent 87bb596a02
commit dfc7656579
3 changed files with 114 additions and 19 deletions

View File

@@ -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)
}
}