Browse Source

Fix Announce activities of unknown statuses not fetching those statuses (#10065)

Regression from #9998
Eugen Rochko 1 month ago
parent
commit
b163368c3e
2 changed files with 32 additions and 14 deletions
  1. 1
    2
      app/lib/activitypub/activity.rb
  2. 31
    12
      spec/lib/activitypub/activity/announce_spec.rb

+ 1
- 2
app/lib/activitypub/activity.rb View File

@@ -150,8 +150,7 @@ class ActivityPub::Activity
150 150
       end
151 151
     end
152 152
 
153
-    # If the status is not from the actor, try to fetch it
154
-    return fetch_remote_original_status if value_or_id(first_of_value(@json['attributedTo'])) == @account.uri
153
+    fetch_remote_original_status
155 154
   end
156 155
 
157 156
   def fetch_remote_original_status

+ 31
- 12
spec/lib/activitypub/activity/announce_spec.rb View File

@@ -1,7 +1,7 @@
1 1
 require 'rails_helper'
2 2
 
3 3
 RSpec.describe ActivityPub::Activity::Announce do
4
-  let(:sender)    { Fabricate(:account, followers_url: 'http://example.com/followers') }
4
+  let(:sender)    { Fabricate(:account, followers_url: 'http://example.com/followers', uri: 'https://example.com/actor') }
5 5
   let(:recipient) { Fabricate(:account) }
6 6
   let(:status)    { Fabricate(:status, account: recipient) }
7 7
 
@@ -10,21 +10,29 @@ RSpec.describe ActivityPub::Activity::Announce do
10 10
       '@context': 'https://www.w3.org/ns/activitystreams',
11 11
       id: 'foo',
12 12
       type: 'Announce',
13
-      actor: ActivityPub::TagManager.instance.uri_for(sender),
13
+      actor: 'https://example.com/actor',
14 14
       object: object_json,
15 15
     }.with_indifferent_access
16 16
   end
17 17
 
18
-  subject { described_class.new(json, sender) }
19
-
20
-  before do
21
-    sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
18
+  let(:unknown_object_json) do
19
+    {
20
+      '@context': 'https://www.w3.org/ns/activitystreams',
21
+      id: 'https://example.com/actor/hello-world',
22
+      type: 'Note',
23
+      attributedTo: 'https://example.com/actor',
24
+      content: 'Hello world',
25
+      to: 'http://example.com/followers',
26
+    }
22 27
   end
23 28
 
29
+  subject { described_class.new(json, sender) }
30
+
24 31
   describe '#perform' do
25 32
     context 'when sender is followed by a local account' do
26 33
       before do
27 34
         Fabricate(:account).follow!(sender)
35
+        stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json))
28 36
         subject.perform
29 37
       end
30 38
 
@@ -38,10 +46,21 @@ RSpec.describe ActivityPub::Activity::Announce do
38 46
         end
39 47
       end
40 48
 
49
+      context 'an unknown status' do
50
+        let(:object_json) { 'https://example.com/actor/hello-world' }
51
+
52
+        it 'creates a reblog by sender of status' do
53
+          reblog = sender.statuses.first
54
+
55
+          expect(reblog).to_not be_nil
56
+          expect(reblog.reblog.text).to eq 'Hello world'
57
+        end
58
+      end
59
+
41 60
       context 'self-boost of a previously unknown status with missing attributedTo' do
42 61
         let(:object_json) do
43 62
           {
44
-            id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
63
+            id: 'https://example.com/actor#bar',
45 64
             type: 'Note',
46 65
             content: 'Lorem ipsum',
47 66
             to: 'http://example.com/followers',
@@ -56,10 +75,10 @@ RSpec.describe ActivityPub::Activity::Announce do
56 75
       context 'self-boost of a previously unknown status with correct attributedTo' do
57 76
         let(:object_json) do
58 77
           {
59
-            id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
78
+            id: 'https://example.com/actor#bar',
60 79
             type: 'Note',
61 80
             content: 'Lorem ipsum',
62
-            attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
81
+            attributedTo: 'https://example.com/actor',
63 82
             to: 'http://example.com/followers',
64 83
           }
65 84
         end
@@ -98,7 +117,7 @@ RSpec.describe ActivityPub::Activity::Announce do
98 117
 
99 118
         let(:object_json) do
100 119
           {
101
-            id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
120
+            id: 'https://example.com/actor#bar',
102 121
             type: 'Note',
103 122
             content: 'Lorem ipsum',
104 123
             to: 'http://example.com/followers',
@@ -117,7 +136,7 @@ RSpec.describe ActivityPub::Activity::Announce do
117 136
 
118 137
         let(:object_json) do
119 138
           {
120
-            id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
139
+            id: 'https://example.com/actor#bar',
121 140
             type: 'Note',
122 141
             content: 'Lorem ipsum',
123 142
             to: 'http://example.com/followers',
@@ -137,7 +156,7 @@ RSpec.describe ActivityPub::Activity::Announce do
137 156
 
138 157
       let(:object_json) do
139 158
         {
140
-          id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
159
+          id: 'https://example.com/actor#bar',
141 160
           type: 'Note',
142 161
           content: 'Lorem ipsum',
143 162
           to: 'http://example.com/followers',

Loading…
Cancel
Save