0
0
Fork 0

Fix RSpec/MessageSpies cop (#27751)

This commit is contained in:
Matt Jankowski 2023-11-07 04:46:28 -05:00 committed by GitHub
parent ae0d551d33
commit 49e2772064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 162 additions and 94 deletions

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