diff --git a/app/workers/scheduler/self_destruct_scheduler.rb b/app/workers/scheduler/self_destruct_scheduler.rb index 93f8d19f16..4d8ee2cd85 100644 --- a/app/workers/scheduler/self_destruct_scheduler.rb +++ b/app/workers/scheduler/self_destruct_scheduler.rb @@ -55,13 +55,10 @@ class Scheduler::SelfDestructScheduler end def delete_account!(account) - payload = ActiveModelSerializers::SerializableResource.new( - account, - serializer: ActivityPub::DeleteActorSerializer, - adapter: ActivityPub::Adapter - ).as_json - - json = JSON.generate(ActivityPub::LinkedDataSignature.new(payload).sign!(account)) + json = ActivityPub::LinkedDataSignature + .new(deletion_payload(account)) + .sign!(account) + .to_json ActivityPub::DeliveryWorker.push_bulk(inboxes, limit: 1_000) do |inbox_url| [json, account.id, inbox_url] @@ -70,4 +67,12 @@ class Scheduler::SelfDestructScheduler # Do not call `Account#suspend!` because we don't want to issue a deletion request account.update!(suspended_at: Time.now.utc, suspension_origin: :local) end + + def deletion_payload(account) + ActiveModelSerializers::SerializableResource.new( + account, + serializer: ActivityPub::DeleteActorSerializer, + adapter: ActivityPub::Adapter + ).as_json + end end diff --git a/spec/workers/scheduler/self_destruct_scheduler_spec.rb b/spec/workers/scheduler/self_destruct_scheduler_spec.rb index a79559efdd..0ff0faf05a 100644 --- a/spec/workers/scheduler/self_destruct_scheduler_spec.rb +++ b/spec/workers/scheduler/self_destruct_scheduler_spec.rb @@ -39,6 +39,8 @@ RSpec.describe Scheduler::SelfDestructScheduler do end context 'when sidekiq is operational' do + let!(:other_account) { Fabricate :account, inbox_url: 'https://host.example/inbox', domain: 'host.example', protocol: :activitypub } + it 'suspends local non-suspended accounts' do worker.perform @@ -51,6 +53,9 @@ RSpec.describe Scheduler::SelfDestructScheduler do worker.perform + expect(ActivityPub::DeliveryWorker) + .to have_enqueued_sidekiq_job(match_json_values(type: 'Delete', signature: be_present), account.id, other_account.inbox_url) + expect(account.reload.suspended_at).to be > 1.day.ago expect { deletion_request.reload }.to raise_error(ActiveRecord::RecordNotFound) end