Skip to content

Commit 788c47d

Browse files
Gargronhiyuki2578
authored andcommitted
Fix Announce activities of unknown statuses not fetching those statuses (mastodon#10065)
Regression from mastodon#9998
1 parent 4a4fff1 commit 788c47d

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

app/lib/activitypub/activity.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ def status_from_object
150150
end
151151
end
152152

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
155154
end
156155

157156
def fetch_remote_original_status

spec/lib/activitypub/activity/announce_spec.rb

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails_helper'
22

33
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') }
55
let(:recipient) { Fabricate(:account) }
66
let(:status) { Fabricate(:status, account: recipient) }
77

@@ -10,21 +10,29 @@
1010
'@context': 'https://www.w3.org/ns/activitystreams',
1111
id: 'foo',
1212
type: 'Announce',
13-
actor: ActivityPub::TagManager.instance.uri_for(sender),
13+
actor: 'https://example.com/actor',
1414
object: object_json,
1515
}.with_indifferent_access
1616
end
1717

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+
}
2227
end
2328

29+
subject { described_class.new(json, sender) }
30+
2431
describe '#perform' do
2532
context 'when sender is followed by a local account' do
2633
before do
2734
Fabricate(:account).follow!(sender)
35+
stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json))
2836
subject.perform
2937
end
3038

@@ -38,10 +46,21 @@
3846
end
3947
end
4048

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+
4160
context 'self-boost of a previously unknown status with missing attributedTo' do
4261
let(:object_json) do
4362
{
44-
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
63+
id: 'https://example.com/actor#bar',
4564
type: 'Note',
4665
content: 'Lorem ipsum',
4766
to: 'http://example.com/followers',
@@ -56,10 +75,10 @@
5675
context 'self-boost of a previously unknown status with correct attributedTo' do
5776
let(:object_json) do
5877
{
59-
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
78+
id: 'https://example.com/actor#bar',
6079
type: 'Note',
6180
content: 'Lorem ipsum',
62-
attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
81+
attributedTo: 'https://example.com/actor',
6382
to: 'http://example.com/followers',
6483
}
6584
end
@@ -98,7 +117,7 @@
98117

99118
let(:object_json) do
100119
{
101-
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
120+
id: 'https://example.com/actor#bar',
102121
type: 'Note',
103122
content: 'Lorem ipsum',
104123
to: 'http://example.com/followers',
@@ -117,7 +136,7 @@
117136

118137
let(:object_json) do
119138
{
120-
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
139+
id: 'https://example.com/actor#bar',
121140
type: 'Note',
122141
content: 'Lorem ipsum',
123142
to: 'http://example.com/followers',
@@ -137,7 +156,7 @@
137156

138157
let(:object_json) do
139158
{
140-
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
159+
id: 'https://example.com/actor#bar',
141160
type: 'Note',
142161
content: 'Lorem ipsum',
143162
to: 'http://example.com/followers',

0 commit comments

Comments
 (0)