Compare commits

..

No commits in common. "2c2ff90913b88d7d4d5010cc9ac84ab53b4e08b9" and "9a91726700c0a1dd89f832220c163c6f13688999" have entirely different histories.

7 changed files with 10 additions and 88 deletions

View file

@ -22,6 +22,7 @@
"errors"
"slices"
"github.com/miekg/dns"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
@ -64,6 +65,14 @@ func (d *domainDB) IsDomainPermissionExcluded(ctx context.Context, domain string
return false, err
}
// Check if our host and given domain are equal
// or part of the same second-level domain; we
// always exclude such perms as creating blocks
// or allows in such cases may break things.
if dns.CompareDomainName(domain, config.GetHost()) >= 2 {
return true, nil
}
// Func to scan list of all
// excluded domain perms from DB.
loadF := func() ([]string, error) {
@ -71,16 +80,12 @@ func (d *domainDB) IsDomainPermissionExcluded(ctx context.Context, domain string
if err := d.db.
NewSelect().
Table("domain_permission_excludes").
Table("domain_excludes").
Column("domain").
Scan(ctx, &domains); err != nil {
return nil, err
}
// Exclude our own domain as creating blocks
// or allows for self will likely break things.
domains = append(domains, config.GetHost())
return domains, nil
}

View file

@ -23,7 +23,6 @@
"testing"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
@ -101,85 +100,6 @@ func (suite *DomainPermissionExcludeTestSuite) TestPermExcludeCreateGetDelete()
}
}
func (suite *DomainPermissionExcludeTestSuite) TestExcluded() {
var (
ctx = context.Background()
createdByAccountID = suite.testAccounts["admin_account"].ID
)
// Insert some excludes into the db.
for _, exclude := range []*gtsmodel.DomainPermissionExclude{
{
ID: "01JD7AFFBBZSPY8R2M0JCGQGPW",
Domain: "example.org",
CreatedByAccountID: createdByAccountID,
},
{
ID: "01JD7AMK98E2QX78KXEZJ1RF5Z",
Domain: "boobs.com",
CreatedByAccountID: createdByAccountID,
},
{
ID: "01JD7AMXW3R3W98E91R62ACDA0",
Domain: "rad.boobs.com",
CreatedByAccountID: createdByAccountID,
},
{
ID: "01JD7AYYN5TXQVASB30PT08CE1",
Domain: "honkers.org",
CreatedByAccountID: createdByAccountID,
},
} {
if err := suite.state.DB.PutDomainPermissionExclude(ctx, exclude); err != nil {
suite.FailNow(err.Error())
}
}
type testCase struct {
domain string
excluded bool
}
for i, testCase := range []testCase{
{
domain: config.GetHost(),
excluded: true,
},
{
domain: "test.example.org",
excluded: true,
},
{
domain: "example.org",
excluded: true,
},
{
domain: "boobs.com",
excluded: true,
},
{
domain: "rad.boobs.com",
excluded: true,
},
{
domain: "sir.not.appearing.in.this.list",
excluded: false,
},
} {
excluded, err := suite.state.DB.IsDomainPermissionExcluded(ctx, testCase.domain)
if err != nil {
suite.FailNow(err.Error())
}
if excluded != testCase.excluded {
suite.Failf("",
"test %d: %s excluded should be %t",
i, testCase.domain, testCase.excluded,
)
}
}
}
func TestDomainPermissionExcludeTestSuite(t *testing.T) {
suite.Run(t, new(DomainPermissionExcludeTestSuite))
}

View file

@ -129,7 +129,4 @@ type Domain interface {
// DeleteDomainPermissionExclude deletes one DomainPermissionExclude with the given id.
DeleteDomainPermissionExclude(ctx context.Context, id string) error
// IsDomainPermissionExcluded returns true if the given domain matches in the list of excluded domains.
IsDomainPermissionExcluded(ctx context.Context, domain string) (bool, error)
}