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.

96 lines
3.0 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 suspended' do
  21. before do
  22. actor.suspend!(origin: :remote)
  23. end
  24. %w(Accept Add Announce Block Create Flag Follow Like Move Remove).each do |activity_type|
  25. context "with #{activity_type} activity" do
  26. let(:payload) do
  27. {
  28. '@context': 'https://www.w3.org/ns/activitystreams',
  29. id: 'foo',
  30. type: activity_type,
  31. actor: ActivityPub::TagManager.instance.uri_for(actor),
  32. }
  33. end
  34. it 'does not process payload' do
  35. expect(ActivityPub::Activity).not_to receive(:factory)
  36. subject.call(json, actor)
  37. end
  38. end
  39. end
  40. %w(Delete Reject Undo Update).each do |activity_type|
  41. context "with #{activity_type} activity" do
  42. let(:payload) do
  43. {
  44. '@context': 'https://www.w3.org/ns/activitystreams',
  45. id: 'foo',
  46. type: activity_type,
  47. actor: ActivityPub::TagManager.instance.uri_for(actor),
  48. }
  49. end
  50. it 'processes the payload' do
  51. expect(ActivityPub::Activity).to receive(:factory)
  52. subject.call(json, actor)
  53. end
  54. end
  55. end
  56. end
  57. context 'when actor differs from sender' do
  58. let(:forwarder) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/other_account') }
  59. it 'does not process payload if no signature exists' do
  60. expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(nil)
  61. expect(ActivityPub::Activity).not_to receive(:factory)
  62. subject.call(json, forwarder)
  63. end
  64. it 'processes payload with actor if valid signature exists' do
  65. payload['signature'] = { 'type' => 'RsaSignature2017' }
  66. expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(actor)
  67. expect(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
  68. subject.call(json, forwarder)
  69. end
  70. it 'does not process payload if invalid signature exists' do
  71. payload['signature'] = { 'type' => 'RsaSignature2017' }
  72. expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(nil)
  73. expect(ActivityPub::Activity).not_to receive(:factory)
  74. subject.call(json, forwarder)
  75. end
  76. end
  77. end
  78. end