Merge tag 'v3.3.1'
This commit is contained in:
commit
42437cacf0
120 changed files with 2046 additions and 460 deletions
|
|
@ -67,7 +67,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
end
|
||||
|
||||
context 'public' do
|
||||
context 'public with explicit public address' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
|
|
@ -85,7 +85,43 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
end
|
||||
|
||||
context 'unlisted' do
|
||||
context 'public with as:Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'as:Public',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'public'
|
||||
end
|
||||
end
|
||||
|
||||
context 'public with Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'Public',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'public'
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlisted with explicit public address' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
|
|
@ -103,6 +139,42 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
end
|
||||
|
||||
context 'unlisted with as:Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
cc: 'as:Public',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'unlisted'
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlisted with Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
cc: 'Public',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'unlisted'
|
||||
end
|
||||
end
|
||||
|
||||
context 'private' do
|
||||
let(:object_json) do
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,4 +49,24 @@ RSpec.describe ActivityPub::Activity::Delete do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the status has been reported' do
|
||||
describe '#perform' do
|
||||
subject { described_class.new(json, sender) }
|
||||
let!(:reporter) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
reporter.reports.create!(target_account: status.account, status_ids: [status.id], forwarded: false)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'marks the status as deleted' do
|
||||
expect(Status.find_by(id: status.id)).to be_nil
|
||||
end
|
||||
|
||||
it 'actually keeps a copy for inspection' do
|
||||
expect(Status.with_discarded.find_by(id: status.id)).to_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,62 +17,171 @@ RSpec.describe ActivityPub::Activity::Follow do
|
|||
describe '#perform' do
|
||||
subject { described_class.new(json, sender) }
|
||||
|
||||
context 'unlocked account' do
|
||||
before do
|
||||
subject.perform
|
||||
context 'with no prior follow' do
|
||||
context 'unlocked account' do
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'creates a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be true
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be true
|
||||
context 'silenced account following an unlocked account' do
|
||||
before do
|
||||
sender.touch(:silenced_at)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'creates a follow request' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
context 'unlocked account muting the sender' do
|
||||
before do
|
||||
recipient.mute!(sender)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'creates a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be true
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'locked account' do
|
||||
before do
|
||||
recipient.update(locked: true)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'creates a follow request' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'silenced account following an unlocked account' do
|
||||
context 'when a follow relationship already exists' do
|
||||
before do
|
||||
sender.touch(:silenced_at)
|
||||
subject.perform
|
||||
sender.active_relationships.create!(target_account: recipient, uri: 'bar')
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
context 'unlocked account' do
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a follow request' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
context 'silenced account following an unlocked account' do
|
||||
before do
|
||||
sender.touch(:silenced_at)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlocked account muting the sender' do
|
||||
before do
|
||||
recipient.mute!(sender)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'locked account' do
|
||||
before do
|
||||
recipient.update(locked: true)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlocked account muting the sender' do
|
||||
context 'when a follow request already exists' do
|
||||
before do
|
||||
recipient.mute!(sender)
|
||||
subject.perform
|
||||
sender.follow_requests.create!(target_account: recipient, uri: 'bar')
|
||||
end
|
||||
|
||||
it 'creates a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be true
|
||||
context 'silenced account following an unlocked account' do
|
||||
before do
|
||||
sender.touch(:silenced_at)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
context 'locked account' do
|
||||
before do
|
||||
recipient.update(locked: true)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
context 'locked account' do
|
||||
before do
|
||||
recipient.update(locked: true)
|
||||
subject.perform
|
||||
end
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'creates a follow request' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,23 +1,11 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::Activity::Move do
|
||||
let(:follower) { Fabricate(:account) }
|
||||
let(:old_account) { Fabricate(:account) }
|
||||
let(:new_account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
follower.follow!(old_account)
|
||||
|
||||
old_account.update!(uri: 'https://example.org/alice', domain: 'example.org', protocol: :activitypub, inbox_url: 'https://example.org/inbox')
|
||||
new_account.update!(uri: 'https://example.com/alice', domain: 'example.com', protocol: :activitypub, inbox_url: 'https://example.com/inbox', also_known_as: [old_account.uri])
|
||||
|
||||
stub_request(:post, 'https://example.org/inbox').to_return(status: 200)
|
||||
stub_request(:post, 'https://example.com/inbox').to_return(status: 200)
|
||||
|
||||
service_stub = double
|
||||
allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
|
||||
allow(service_stub).to receive(:call).and_return(new_account)
|
||||
end
|
||||
let(:follower) { Fabricate(:account) }
|
||||
let(:old_account) { Fabricate(:account, uri: 'https://example.org/alice', domain: 'example.org', protocol: :activitypub, inbox_url: 'https://example.org/inbox') }
|
||||
let(:new_account) { Fabricate(:account, uri: 'https://example.com/alice', domain: 'example.com', protocol: :activitypub, inbox_url: 'https://example.com/inbox', also_known_as: also_known_as) }
|
||||
let(:also_known_as) { [old_account.uri] }
|
||||
let(:returned_account) { new_account }
|
||||
|
||||
let(:json) do
|
||||
{
|
||||
|
|
@ -30,6 +18,17 @@ RSpec.describe ActivityPub::Activity::Move do
|
|||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
before do
|
||||
follower.follow!(old_account)
|
||||
|
||||
stub_request(:post, old_account.inbox_url).to_return(status: 200)
|
||||
stub_request(:post, new_account.inbox_url).to_return(status: 200)
|
||||
|
||||
service_stub = double
|
||||
allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
|
||||
allow(service_stub).to receive(:call).and_return(returned_account)
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
subject { described_class.new(json, old_account) }
|
||||
|
||||
|
|
@ -37,16 +36,70 @@ RSpec.describe ActivityPub::Activity::Move do
|
|||
subject.perform
|
||||
end
|
||||
|
||||
it 'sets moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to eq new_account.id
|
||||
context 'when all conditions are met' do
|
||||
it 'sets moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to eq new_account.id
|
||||
end
|
||||
|
||||
it 'makes followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be false
|
||||
end
|
||||
|
||||
it 'makes followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it 'makes followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be false
|
||||
context "when the new account can't be resolved" do
|
||||
let(:returned_account) { nil }
|
||||
|
||||
it 'does not set moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to be_nil
|
||||
end
|
||||
|
||||
it 'does not make followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be true
|
||||
end
|
||||
|
||||
it 'does not make followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it 'makes followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be true
|
||||
context 'when the new account does not references the old account' do
|
||||
let(:also_known_as) { [] }
|
||||
|
||||
it 'does not set moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to be_nil
|
||||
end
|
||||
|
||||
it 'does not make followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be true
|
||||
end
|
||||
|
||||
it 'does not make followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a Move has been recently processed' do
|
||||
around do |example|
|
||||
Redis.current.set("move_in_progress:#{old_account.id}", true, nx: true, ex: 7.days.seconds)
|
||||
example.run
|
||||
Redis.current.del("move_in_progress:#{old_account.id}")
|
||||
end
|
||||
|
||||
it 'does not set moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to be_nil
|
||||
end
|
||||
|
||||
it 'does not make followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be true
|
||||
end
|
||||
|
||||
it 'does not make followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,6 +42,14 @@ RSpec.describe ActivityPub::TagManager do
|
|||
expect(subject.to(status)).to eq [subject.uri_for(mentioned)]
|
||||
end
|
||||
|
||||
it "returns URIs of mentioned group's followers for direct statuses to groups" do
|
||||
status = Fabricate(:status, visibility: :direct)
|
||||
mentioned = Fabricate(:account, domain: 'remote.org', uri: 'https://remote.org/group', followers_url: 'https://remote.org/group/followers', actor_type: 'Group')
|
||||
status.mentions.create(account: mentioned)
|
||||
expect(subject.to(status)).to include(subject.uri_for(mentioned))
|
||||
expect(subject.to(status)).to include(subject.followers_uri_for(mentioned))
|
||||
end
|
||||
|
||||
it "returns URIs of mentions for direct silenced author's status only if they are followers or requesting to be" do
|
||||
bob = Fabricate(:account, username: 'bob')
|
||||
alice = Fabricate(:account, username: 'alice')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue