2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-09 05:52:15 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ActivityPub::Activity::Announce do
|
2023-02-20 15:24:14 +11:00
|
|
|
subject { described_class.new(json, sender) }
|
|
|
|
|
2023-07-21 02:23:48 +10:00
|
|
|
let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers', uri: 'https://example.com/actor', domain: 'example.com') }
|
2017-08-09 05:52:15 +10:00
|
|
|
let(:recipient) { Fabricate(:account) }
|
|
|
|
let(:status) { Fabricate(:status, account: recipient) }
|
|
|
|
|
|
|
|
let(:json) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: 'Announce',
|
2019-02-18 01:16:36 +11:00
|
|
|
actor: 'https://example.com/actor',
|
2019-02-14 04:36:23 +11:00
|
|
|
object: object_json,
|
2019-03-18 00:54:09 +11:00
|
|
|
to: 'http://example.com/followers',
|
2017-08-09 05:52:15 +10:00
|
|
|
}.with_indifferent_access
|
|
|
|
end
|
|
|
|
|
2019-02-18 01:16:36 +11:00
|
|
|
let(:unknown_object_json) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'https://example.com/actor/hello-world',
|
|
|
|
type: 'Note',
|
|
|
|
attributedTo: 'https://example.com/actor',
|
|
|
|
content: 'Hello world',
|
|
|
|
to: 'http://example.com/followers',
|
|
|
|
}
|
2019-02-14 04:36:23 +11:00
|
|
|
end
|
2017-08-09 05:52:15 +10:00
|
|
|
|
2019-02-14 04:36:23 +11:00
|
|
|
describe '#perform' do
|
2019-02-17 13:38:25 +11:00
|
|
|
context 'when sender is followed by a local account' do
|
|
|
|
before do
|
|
|
|
Fabricate(:account).follow!(sender)
|
2024-02-16 21:56:12 +11:00
|
|
|
stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' })
|
2019-02-17 13:38:25 +11:00
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'with known status' do
|
2019-02-17 13:38:25 +11:00
|
|
|
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
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'with unknown status' do
|
2019-02-18 01:16:36 +11:00
|
|
|
let(:object_json) { 'https://example.com/actor/hello-world' }
|
|
|
|
|
|
|
|
it 'creates a reblog by sender of status' do
|
|
|
|
reblog = sender.statuses.first
|
|
|
|
|
|
|
|
expect(reblog).to_not be_nil
|
|
|
|
expect(reblog.reblog.text).to eq 'Hello world'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when self-boost of a previously unknown status with correct attributedTo' do
|
2019-02-17 13:38:25 +11:00
|
|
|
let(:object_json) do
|
|
|
|
{
|
2019-02-18 01:16:36 +11:00
|
|
|
id: 'https://example.com/actor#bar',
|
2019-02-17 13:38:25 +11:00
|
|
|
type: 'Note',
|
|
|
|
content: 'Lorem ipsum',
|
2019-02-18 01:16:36 +11:00
|
|
|
attributedTo: 'https://example.com/actor',
|
2019-02-17 13:38:25 +11:00
|
|
|
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
|
2020-08-24 22:11:47 +10:00
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when self-boost of a previously unknown status with correct attributedTo, inlined Collection in audience' do
|
2020-08-24 22:11:47 +10:00
|
|
|
let(:object_json) do
|
|
|
|
{
|
|
|
|
id: 'https://example.com/actor#bar',
|
|
|
|
type: 'Note',
|
|
|
|
content: 'Lorem ipsum',
|
|
|
|
attributedTo: 'https://example.com/actor',
|
|
|
|
to: {
|
2023-02-18 13:23:49 +11:00
|
|
|
type: 'OrderedCollection',
|
|
|
|
id: 'http://example.com/followers',
|
|
|
|
first: 'http://example.com/followers?page=true',
|
2023-02-19 01:33:41 +11:00
|
|
|
},
|
2020-08-24 22:11:47 +10:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a reblog by sender of status' do
|
|
|
|
expect(sender.reblogged?(sender.statuses.first)).to be true
|
|
|
|
end
|
|
|
|
end
|
2017-08-09 05:52:15 +10:00
|
|
|
end
|
|
|
|
|
2019-02-17 13:38:25 +11:00
|
|
|
context 'when the status belongs to a local user' do
|
|
|
|
before do
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
2019-02-14 04:36:23 +11:00
|
|
|
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
|
|
|
|
|
2019-02-17 13:38:25 +11:00
|
|
|
context 'when the sender is relayed' do
|
2023-02-20 15:24:14 +11:00
|
|
|
subject { described_class.new(json, sender, relayed_through_actor: relay_account) }
|
|
|
|
|
2023-07-21 02:23:48 +10:00
|
|
|
let!(:relay_account) { Fabricate(:account, inbox_url: 'https://relay.example.com/inbox', domain: 'relay.example.com') }
|
2019-02-17 13:38:25 +11:00
|
|
|
let!(:relay) { Fabricate(:relay, inbox_url: 'https://relay.example.com/inbox') }
|
|
|
|
|
2022-02-17 00:36:44 +11:00
|
|
|
let(:object_json) { 'https://example.com/actor/hello-world' }
|
|
|
|
|
|
|
|
before do
|
2024-02-16 21:56:12 +11:00
|
|
|
stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json), headers: { 'Content-Type': 'application/activity+json' })
|
2022-02-17 00:36:44 +11:00
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when the relay is enabled' do
|
2019-02-17 13:38:25 +11:00
|
|
|
before do
|
|
|
|
relay.update(state: :accepted)
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
2022-02-17 00:36:44 +11:00
|
|
|
it 'fetches the remote status' do
|
|
|
|
expect(a_request(:get, 'https://example.com/actor/hello-world')).to have_been_made
|
|
|
|
expect(Status.find_by(uri: 'https://example.com/actor/hello-world').text).to eq 'Hello world'
|
2019-02-17 13:38:25 +11:00
|
|
|
end
|
2019-02-14 04:36:23 +11:00
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when the relay is disabled' do
|
2019-02-17 13:38:25 +11:00
|
|
|
before do
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
2022-02-17 00:36:44 +11:00
|
|
|
it 'does not fetch the remote status' do
|
2023-02-20 12:33:27 +11:00
|
|
|
expect(a_request(:get, 'https://example.com/actor/hello-world')).to_not have_been_made
|
2022-02-17 00:36:44 +11:00
|
|
|
expect(Status.find_by(uri: 'https://example.com/actor/hello-world')).to be_nil
|
2019-02-17 13:38:25 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create anything' do
|
|
|
|
expect(sender.statuses.count).to eq 0
|
|
|
|
end
|
2019-02-14 04:36:23 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-17 13:38:25 +11:00
|
|
|
context 'when the sender has no relevance to local activity' do
|
|
|
|
before do
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
2019-02-14 04:36:23 +11:00
|
|
|
let(:object_json) do
|
|
|
|
{
|
2019-02-18 01:16:36 +11:00
|
|
|
id: 'https://example.com/actor#bar',
|
2019-02-14 04:36:23 +11:00
|
|
|
type: 'Note',
|
|
|
|
content: 'Lorem ipsum',
|
|
|
|
to: 'http://example.com/followers',
|
2019-06-05 07:24:31 +10:00
|
|
|
attributedTo: 'https://example.com/actor',
|
2019-02-14 04:36:23 +11:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-02-17 13:38:25 +11:00
|
|
|
it 'does not create anything' do
|
|
|
|
expect(sender.statuses.count).to eq 0
|
2019-02-14 04:36:23 +11:00
|
|
|
end
|
2017-08-09 05:52:15 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|