2017-08-08 20:52:15 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-05-02 17:58:48 +01:00
|
|
|
RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
2017-09-26 00:06:13 +01:00
|
|
|
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') }
|
2017-08-31 16:18:49 +01:00
|
|
|
|
|
|
|
let(:payload) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: 'Create',
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(actor),
|
|
|
|
object: {
|
|
|
|
id: 'bar',
|
|
|
|
type: 'Note',
|
|
|
|
content: 'Lorem ipsum',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:json) { Oj.dump(payload) }
|
|
|
|
|
2017-08-26 12:47:38 +01:00
|
|
|
subject { described_class.new }
|
2017-08-08 20:52:15 +01:00
|
|
|
|
|
|
|
describe '#call' do
|
2020-11-07 23:28:39 +00:00
|
|
|
context 'when actor is suspended' do
|
|
|
|
before do
|
|
|
|
actor.suspend!(origin: :remote)
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(Accept Add Announce Block Create Flag Follow Like Move Remove).each do |activity_type|
|
|
|
|
context "with #{activity_type} activity" do
|
|
|
|
let(:payload) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: activity_type,
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(actor),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not process payload' do
|
|
|
|
expect(ActivityPub::Activity).not_to receive(:factory)
|
|
|
|
subject.call(json, actor)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(Delete Reject Undo Update).each do |activity_type|
|
|
|
|
context "with #{activity_type} activity" do
|
|
|
|
let(:payload) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: activity_type,
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(actor),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'processes the payload' do
|
|
|
|
expect(ActivityPub::Activity).to receive(:factory)
|
|
|
|
subject.call(json, actor)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-31 16:18:49 +01:00
|
|
|
context 'when actor differs from sender' do
|
2017-09-26 00:06:13 +01:00
|
|
|
let(:forwarder) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/other_account') }
|
2017-08-31 16:18:49 +01:00
|
|
|
|
2018-12-30 08:48:59 +00:00
|
|
|
it 'does not process payload if no signature exists' do
|
|
|
|
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(nil)
|
|
|
|
expect(ActivityPub::Activity).not_to receive(:factory)
|
2017-08-31 16:18:49 +01:00
|
|
|
|
|
|
|
subject.call(json, forwarder)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'processes payload with actor if valid signature exists' do
|
2018-10-04 11:36:53 +01:00
|
|
|
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
2017-08-31 16:18:49 +01:00
|
|
|
|
|
|
|
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(actor)
|
2017-10-08 16:34:34 +01:00
|
|
|
expect(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
|
2017-08-31 16:18:49 +01:00
|
|
|
|
|
|
|
subject.call(json, forwarder)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not process payload if invalid signature exists' do
|
2018-10-04 11:36:53 +01:00
|
|
|
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
2017-08-31 16:18:49 +01:00
|
|
|
|
|
|
|
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(nil)
|
|
|
|
expect(ActivityPub::Activity).not_to receive(:factory)
|
|
|
|
|
|
|
|
subject.call(json, forwarder)
|
|
|
|
end
|
|
|
|
end
|
2017-08-08 20:52:15 +01:00
|
|
|
end
|
|
|
|
end
|