about summary refs log tree commit diff
path: root/spec/lib/activitypub/activity/announce_spec.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-02-17 03:38:25 +0100
committerGitHub <noreply@github.com>2019-02-17 03:38:25 +0100
commit147b4c2c3afacd6ad9d5c1353c072861eaca5fd2 (patch)
treef1e7cc90285e97715ab6aae25abc4e5165c3100b /spec/lib/activitypub/activity/announce_spec.rb
parent041ff5fa9a45f7b8d1048a05a35611622b6f5fdb (diff)
Add logging for rejected ActivityPub payloads and add tests (#10062)
Diffstat (limited to 'spec/lib/activitypub/activity/announce_spec.rb')
-rw-r--r--spec/lib/activitypub/activity/announce_spec.rb117
1 files changed, 99 insertions, 18 deletions
diff --git a/spec/lib/activitypub/activity/announce_spec.rb b/spec/lib/activitypub/activity/announce_spec.rb
index 5e6f008ec..94b9d348d 100644
--- a/spec/lib/activitypub/activity/announce_spec.rb
+++ b/spec/lib/activitypub/activity/announce_spec.rb
@@ -18,16 +18,63 @@ RSpec.describe ActivityPub::Activity::Announce do
   subject { described_class.new(json, sender) }
 
   before do
-    Fabricate(:account).follow!(sender)
     sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
   end
 
   describe '#perform' do
-    before do
-      subject.perform
+    context 'when sender is followed by a local account' do
+      before do
+        Fabricate(:account).follow!(sender)
+        subject.perform
+      end
+
+      context 'a known status' do
+        let(:object_json) do
+          ActivityPub::TagManager.instance.uri_for(status)
+        end
+
+        it 'creates a reblog by sender of status' do
+          expect(sender.reblogged?(status)).to be true
+        end
+      end
+
+      context 'self-boost of a previously unknown status with missing attributedTo' do
+        let(:object_json) do
+          {
+            id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
+            type: 'Note',
+            content: 'Lorem ipsum',
+            to: 'http://example.com/followers',
+          }
+        end
+
+        it 'creates a reblog by sender of status' do
+          expect(sender.reblogged?(sender.statuses.first)).to be true
+        end
+      end
+
+      context 'self-boost of a previously unknown status with correct attributedTo' do
+        let(:object_json) do
+          {
+            id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
+            type: 'Note',
+            content: 'Lorem ipsum',
+            attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
+            to: 'http://example.com/followers',
+          }
+        end
+
+        it 'creates a reblog by sender of status' do
+          expect(sender.reblogged?(sender.statuses.first)).to be true
+        end
+      end
     end
 
-    context 'a known status' do
+    context 'when the status belongs to a local user' do
+      before do
+        subject.perform
+      end
+
       let(:object_json) do
         ActivityPub::TagManager.instance.uri_for(status)
       end
@@ -37,34 +84,68 @@ RSpec.describe ActivityPub::Activity::Announce do
       end
     end
 
-    context 'self-boost of a previously unknown status with missing attributedTo' do
-      let(:object_json) do
-        {
-          id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
-          type: 'Note',
-          content: 'Lorem ipsum',
-          to: 'http://example.com/followers',
-        }
+    context 'when the sender is relayed' do
+      let!(:relay_account) { Fabricate(:account, inbox_url: 'https://relay.example.com/inbox') }
+      let!(:relay) { Fabricate(:relay, inbox_url: 'https://relay.example.com/inbox') }
+
+      subject { described_class.new(json, sender, relayed_through_account: relay_account) }
+
+      context 'and the relay is enabled' do
+        before do
+          relay.update(state: :accepted)
+          subject.perform
+        end
+
+        let(:object_json) do
+          {
+            id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
+            type: 'Note',
+            content: 'Lorem ipsum',
+            to: 'http://example.com/followers',
+          }
+        end
+
+        it 'creates a reblog by sender of status' do
+          expect(sender.statuses.count).to eq 2
+        end
       end
 
-      it 'creates a reblog by sender of status' do
-        expect(sender.reblogged?(sender.statuses.first)).to be true
+      context 'and the relay is disabled' do
+        before do
+          subject.perform
+        end
+
+        let(:object_json) do
+          {
+            id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
+            type: 'Note',
+            content: 'Lorem ipsum',
+            to: 'http://example.com/followers',
+          }
+        end
+
+        it 'does not create anything' do
+          expect(sender.statuses.count).to eq 0
+        end
       end
     end
 
-    context 'self-boost of a previously unknown status with correct attributedTo' do
+    context 'when the sender has no relevance to local activity' do
+      before do
+        subject.perform
+      end
+
       let(:object_json) do
         {
           id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
           type: 'Note',
           content: 'Lorem ipsum',
-          attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
           to: 'http://example.com/followers',
         }
       end
 
-      it 'creates a reblog by sender of status' do
-        expect(sender.reblogged?(sender.statuses.first)).to be true
+      it 'does not create anything' do
+        expect(sender.statuses.count).to eq 0
       end
     end
   end