2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-08-20 19:53:33 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-03-13 19:39:26 +11:00
|
|
|
RSpec.describe SuspendAccountService, :sidekiq_inline do
|
2021-08-20 19:53:33 +10:00
|
|
|
shared_examples 'common behavior' do
|
2023-02-20 15:24:14 +11:00
|
|
|
subject { described_class.new.call(account) }
|
|
|
|
|
2021-08-20 19:53:33 +10:00
|
|
|
let!(:local_follower) { Fabricate(:user, current_sign_in_at: 1.hour.ago).account }
|
|
|
|
let!(:list) { Fabricate(:list, account: local_follower) }
|
|
|
|
|
|
|
|
before do
|
2023-08-22 17:31:40 +10:00
|
|
|
allow(FeedManager.instance).to receive_messages(unmerge_from_home: nil, unmerge_from_list: nil)
|
2021-08-20 19:53:33 +10:00
|
|
|
|
|
|
|
local_follower.follow!(account)
|
|
|
|
list.accounts << account
|
2023-01-05 23:47:21 +11:00
|
|
|
|
|
|
|
account.suspend!
|
2024-01-08 22:05:10 +11:00
|
|
|
|
|
|
|
Fabricate(:media_attachment, file: attachment_fixture('boop.ogg'), account: account)
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
|
2024-01-08 22:05:10 +11:00
|
|
|
it 'unmerges from feeds of local followers and changes file mode and preserves suspended flag' do
|
2023-12-06 19:45:19 +11:00
|
|
|
expect { subject }
|
2024-01-08 22:05:10 +11:00
|
|
|
.to change_file_mode
|
|
|
|
.and not_change_suspended_flag
|
2021-08-20 19:53:33 +10:00
|
|
|
expect(FeedManager.instance).to have_received(:unmerge_from_home).with(account, local_follower)
|
|
|
|
expect(FeedManager.instance).to have_received(:unmerge_from_list).with(account, list)
|
|
|
|
end
|
|
|
|
|
2024-01-08 22:05:10 +11:00
|
|
|
def change_file_mode
|
|
|
|
change { File.stat(account.media_attachments.first.file.path).mode }
|
|
|
|
end
|
|
|
|
|
|
|
|
def not_change_suspended_flag
|
|
|
|
not_change(account, :suspended?)
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'suspending a local account' do
|
|
|
|
def match_update_actor_request(req, account)
|
|
|
|
json = JSON.parse(req.body)
|
|
|
|
actor_id = ActivityPub::TagManager.instance.uri_for(account)
|
|
|
|
json['type'] == 'Update' && json['actor'] == actor_id && json['object']['id'] == actor_id && json['object']['suspended']
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_request(:post, 'https://alice.com/inbox').to_return(status: 201)
|
|
|
|
stub_request(:post, 'https://bob.com/inbox').to_return(status: 201)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'common behavior' do
|
|
|
|
let!(:account) { Fabricate(:account) }
|
2023-07-21 02:23:48 +10:00
|
|
|
let!(:remote_follower) { Fabricate(:account, uri: 'https://alice.com', inbox_url: 'https://alice.com/inbox', protocol: :activitypub, domain: 'alice.com') }
|
|
|
|
let!(:remote_reporter) { Fabricate(:account, uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub, domain: 'bob.com') }
|
2021-08-20 19:53:33 +10:00
|
|
|
|
|
|
|
before do
|
2023-12-22 01:23:53 +11:00
|
|
|
Fabricate(:report, account: remote_reporter, target_account: account)
|
2021-08-20 19:53:33 +10:00
|
|
|
remote_follower.follow!(account)
|
|
|
|
end
|
|
|
|
|
2024-03-21 02:37:21 +11:00
|
|
|
it 'sends an Update actor activity to followers and reporters' do
|
2022-03-28 21:43:58 +11:00
|
|
|
subject
|
2021-08-20 19:53:33 +10:00
|
|
|
expect(a_request(:post, remote_follower.inbox_url).with { |req| match_update_actor_request(req, account) }).to have_been_made.once
|
|
|
|
expect(a_request(:post, remote_reporter.inbox_url).with { |req| match_update_actor_request(req, account) }).to have_been_made.once
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'suspending a remote account' do
|
|
|
|
def match_reject_follow_request(req, account, followee)
|
|
|
|
json = JSON.parse(req.body)
|
|
|
|
json['type'] == 'Reject' && json['actor'] == ActivityPub::TagManager.instance.uri_for(followee) && json['object']['actor'] == account.uri
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_request(:post, 'https://bob.com/inbox').to_return(status: 201)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'common behavior' do
|
|
|
|
let!(:account) { Fabricate(:account, domain: 'bob.com', uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
|
|
|
|
let!(:local_followee) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
account.follow!(local_followee)
|
|
|
|
end
|
|
|
|
|
2024-03-21 02:37:21 +11:00
|
|
|
it 'sends a Reject Follow activity, and records severed relationships', :aggregate_failures do
|
2022-03-28 21:43:58 +11:00
|
|
|
subject
|
2024-03-21 02:37:21 +11:00
|
|
|
|
2021-08-20 19:53:33 +10:00
|
|
|
expect(a_request(:post, account.inbox_url).with { |req| match_reject_follow_request(req, account, local_followee) }).to have_been_made.once
|
2024-03-21 02:37:21 +11:00
|
|
|
|
|
|
|
severed_relationships = local_followee.severed_relationships.to_a
|
|
|
|
expect(severed_relationships.count).to eq 1
|
|
|
|
expect(severed_relationships.map { |rel| [rel.account, rel.target_account] }).to contain_exactly([account, local_followee])
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|