diff options
Diffstat (limited to 'internal/subscriptions/subscriptions_test.go')
| -rw-r--r-- | internal/subscriptions/subscriptions_test.go | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/internal/subscriptions/subscriptions_test.go b/internal/subscriptions/subscriptions_test.go index 8e292209d..193c073f0 100644 --- a/internal/subscriptions/subscriptions_test.go +++ b/internal/subscriptions/subscriptions_test.go @@ -949,6 +949,138 @@ func (suite *SubscriptionsTestSuite) TestDomainAllowsAndBlocks() { suite.Equal(existingAllow.SubscriptionID, testAllowSubscription.ID) } +func (suite *SubscriptionsTestSuite) TestRemoveRetraction() { + var ( + ctx = suite.T().Context() + testStructs = testrig.SetupTestStructs(rMediaPath, rTemplatePath) + testAccount = suite.testAccounts["admin_account"] + subscriptions = subscriptions.New( + testStructs.State, + testStructs.TransportController, + testStructs.TypeConverter, + ) + + // A subscription for a plain list of + // baddies, which removes retracted entries. + testSubscription = >smodel.DomainPermissionSubscription{ + ID: "01JGE681TQSBPAV59GZXPKE62H", + Priority: 255, + Title: "whatever!", + PermissionType: gtsmodel.DomainPermissionBlock, + AsDraft: util.Ptr(false), + AdoptOrphans: util.Ptr(false), + CreatedByAccountID: testAccount.ID, + CreatedByAccount: testAccount, + URI: "https://lists.example.org/baddies.txt", + ContentType: gtsmodel.DomainPermSubContentTypePlain, + RemoveRetracted: util.Ptr(true), + } + + // Block owned by testSubscription + // that no longer exists on the remote + // list, ie., it's been retracted. + retractedBlock = >smodel.DomainBlock{ + ID: "01JHX2V5WN250TKB6FQ1M3QE1H", + Domain: "retracted.example.org", + CreatedByAccount: testAccount, + CreatedByAccountID: testAccount.ID, + SubscriptionID: "01JGE681TQSBPAV59GZXPKE62H", + } + ) + defer testrig.TearDownTestStructs(testStructs) + + // Store test subscription. + if err := testStructs.State.DB.PutDomainPermissionSubscription( + ctx, testSubscription, + ); err != nil { + suite.FailNow(err.Error()) + } + + // Store the retracted block. + if err := testStructs.State.DB.PutDomainBlock( + ctx, retractedBlock, + ); err != nil { + suite.FailNow(err.Error()) + } + + // Process subscriptions. + subscriptions.ProcessDomainPermissionSubscriptions(ctx, testSubscription.PermissionType) + + // Retracted block should be removed. + if !testrig.WaitFor(func() bool { + _, err := testStructs.State.DB.GetDomainBlock(ctx, retractedBlock.Domain) + return errors.Is(err, db.ErrNoEntries) + }) { + suite.FailNow("timed out waiting for block to be removed") + } +} + +func (suite *SubscriptionsTestSuite) TestOrphanRetraction() { + var ( + ctx = suite.T().Context() + testStructs = testrig.SetupTestStructs(rMediaPath, rTemplatePath) + testAccount = suite.testAccounts["admin_account"] + subscriptions = subscriptions.New( + testStructs.State, + testStructs.TransportController, + testStructs.TypeConverter, + ) + + // A subscription for a plain list of + // baddies, which orphans retracted entries. + testSubscription = >smodel.DomainPermissionSubscription{ + ID: "01JGE681TQSBPAV59GZXPKE62H", + Priority: 255, + Title: "whatever!", + PermissionType: gtsmodel.DomainPermissionBlock, + AsDraft: util.Ptr(false), + AdoptOrphans: util.Ptr(false), + CreatedByAccountID: testAccount.ID, + CreatedByAccount: testAccount, + URI: "https://lists.example.org/baddies.txt", + ContentType: gtsmodel.DomainPermSubContentTypePlain, + RemoveRetracted: util.Ptr(false), + } + + // Block owned by testSubscription + // that no longer exists on the remote + // list, ie., it's been retracted. + retractedBlock = >smodel.DomainBlock{ + ID: "01JHX2V5WN250TKB6FQ1M3QE1H", + Domain: "retracted.example.org", + CreatedByAccount: testAccount, + CreatedByAccountID: testAccount.ID, + SubscriptionID: "01JGE681TQSBPAV59GZXPKE62H", + } + ) + defer testrig.TearDownTestStructs(testStructs) + + // Store test subscription. + if err := testStructs.State.DB.PutDomainPermissionSubscription( + ctx, testSubscription, + ); err != nil { + suite.FailNow(err.Error()) + } + + // Store the retracted block. + if err := testStructs.State.DB.PutDomainBlock( + ctx, retractedBlock, + ); err != nil { + suite.FailNow(err.Error()) + } + + // Process subscriptions. + subscriptions.ProcessDomainPermissionSubscriptions(ctx, testSubscription.PermissionType) + + // Retracted block should be orphaned. + if !testrig.WaitFor(func() bool { + block, err := testStructs.State.DB.GetDomainBlock(ctx, retractedBlock.Domain) + return err == nil && block.SubscriptionID == "" + }) { + suite.FailNow("timed out waiting for block to be orphaned") + } +} + func TestSubscriptionTestSuite(t *testing.T) { suite.Run(t, new(SubscriptionsTestSuite)) } |
