Add check for wrong attribution of collections (#39525)
This commit is contained in:
parent
7608436b64
commit
052d6bb173
@ -12,6 +12,7 @@ class ActivityPub::ProcessFeaturedCollectionService
|
|||||||
@json = json
|
@json = json
|
||||||
@request_id = request_id
|
@request_id = request_id
|
||||||
return if non_matching_uri_hosts?(@account.uri, @json['id'])
|
return if non_matching_uri_hosts?(@account.uri, @json['id'])
|
||||||
|
return unless @json['attributedTo'] == @account.uri
|
||||||
|
|
||||||
with_redis_lock("collection:#{@json['id']}") do
|
with_redis_lock("collection:#{@json['id']}") do
|
||||||
Collection.transaction do
|
Collection.transaction do
|
||||||
|
|||||||
@ -7,12 +7,13 @@ RSpec.describe ActivityPub::ProcessFeaturedCollectionService do
|
|||||||
|
|
||||||
let(:account) { Fabricate(:remote_account) }
|
let(:account) { Fabricate(:remote_account) }
|
||||||
let(:summary) { '<p>A list of remote actors you should follow.</p>' }
|
let(:summary) { '<p>A list of remote actors you should follow.</p>' }
|
||||||
|
let(:attributed_to) { account.uri }
|
||||||
let(:base_json) do
|
let(:base_json) do
|
||||||
{
|
{
|
||||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
'id' => 'https://example.com/featured_collections/1',
|
'id' => 'https://example.com/featured_collections/1',
|
||||||
'type' => 'FeaturedCollection',
|
'type' => 'FeaturedCollection',
|
||||||
'attributedTo' => account.uri,
|
'attributedTo' => attributed_to,
|
||||||
'name' => 'Good people from other servers',
|
'name' => 'Good people from other servers',
|
||||||
'sensitive' => false,
|
'sensitive' => false,
|
||||||
'discoverable' => true,
|
'discoverable' => true,
|
||||||
@ -41,6 +42,16 @@ RSpec.describe ActivityPub::ProcessFeaturedCollectionService do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when `attributedTo` does not match the given account' do
|
||||||
|
let(:attributed_to) { 'https://example.com/random/account' }
|
||||||
|
|
||||||
|
it 'does not create a collection and returns nil' do
|
||||||
|
expect do
|
||||||
|
expect(subject.call(account, featured_collection_json)).to be_nil
|
||||||
|
end.to_not change(Collection, :count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when URIs match up' do
|
context 'when URIs match up' do
|
||||||
it 'creates a collection and queues jobs to handle its items' do
|
it 'creates a collection and queues jobs to handle its items' do
|
||||||
expect { subject.call(account, featured_collection_json) }.to change(account.collections, :count).by(1)
|
expect { subject.call(account, featured_collection_json) }.to change(account.collections, :count).by(1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user