process_collection_service_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::ProcessCollectionService do
  3. let(:actor) { Fabricate(: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) }
  23. it 'processes payload with sender if no signature exists' do
  24. expect_any_instance_of(ActivityPub::LinkedDataSignature).not_to receive(:verify_account!)
  25. expect(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), forwarder)
  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)
  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