diff options
author | 2024-01-09 13:12:43 +0000 | |
---|---|---|
committer | 2024-01-09 13:12:43 +0000 | |
commit | dfc7656579349bda98d3097c473efbb6000e233b (patch) | |
tree | 804e32acb98d8a92d90a8f67ab40b9fa70bd120a /internal/db | |
parent | Bump follow-redirects from 1.15.3 to 1.15.4 in /web/source (#2512) (diff) | |
download | gotosocial-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/db')
-rw-r--r-- | internal/db/bundb/domain_test.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/internal/db/bundb/domain_test.go b/internal/db/bundb/domain_test.go index ff687cf59..8164259e8 100644 --- a/internal/db/bundb/domain_test.go +++ b/internal/db/bundb/domain_test.go @@ -19,6 +19,7 @@ package bundb_test import ( "context" + "slices" "testing" "time" @@ -212,6 +213,67 @@ func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII2() { suite.True(blocked) } +func (suite *DomainTestSuite) TestIsOtherDomainBlockedWildcardAndExplicit() { + ctx := context.Background() + + blocks := []*gtsmodel.DomainBlock{ + { + ID: "01G204214Y9TNJEBX39C7G88SW", + Domain: "bad.apples", + CreatedByAccountID: suite.testAccounts["admin_account"].ID, + CreatedByAccount: suite.testAccounts["admin_account"], + }, + { + ID: "01HKPSVQ864FQ2JJ01CDGPHHMJ", + Domain: "some.bad.apples", + CreatedByAccountID: suite.testAccounts["admin_account"].ID, + CreatedByAccount: suite.testAccounts["admin_account"], + }, + } + + for _, block := range blocks { + if err := suite.db.CreateDomainBlock(ctx, block); err != nil { + suite.FailNow(err.Error()) + } + } + + // Ensure each block created + // above is now present in the db. + dbBlocks, err := suite.db.GetDomainBlocks(ctx) + if err != nil { + suite.FailNow(err.Error()) + } + + for _, block := range blocks { + if !slices.ContainsFunc( + dbBlocks, + func(dbBlock *gtsmodel.DomainBlock) bool { + return block.Domain == dbBlock.Domain + }, + ) { + suite.FailNow("", "stored blocks did not contain %s", block.Domain) + } + } + + // All domains and subdomains + // should now be blocked, even + // ones without an explicit block. + for _, domain := range []string{ + "bad.apples", + "some.bad.apples", + "other.bad.apples", + } { + blocked, err := suite.db.IsDomainBlocked(ctx, domain) + if err != nil { + suite.FailNow(err.Error()) + } + + if !blocked { + suite.Fail("", "domain %s should be blocked", domain) + } + } +} + func TestDomainTestSuite(t *testing.T) { suite.Run(t, new(DomainTestSuite)) } |