From 5cf0f9950a95cf46fda6ba8f479aa4728eba5ec4 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 6 Oct 2022 12:48:17 +0200 Subject: [PATCH] [bugfix] Fix new domain block date (#893) --- internal/db/bundb/domain.go | 8 ++++---- internal/db/bundb/domain_test.go | 11 ++++------- internal/db/domain.go | 2 +- internal/processing/admin/createdomainblock.go | 4 ++-- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/internal/db/bundb/domain.go b/internal/db/bundb/domain.go index 5d262c676..9fc4bb276 100644 --- a/internal/db/bundb/domain.go +++ b/internal/db/bundb/domain.go @@ -47,7 +47,7 @@ func normalizeDomain(domain string) (out string, err error) { return out, err } -func (d *domainDB) CreateDomainBlock(ctx context.Context, block gtsmodel.DomainBlock) db.Error { +func (d *domainDB) CreateDomainBlock(ctx context.Context, block *gtsmodel.DomainBlock) db.Error { domain, err := normalizeDomain(block.Domain) if err != nil { return err @@ -56,13 +56,13 @@ func (d *domainDB) CreateDomainBlock(ctx context.Context, block gtsmodel.DomainB // Attempt to insert new domain block if _, err := d.conn.NewInsert(). - Model(&block). - Exec(ctx, &block); err != nil { + Model(block). + Exec(ctx); err != nil { return d.conn.ProcessError(err) } // Cache this domain block - d.cache.Put(block.Domain, &block) + d.cache.Put(block.Domain, block) return nil } diff --git a/internal/db/bundb/domain_test.go b/internal/db/bundb/domain_test.go index 48c4a7798..41a73ff80 100644 --- a/internal/db/bundb/domain_test.go +++ b/internal/db/bundb/domain_test.go @@ -34,13 +34,9 @@ type DomainTestSuite struct { func (suite *DomainTestSuite) TestIsDomainBlocked() { ctx := context.Background() - now := time.Now() - domainBlock := >smodel.DomainBlock{ ID: "01G204214Y9TNJEBX39C7G88SW", Domain: "some.bad.apples", - CreatedAt: now, - UpdatedAt: now, CreatedByAccountID: suite.testAccounts["admin_account"].ID, CreatedByAccount: suite.testAccounts["admin_account"], } @@ -50,13 +46,14 @@ func (suite *DomainTestSuite) TestIsDomainBlocked() { suite.NoError(err) suite.False(blocked) - err = suite.db.CreateDomainBlock(ctx, *domainBlock) + err = suite.db.CreateDomainBlock(ctx, domainBlock) suite.NoError(err) // domain block now exists blocked, err = suite.db.IsDomainBlocked(ctx, domainBlock.Domain) suite.NoError(err) suite.True(blocked) + suite.WithinDuration(time.Now(), domainBlock.CreatedAt, 10*time.Second) } func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII() { @@ -82,7 +79,7 @@ func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII() { suite.NoError(err) suite.False(blocked) - err = suite.db.CreateDomainBlock(ctx, *domainBlock) + err = suite.db.CreateDomainBlock(ctx, domainBlock) suite.NoError(err) // domain block now exists @@ -118,7 +115,7 @@ func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII2() { suite.NoError(err) suite.False(blocked) - err = suite.db.CreateDomainBlock(ctx, *domainBlock) + err = suite.db.CreateDomainBlock(ctx, domainBlock) suite.NoError(err) // domain block now exists diff --git a/internal/db/domain.go b/internal/db/domain.go index 7b264165d..f35340a2a 100644 --- a/internal/db/domain.go +++ b/internal/db/domain.go @@ -28,7 +28,7 @@ import ( // Domain contains DB functions related to domains and domain blocks. type Domain interface { // CreateDomainBlock ... - CreateDomainBlock(ctx context.Context, block gtsmodel.DomainBlock) Error + CreateDomainBlock(ctx context.Context, block *gtsmodel.DomainBlock) Error // GetDomainBlock ... GetDomainBlock(ctx context.Context, domain string) (*gtsmodel.DomainBlock, Error) diff --git a/internal/processing/admin/createdomainblock.go b/internal/processing/admin/createdomainblock.go index 690160150..c39a91989 100644 --- a/internal/processing/admin/createdomainblock.go +++ b/internal/processing/admin/createdomainblock.go @@ -56,7 +56,7 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc return nil, gtserror.NewErrorInternalError(fmt.Errorf("error creating id for new domain block %s: %s", domain, err)) } - newBlock := gtsmodel.DomainBlock{ + newBlock := >smodel.DomainBlock{ ID: blockID, Domain: domain, CreatedByAccountID: account.ID, @@ -72,7 +72,7 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc } // Set the newly created block - block = &newBlock + block = newBlock // Process the side effects of the domain block asynchronously since it might take a while go func() {