Change: #375 投稿を編集して拡張ドメインブロックの条件にひっかかる状態になった場合、対象サーバーには投稿削除のActivityを送信する (#495)

* Change: #375 投稿を編集して拡張ドメインブロックの条件にひっかかる状態になった場合、対象サーバーには投稿削除のActivityを送信する

* Fix test

* Add test
This commit is contained in:
KMY(雪あすか) 2024-01-24 09:03:24 +09:00 committed by GitHub
parent e4375143ca
commit fcd13a6474
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 146 additions and 12 deletions

View file

@ -117,6 +117,33 @@ RSpec.describe ActivityPub::Activity::Update do
end
end
context 'when the status is not existing' do
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Update',
actor: sender.uri,
signature: 'foo',
object: {
type: 'Note',
id: 'https://example.com/note',
content: 'Ohagi is tsubuan',
},
}.with_indifferent_access
end
before do
stub_request(:post, 'https://example.com/inbox').to_return(status: 200)
subject.perform
end
it 'does not create a new status', :sidekiq_inline do
status = Status.find_by(uri: 'https://example.com/note')
expect(status).to be_nil
end
end
context 'when the status is limited post and has conversation' do
let(:status) { Fabricate(:status, visibility: :limited, account: sender, uri: 'https://example.com/note', text: 'Ohagi is koshian') }
let(:conversation) { Fabricate(:conversation, ancestor_status: status) }

View file

@ -379,15 +379,15 @@ describe StatusReachFinder do
let(:visibility) { :public }
let(:searchability) { :public }
let(:dissubscribable) { false }
let(:spoiler_text) { '' }
let(:status) { Fabricate(:status, account: alice, visibility: visibility, searchability: searchability, spoiler_text: spoiler_text) }
let(:sensitive) { false }
let(:status) { Fabricate(:status, account: alice, visibility: visibility, searchability: searchability, sensitive: sensitive) }
let(:alice) { Fabricate(:account, username: 'alice', master_settings: { subscription_policy: dissubscribable ? 'block' : 'allow' }) }
let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', protocol: :activitypub, uri: 'https://example.com/', inbox_url: 'https://example.com/inbox') }
let(:tom) { Fabricate(:account, username: 'tom', domain: 'tom.com', protocol: :activitypub, uri: 'https://tom.com/', inbox_url: 'https://tom.com/inbox') }
context 'when reject_send_sensitive' do
let(:properties) { { reject_send_sensitive: true } }
let(:spoiler_text) { 'CW' }
let(:sensitive) { true }
it 'does not include the inbox of blocked domain' do
expect(subject.inboxes).to_not include 'https://example.com/inbox'

View file

@ -62,6 +62,55 @@ RSpec.describe UpdateStatusService, type: :service do
end
end
context 'when content warning changes and has remote user', :sidekiq_inline do
let(:remote_follower) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/actor', protocol: :activitypub, inbox_url: 'https://example.com/inbox') }
let(:status) { Fabricate(:status, text: 'Foo', spoiler_text: '', account: Fabricate(:user).account) }
before do
remote_follower.follow!(status.account)
stub_request(:post, 'https://example.com/inbox').to_return(status: 200)
end
def match_update_request(req, type)
json = JSON.parse(req.body)
actor_id = ActivityPub::TagManager.instance.uri_for(status.account)
status_id = ActivityPub::TagManager.instance.uri_for(status)
json['type'] == type && json['actor'] == actor_id && json['object']['id'] == status_id
end
it 'edit activity is sent' do
subject.call(status, status.account_id, text: 'Foo', spoiler_text: 'Bar')
expect(a_request(:post, 'https://example.com/inbox').with { |req| match_update_request(req, 'Update') }).to have_been_made.once
expect(a_request(:post, 'https://example.com/inbox').with { |req| match_update_request(req, 'Delete') }).to_not have_been_made
end
it 'edit activity is sent for target user' do
Fabricate(:domain_block, domain: 'example.com', severity: :noop, reject_send_sensitive: true)
subject.call(status, status.account_id, text: 'Ohagi')
expect(a_request(:post, 'https://example.com/inbox').with { |req| match_update_request(req, 'Update') }).to have_been_made.once
expect(a_request(:post, 'https://example.com/inbox').with { |req| match_update_request(req, 'Delete') }).to_not have_been_made
end
it 'delete activity is sent when follower is target user' do
Fabricate(:domain_block, domain: 'example.com', severity: :noop, reject_send_sensitive: true)
subject.call(status, status.account_id, text: 'Foo', spoiler_text: 'Bar')
expect(a_request(:post, 'https://example.com/inbox').with { |req| match_update_request(req, 'Delete') }).to have_been_made.once
expect(a_request(:post, 'https://example.com/inbox').with { |req| match_update_request(req, 'Update') }).to_not have_been_made
end
it 'delete activity is sent and update activity is not sent when follower is target user' do
Fabricate(:domain_block, domain: 'example.com', severity: :noop, reject_send_sensitive: true)
subject.call(status, status.account_id, text: 'Foo', spoiler_text: 'Bar')
subject.call(status, status.account_id, text: 'Ohagi', spoiler_text: 'Bar')
expect(a_request(:post, 'https://example.com/inbox').with { |req| match_update_request(req, 'Delete') }).to have_been_made.once
expect(a_request(:post, 'https://example.com/inbox').with { |req| match_update_request(req, 'Update') }).to_not have_been_made
end
end
context 'when media attachments change' do
let!(:status) { Fabricate(:status, text: 'Foo') }
let!(:detached_media_attachment) { Fabricate(:media_attachment, account: status.account) }