Merge commit '389a6cc4c0' into upstream-20231108

This commit is contained in:
KMY 2023-11-08 10:41:10 +09:00
commit 08f86bcb8f
107 changed files with 970 additions and 703 deletions

View file

@ -36,8 +36,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
context 'when the payload is a Collection with inlined replies' do
context 'when passing the collection itself' do
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, payload)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
@ -47,8 +50,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
end
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, collection_uri)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
end
@ -65,8 +71,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
context 'when passing the collection itself' do
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, payload)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
@ -76,8 +85,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
end
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, collection_uri)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
end
@ -98,8 +110,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
context 'when passing the collection itself' do
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, payload)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
@ -109,8 +124,11 @@ RSpec.describe ActivityPub::FetchRepliesService, type: :service do
end
it 'spawns workers for up to 5 replies on the same server' do
expect(FetchReplyWorker).to receive(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
allow(FetchReplyWorker).to receive(:push_bulk)
subject.call(status, collection_uri)
expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
end
end
end

View file

@ -41,8 +41,11 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
end
it 'does not process payload' do
expect(ActivityPub::Activity).to_not receive(:factory)
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, actor)
expect(ActivityPub::Activity).to_not have_received(:factory)
end
end
end
@ -59,8 +62,11 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
end
it 'processes the payload' do
expect(ActivityPub::Activity).to receive(:factory)
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, actor)
expect(ActivityPub::Activity).to have_received(:factory)
end
end
end
@ -71,27 +77,33 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
it 'does not process payload if no signature exists' do
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
expect(ActivityPub::Activity).to_not receive(:factory)
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, forwarder)
expect(ActivityPub::Activity).to_not have_received(:factory)
end
it 'processes payload with actor if valid signature exists' do
payload['signature'] = { 'type' => 'RsaSignature2017' }
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(actor)
expect(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
allow(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
subject.call(json, forwarder)
expect(ActivityPub::Activity).to have_received(:factory).with(instance_of(Hash), actor, instance_of(Hash))
end
it 'does not process payload if invalid signature exists' do
payload['signature'] = { 'type' => 'RsaSignature2017' }
allow_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
expect(ActivityPub::Activity).to_not receive(:factory)
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, forwarder)
expect(ActivityPub::Activity).to_not have_received(:factory)
end
context 'when receiving a fabricated status' do
@ -225,7 +237,11 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
end
it 'does not process forged payload' do
expect(ActivityPub::Activity).to_not receive(:factory).with(
allow(ActivityPub::Activity).to receive(:factory)
subject.call(json, forwarder)
expect(ActivityPub::Activity).to_not have_received(:factory).with(
hash_including(
'object' => hash_including(
'id' => 'https://example.com/users/bob/fake-status'
@ -235,7 +251,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
anything
)
expect(ActivityPub::Activity).to_not receive(:factory).with(
expect(ActivityPub::Activity).to_not have_received(:factory).with(
hash_including(
'object' => hash_including(
'content' => '<p>puck was here</p>'
@ -245,8 +261,6 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
anything
)
subject.call(json, forwarder)
expect(Status.where(uri: 'https://example.com/users/bob/fake-status').exists?).to be false
end
end

View file

@ -54,7 +54,7 @@ RSpec.describe BulkImportService do
Import::RowWorker.drain
expect(FollowRequest.includes(:target_account).where(account: account).map(&:target_account).map(&:acct)).to contain_exactly('user@foo.bar', 'unknown@unknown.bar')
expect(FollowRequest.includes(:target_account).where(account: account).map { |follow_request| follow_request.target_account.acct }).to contain_exactly('user@foo.bar', 'unknown@unknown.bar')
end
end
@ -102,7 +102,7 @@ RSpec.describe BulkImportService do
Import::RowWorker.drain
expect(FollowRequest.includes(:target_account).where(account: account).map(&:target_account).map(&:acct)).to contain_exactly('user@foo.bar', 'unknown@unknown.bar')
expect(FollowRequest.includes(:target_account).where(account: account).map { |follow_request| follow_request.target_account.acct }).to contain_exactly('user@foo.bar', 'unknown@unknown.bar')
end
end
@ -367,7 +367,7 @@ RSpec.describe BulkImportService do
Import::RowWorker.drain
expect(account.bookmarks.map(&:status).map(&:uri)).to contain_exactly(already_bookmarked.uri, status.uri, bookmarked.uri, 'https://domain.unknown/foo')
expect(account.bookmarks.map { |bookmark| bookmark.status.uri }).to contain_exactly(already_bookmarked.uri, status.uri, bookmarked.uri, 'https://domain.unknown/foo')
end
end
@ -410,7 +410,7 @@ RSpec.describe BulkImportService do
Import::RowWorker.drain
expect(account.bookmarks.map(&:status).map(&:uri)).to contain_exactly(status.uri, bookmarked.uri, 'https://domain.unknown/foo')
expect(account.bookmarks.map { |bookmark| bookmark.status.uri }).to contain_exactly(status.uri, bookmarked.uri, 'https://domain.unknown/foo')
end
end
end

View file

@ -208,7 +208,7 @@ RSpec.describe ImportService, type: :service do
let!(:remote_status) { Fabricate(:status, uri: 'https://example.com/statuses/1312') }
let!(:direct_status) { Fabricate(:status, uri: 'https://example.com/statuses/direct', visibility: :direct) }
around(:each) do |example|
around do |example|
local_before = Rails.configuration.x.local_domain
web_before = Rails.configuration.x.web_domain
Rails.configuration.x.local_domain = 'local.com'
@ -232,9 +232,9 @@ RSpec.describe ImportService, type: :service do
it 'adds the toots the user has access to to bookmarks' do
local_status = Fabricate(:status, account: local_account, uri: 'https://local.com/users/foo/statuses/42', id: 42, local: true)
subject.call(import)
expect(account.bookmarks.map(&:status).map(&:id)).to include(local_status.id)
expect(account.bookmarks.map(&:status).map(&:id)).to include(remote_status.id)
expect(account.bookmarks.map(&:status).map(&:id)).to_not include(direct_status.id)
expect(account.bookmarks.map { |bookmark| bookmark.status.id }).to include(local_status.id)
expect(account.bookmarks.map { |bookmark| bookmark.status.id }).to include(remote_status.id)
expect(account.bookmarks.map { |bookmark| bookmark.status.id }).to_not include(direct_status.id)
expect(account.bookmarks.count).to eq 3
end
end