You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
  3. let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') }
  4. let(:payload) do
  5. {
  6. '@context': 'https://www.w3.org/ns/activitystreams',
  7. id: 'foo',
  8. type: 'Create',
  9. actor: ActivityPub::TagManager.instance.uri_for(actor),
  10. object: {
  11. id: 'bar',
  12. type: 'Note',
  13. content: 'Lorem ipsum',
  14. },
  15. }
  16. end
  17. let(:json) { Oj.dump(payload) }
  18. subject { described_class.new }
  19. describe '#call' do
  20. context 'when actor is the sender'
  21. context 'when actor differs from sender' do
  22. let(:forwarder) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/other_account') }
  23. it 'does not process payload if no signature exists' do
  24. expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(nil)
  25. expect(ActivityPub::Activity).not_to receive(:factory)
  26. subject.call(json, forwarder)
  27. end
  28. it 'processes payload with actor if valid signature exists' do
  29. payload['signature'] = { 'type' => 'RsaSignature2017' }
  30. expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(actor)
  31. expect(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
  32. subject.call(json, forwarder)
  33. end
  34. it 'does not process payload if invalid signature exists' do
  35. payload['signature'] = { 'type' => 'RsaSignature2017' }
  36. expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(nil)
  37. expect(ActivityPub::Activity).not_to receive(:factory)
  38. subject.call(json, forwarder)
  39. end
  40. end
  41. end
  42. end