Add: フレンドサーバー (#61)

* Fix mastodon version

* テーブル作成

* Wip: フレンドサーバーフォローの承認を受信

* Wip: フレンド申請拒否を受信

* Wip: フォローリクエストを受理

* Wip: 相手からのフォロー・アンフォローを受理

* 普通のフォローとフレンドサーバーのフォローを区別するテストを追加

* ドメインブロックによるフォロー拒否

* ドメインブロックしたあと、申請中のフォロリクを取り下げる処理

* スタブに条件を追加

* Wip: 相手からのDelete信号に対応

* DB定義が消えていたので修正

* Wip: ローカル公開投稿をフレンドに送信する処理など

* Wip: 未収載+誰でもの投稿をフレンドに送る設定

* Wip: ローカル公開をそのまま送信する設定を考慮

* Fix test

* Wip: 他サーバーからのローカル公開投稿の受け入れ

* Wip: Web画面作成

* Fix test

* Wip: ローカル公開を連合TLに流す

* Wip: フレンドサーバーの削除ボタン

* Wip: メール通知や設定のテストなど

* Wip: 翻訳を作成

* Fix: 却下されたあとフォローボタンが表示されない問題

* Wip: 編集できない問題

* 有効にしていないフレンドサーバーをリストで無効表示
This commit is contained in:
KMY(雪あすか) 2023-10-09 11:51:15 +09:00 committed by GitHub
parent acb29e5b11
commit 87e858a202
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 1638 additions and 51 deletions

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
Fabricator(:friend_domain) do
domain 'example.com'
inbox_url 'https://example.com/inbox'
active_state :idle
passive_state :idle
available true
before_create { |friend_domain, _| friend_domain.inbox_url = "https://#{friend_domain.domain}/inbox" if friend_domain.inbox_url.blank? }
end

View file

@ -43,6 +43,35 @@ RSpec.describe ActivityPub::Activity::Accept do
end
end
context 'when sender is from friend server' do
subject { described_class.new(json, sender) }
let(:sender) { Fabricate(:account, domain: 'abc.com', url: 'https://abc.com/#actor') }
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', active_state: :pending, active_follow_activity_id: 'https://abc-123/456') }
before do
allow(RemoteAccountRefreshWorker).to receive(:perform_async)
Fabricate(:follow_request, account: recipient, target_account: sender)
subject.perform
end
it 'creates a follow relationship' do
expect(recipient.following?(sender)).to be true
end
it 'removes the follow request' do
expect(recipient.requested?(sender)).to be false
end
it 'queues a refresh' do
expect(RemoteAccountRefreshWorker).to have_received(:perform_async).with(sender.id)
end
it 'friend server is not changed' do
expect(friend.reload.i_am_pending?).to be true
end
end
context 'when given a relay' do
subject { described_class.new(json, sender) }
@ -68,4 +97,26 @@ RSpec.describe ActivityPub::Activity::Accept do
expect(relay.reload.accepted?).to be true
end
end
context 'when given a friend server' do
subject { described_class.new(json, sender) }
let(:sender) { Fabricate(:account, domain: 'abc.com', url: 'https://abc.com/#actor') }
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', active_state: :pending, active_follow_activity_id: 'https://abc-123/456') }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Accept',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: 'https://abc-123/456',
}.with_indifferent_access
end
it 'marks the friend as accepted' do
subject.perform
expect(friend.reload.i_am_accepted?).to be true
end
end
end

View file

@ -234,6 +234,25 @@ RSpec.describe ActivityPub::Activity::Create do
end
end
context 'when public_unlisted with LocalPublic' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
to: ['http://example.com/followers', 'LocalPublic'],
cc: 'https://www.w3.org/ns/activitystreams#Public',
}
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.visibility).to eq 'public_unlisted'
end
end
context 'when private' do
let(:object_json) do
{
@ -411,6 +430,17 @@ RSpec.describe ActivityPub::Activity::Create do
end
end
context 'with public_unlisted with LocalPublic' do
let(:searchable_by) { ['http://example.com/followers', 'LocalPublic'] }
it 'create status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.searchability).to eq 'public_unlisted'
end
end
context 'with private' do
let(:searchable_by) { 'http://example.com/followers' }
@ -1462,6 +1492,30 @@ RSpec.describe ActivityPub::Activity::Create do
end
end
context 'when sender is in friend server' do
subject { described_class.new(json, sender, delivery: true) }
before do
Fabricate(:friend_domain, domain: sender.domain, active_state: :accepted, passive_state: :accepted)
subject.perform
end
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
}
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.text).to eq 'Lorem ipsum'
end
end
context 'when the sender has no relevance to local activity' do
subject { described_class.new(json, sender, delivery: true) }

View file

@ -73,4 +73,30 @@ RSpec.describe ActivityPub::Activity::Delete do
end
end
end
context 'when given a friend server' do
subject { described_class.new(json, sender) }
before do
Fabricate(:friend_domain, domain: 'abc.com', inbox_url: 'https://abc.com/inbox', passive_state: :accepted)
stub_request(:post, 'https://abc.com/inbox')
end
let(:sender) { Fabricate(:account, domain: 'abc.com', url: 'https://abc.com/#actor') }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Delete',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: 'https://www.w3.org/ns/activitystreams#Public',
}.with_indifferent_access
end
it 'marks the friend as deleted' do
subject.perform
expect(FriendDomain.find_by(domain: 'abc.com')).to be_nil
end
end
end

View file

@ -37,6 +37,23 @@ RSpec.describe ActivityPub::Activity::Follow do
end
end
context 'with an unlocked account from friend server' do
let!(:friend) { Fabricate(:friend_domain, domain: sender.domain, passive_state: :idle) }
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 change friend server passive status' do
expect(friend.they_are_idle?).to be true
end
end
context 'when silenced account following an unlocked account' do
before do
sender.touch(:silenced_at)
@ -285,4 +302,148 @@ RSpec.describe ActivityPub::Activity::Follow do
end
end
end
context 'when given a friend server' do
subject { described_class.new(json, sender) }
let(:sender) { Fabricate(:account, domain: 'abc.com', url: 'https://abc.com/#actor') }
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', passive_state: :idle) }
let!(:owner_user) { Fabricate(:user, role: UserRole.find_by(name: 'Owner')) }
let!(:patch_user) { Fabricate(:user, role: Fabricate(:user_role, name: 'OhagiOps', permissions: UserRole::FLAGS[:manage_federation])) }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Follow',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: 'https://www.w3.org/ns/activitystreams#Public',
}.with_indifferent_access
end
it 'marks the friend as pending' do
subject.perform
expect(friend.reload.they_are_pending?).to be true
expect(friend.passive_follow_activity_id).to eq 'foo'
end
context 'when no record' do
before do
friend.update(domain: 'def.com')
end
it 'marks the friend as pending' do
subject.perform
friend = FriendDomain.find_by(domain: 'abc.com')
expect(friend).to_not be_nil
expect(friend.they_are_pending?).to be true
expect(friend.passive_follow_activity_id).to eq 'foo'
end
end
context 'with sending email' do
around do |example|
queue_adapter = ActiveJob::Base.queue_adapter
ActiveJob::Base.queue_adapter = :test
example.run
ActiveJob::Base.queue_adapter = queue_adapter
end
it 'perform' do
expect { subject.perform }.to have_enqueued_mail(AdminMailer, :new_pending_friend_server)
.with(hash_including(params: { recipient: owner_user.account })).once
.and(have_enqueued_mail(AdminMailer, :new_pending_friend_server).with(hash_including(params: { recipient: patch_user.account })).once)
.and(have_enqueued_mail.at_most(2))
end
end
context 'when after rejected' do
before do
friend.update(passive_state: :rejected)
end
it 'marks the friend as pending' do
subject.perform
expect(friend.reload.they_are_pending?).to be true
expect(friend.passive_follow_activity_id).to eq 'foo'
end
end
context 'when unlocked' do
before do
friend.update(unlocked: true)
stub_request(:post, 'https://example.com/inbox')
end
it 'marks the friend as accepted' do
subject.perform
friend = FriendDomain.find_by(domain: 'abc.com')
expect(friend).to_not be_nil
expect(friend.they_are_accepted?).to be true
expect(a_request(:post, 'https://example.com/inbox').with(body: hash_including({
id: 'foo#accepts/friends',
type: 'Accept',
object: 'foo',
}))).to have_been_made.once
end
end
context 'when unlocked on admin settings' do
before do
Form::AdminSettings.new(unlocked_friend: '1').save
stub_request(:post, 'https://example.com/inbox')
end
it 'marks the friend as accepted' do
subject.perform
friend = FriendDomain.find_by(domain: 'abc.com')
expect(friend).to_not be_nil
expect(friend.they_are_accepted?).to be true
expect(a_request(:post, 'https://example.com/inbox').with(body: hash_including({
id: 'foo#accepts/friends',
type: 'Accept',
object: 'foo',
}))).to have_been_made.once
end
end
context 'when already accepted' do
before do
friend.update(passive_state: :accepted)
stub_request(:post, 'https://example.com/inbox')
end
it 'marks the friend as accepted' do
subject.perform
friend = FriendDomain.find_by(domain: 'abc.com')
expect(friend).to_not be_nil
expect(friend.they_are_accepted?).to be true
expect(a_request(:post, 'https://example.com/inbox').with(body: hash_including({
id: 'foo#accepts/friends',
type: 'Accept',
object: 'foo',
}))).to have_been_made.once
end
end
context 'when domain blocked' do
before do
friend.update(domain: 'def.com')
end
it 'marks the friend rejected' do
Fabricate(:domain_block, domain: 'abc.com', reject_friend: true)
subject.perform
friend = FriendDomain.find_by(domain: 'abc.com')
expect(friend).to be_nil
end
end
end
end

View file

@ -122,6 +122,30 @@ RSpec.describe ActivityPub::Activity::Reject do
end
end
context 'when sender is from friend server' do
subject { described_class.new(json, sender) }
let(:sender) { Fabricate(:account, domain: 'abc.com', url: 'https://abc.com/#actor') }
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', active_state: :pending, active_follow_activity_id: 'https://abc-123/456') }
before do
Fabricate(:follow_request, account: recipient, target_account: sender)
subject.perform
end
it 'does not create a follow relationship' do
expect(recipient.following?(sender)).to be false
end
it 'removes the follow request' do
expect(recipient.requested?(sender)).to be false
end
it 'friend server is not changed' do
expect(friend.reload.i_am_pending?).to be true
end
end
context 'when given a relay' do
subject { described_class.new(json, sender) }
@ -147,4 +171,26 @@ RSpec.describe ActivityPub::Activity::Reject do
expect(relay.reload.rejected?).to be true
end
end
context 'when given a friend' do
subject { described_class.new(json, sender) }
let(:sender) { Fabricate(:account, domain: 'abc.com', url: 'https://abc.com/#actor') }
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', active_state: :pending, active_follow_activity_id: 'https://abc-123/456') }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Reject',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: 'https://abc-123/456',
}.with_indifferent_access
end
it 'marks the friend as rejected' do
subject.perform
expect(friend.reload.i_am_rejected?).to be true
end
end
end

View file

@ -145,6 +145,13 @@ RSpec.describe ActivityPub::Activity::Undo do
expect(sender.following?(recipient)).to be false
end
it 'deletes follow from sender to recipient when has friend' do
friend = Fabricate(:friend_domain, domain: sender.domain, passive_state: :accepted)
subject.perform
expect(sender.following?(recipient)).to be false
expect(friend.they_are_accepted?).to be true
end
context 'with only object uri' do
let(:object_json) { 'bar' }
@ -153,6 +160,25 @@ RSpec.describe ActivityPub::Activity::Undo do
expect(sender.following?(recipient)).to be false
end
end
context 'when for a friend' do
let(:sender) { Fabricate(:account, domain: 'abc.com', url: 'https://abc.com/#actor') }
let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', passive_state: :accepted, passive_follow_activity_id: 'bar') }
let(:object_json) do
{
id: 'bar',
type: 'Follow',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: 'https://www.w3.org/ns/activitystreams#Public',
}
end
it 'deletes follow from this server to friend' do
subject.perform
expect(friend.reload.they_are_idle?).to be true
expect(friend.passive_follow_activity_id).to be_nil
end
end
end
context 'with Like' do

View file

@ -27,6 +27,11 @@ RSpec.describe ActivityPub::TagManager do
expect(subject.to(status)).to eq ['https://www.w3.org/ns/activitystreams#Public']
end
it 'returns followers collection for public_unlisted status' do
status = Fabricate(:status, visibility: :public_unlisted)
expect(subject.to(status)).to eq [account_followers_url(status.account)]
end
it 'returns followers collection for unlisted status' do
status = Fabricate(:status, visibility: :unlisted)
expect(subject.to(status)).to eq [account_followers_url(status.account)]
@ -69,12 +74,34 @@ RSpec.describe ActivityPub::TagManager do
end
end
describe '#to_for_friend' do
it 'returns followers collection for public_unlisted status' do
status = Fabricate(:status, visibility: :public_unlisted)
expect(subject.to_for_friend(status)).to eq [account_followers_url(status.account), 'LocalPublic']
end
it 'returns followers collection for unlisted status' do
status = Fabricate(:status, visibility: :unlisted)
expect(subject.to_for_friend(status)).to eq [account_followers_url(status.account)]
end
it 'returns followers collection for private status' do
status = Fabricate(:status, visibility: :private)
expect(subject.to_for_friend(status)).to eq [account_followers_url(status.account)]
end
end
describe '#cc' do
it 'returns followers collection for public status' do
status = Fabricate(:status, visibility: :public)
expect(subject.cc(status)).to eq [account_followers_url(status.account)]
end
it 'returns public collection for public_unlisted status' do
status = Fabricate(:status, visibility: :public_unlisted)
expect(subject.cc(status)).to eq ['https://www.w3.org/ns/activitystreams#Public']
end
it 'returns public collection for unlisted status' do
status = Fabricate(:status, visibility: :unlisted)
expect(subject.cc(status)).to eq ['https://www.w3.org/ns/activitystreams#Public']
@ -114,6 +141,74 @@ RSpec.describe ActivityPub::TagManager do
end
end
describe '#cc_for_misskey' do
let(:user) { Fabricate(:user) }
before do
user.settings.update(reject_unlisted_subscription: true, reject_public_unlisted_subscription: true)
user.save
end
it 'returns public collection for public status' do
status = Fabricate(:status, visibility: :public)
expect(subject.cc_for_misskey(status)).to eq [account_followers_url(status.account)]
end
it 'returns empty array for public_unlisted status' do
status = Fabricate(:status, account: user.account, visibility: :public_unlisted)
expect(subject.cc_for_misskey(status)).to eq []
end
it 'returns empty array for unlisted status' do
status = Fabricate(:status, account: user.account, visibility: :unlisted)
expect(subject.cc_for_misskey(status)).to eq []
end
end
describe '#searchable_by' do
it 'returns public collection for public status' do
status = Fabricate(:status, searchability: :public)
expect(subject.searchable_by(status)).to eq ['https://www.w3.org/ns/activitystreams#Public']
end
it 'returns followers collection for public_unlisted status' do
status = Fabricate(:status, searchability: :public_unlisted)
expect(subject.searchable_by(status)).to eq [account_followers_url(status.account)]
end
it 'returns followers collection for private status' do
status = Fabricate(:status, searchability: :private)
expect(subject.searchable_by(status)).to eq [account_followers_url(status.account)]
end
it 'returns empty array for direct status' do
status = Fabricate(:status, searchability: :direct)
expect(subject.searchable_by(status)).to eq []
end
it 'returns as:Limited array for limited status' do
status = Fabricate(:status, searchability: :limited)
expect(subject.searchable_by(status)).to eq ['as:Limited']
end
end
describe '#searchable_by_for_friend' do
it 'returns public collection for public status' do
status = Fabricate(:status, account: Fabricate(:account, searchability: :public), searchability: :public)
expect(subject.searchable_by_for_friend(status)).to eq ['https://www.w3.org/ns/activitystreams#Public']
end
it 'returns public collection for public_unlisted status' do
status = Fabricate(:status, account: Fabricate(:account, searchability: :public), searchability: :public_unlisted)
expect(subject.searchable_by_for_friend(status)).to eq [account_followers_url(status.account), 'LocalPublic']
end
it 'returns followers collection for private status' do
status = Fabricate(:status, account: Fabricate(:account, searchability: :public), searchability: :private)
expect(subject.searchable_by_for_friend(status)).to eq [account_followers_url(status.account)]
end
end
describe '#local_uri?' do
it 'returns false for non-local URI' do
expect(subject.local_uri?('http://example.com/123')).to be false

View file

@ -24,12 +24,14 @@ describe StatusReachFinder do
it 'send status' do
expect(subject.inboxes).to include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to_not include 'https://foo.bar/inbox'
end
end
context 'with non-follower' do
it 'send status' do
expect(subject.inboxes).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to_not include 'https://foo.bar/inbox'
end
end
end
@ -92,6 +94,103 @@ describe StatusReachFinder do
expect(subject.inboxes_for_misskey).to_not include 'https://foo.bar/inbox'
end
end
context 'when has distributable friend server' do
let(:sender_software) { 'misskey' }
let(:searchability) { :public }
before { Fabricate(:friend_domain, domain: 'foo.bar', inbox_url: 'https://foo.bar/inbox', available: true, active_state: :accepted, passive_state: :accepted, pseudo_relay: true) }
it 'send status without friend server' do
expect(subject.inboxes).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_misskey).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to include 'https://foo.bar/inbox'
end
end
end
context 'when this server has a friend' do
let(:bob) { Fabricate(:account, username: 'bob', domain: 'foo.bar', protocol: :activitypub, inbox_url: 'https://foo.bar/inbox') }
context 'with follower' do
before do
Fabricate(:friend_domain, domain: 'foo.bar', active_state: :accepted)
bob.follow!(alice)
end
it 'send status' do
expect(subject.inboxes).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to include 'https://foo.bar/inbox'
end
end
context 'with non-follower' do
before do
Fabricate(:friend_domain, domain: 'foo.bar', active_state: :accepted)
end
it 'send status' do
expect(subject.inboxes).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to_not include 'https://foo.bar/inbox'
end
end
context 'with pending' do
before do
Fabricate(:friend_domain, domain: 'foo.bar', active_state: :pending)
bob.follow!(alice)
end
it 'send status' do
expect(subject.inboxes).to include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to_not include 'https://foo.bar/inbox'
end
end
context 'when unavailable' do
before do
Fabricate(:friend_domain, domain: 'foo.bar', active_state: :accepted, available: false)
bob.follow!(alice)
end
it 'send status' do
expect(subject.inboxes).to include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to_not include 'https://foo.bar/inbox'
end
end
context 'when distributable' do
before do
Fabricate(:friend_domain, domain: 'foo.bar', active_state: :accepted, passive_state: :accepted, pseudo_relay: true)
bob.follow!(alice)
end
it 'send status' do
expect(subject.inboxes).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to include 'https://foo.bar/inbox'
end
end
context 'when distributable and not following' do
before do
Fabricate(:friend_domain, domain: 'foo.bar', inbox_url: 'https://foo.bar/inbox', active_state: :accepted, passive_state: :accepted, pseudo_relay: true)
end
it 'send status' do
expect(subject.inboxes).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to include 'https://foo.bar/inbox'
end
end
end
context 'when it contains distributable friend server' do
before { Fabricate(:friend_domain, domain: 'foo.bar', inbox_url: 'https://foo.bar/inbox', available: true, active_state: :accepted, passive_state: :accepted, pseudo_relay: true) }
it 'includes the inbox of the mentioned account' do
expect(subject.inboxes).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_misskey).to_not include 'https://foo.bar/inbox'
expect(subject.inboxes_for_friend).to include 'https://foo.bar/inbox'
end
end
context 'when it contains mentions of remote accounts' do
@ -255,4 +354,99 @@ describe StatusReachFinder do
end
end
end
describe '#inboxes_for_friend and distributables' do
subject { described_class.new(status).inboxes_for_friend }
let(:visibility) { :public }
let(:searchability) { :public }
let(:alice) { Fabricate(:account, username: 'alice') }
let(:status) { Fabricate(:status, account: alice, visibility: visibility, searchability: searchability) }
context 'when a simple case' do
before do
Fabricate(:friend_domain, domain: 'abc.com', inbox_url: 'https://abc.com/inbox', active_state: :accepted, passive_state: :accepted, pseudo_relay: true, available: true)
Fabricate(:friend_domain, domain: 'def.com', inbox_url: 'https://def.com/inbox', active_state: :accepted, passive_state: :accepted, pseudo_relay: true, available: true)
Fabricate(:friend_domain, domain: 'ghi.com', inbox_url: 'https://ghi.com/inbox', active_state: :accepted, passive_state: :accepted, pseudo_relay: true, available: false)
Fabricate(:friend_domain, domain: 'jkl.com', inbox_url: 'https://jkl.com/inbox', active_state: :accepted, passive_state: :accepted, pseudo_relay: false, available: true)
Fabricate(:friend_domain, domain: 'mno.com', inbox_url: 'https://mno.com/inbox', active_state: :accepted, passive_state: :pending, pseudo_relay: true, available: true)
Fabricate(:friend_domain, domain: 'pqr.com', inbox_url: 'https://pqr.com/inbox', active_state: :accepted, passive_state: :accepted, pseudo_relay: true, available: true)
Fabricate(:unavailable_domain, domain: 'pqr.com')
end
it 'returns friend servers' do
expect(subject).to include 'https://abc.com/inbox'
expect(subject).to include 'https://def.com/inbox'
end
it 'not contains unavailable friends' do
expect(subject).to_not include 'https://ghi.com/inbox'
end
it 'not contains no-relay friends' do
expect(subject).to_not include 'https://jkl.com/inbox'
end
it 'not contains no-mutual friends' do
expect(subject).to_not include 'https://mno.com/inbox'
end
it 'not contains unavailable domain friends' do
expect(subject).to_not include 'https://pqr.com/inbox'
end
context 'when public visibility' do
let(:visibility) { :public }
let(:searchability) { :direct }
it 'returns friend servers' do
expect(subject).to_not eq []
end
end
context 'when public_unlsited visibility' do
let(:visibility) { :public_unlisted }
let(:searchability) { :direct }
it 'returns friend servers' do
expect(subject).to_not eq []
end
end
context 'when unlsited visibility with public searchability' do
let(:visibility) { :unlisted }
let(:searchability) { :public }
it 'returns friend servers' do
expect(subject).to_not eq []
end
end
context 'when unlsited visibility with public_unlisted searchability' do
let(:visibility) { :unlisted }
let(:searchability) { :public_unlisted }
it 'returns friend servers' do
expect(subject).to_not eq []
end
end
context 'when unlsited visibility with private searchability' do
let(:visibility) { :unlisted }
let(:searchability) { :private }
it 'returns empty servers' do
expect(subject).to eq []
end
end
context 'when private visibility' do
let(:visibility) { :private }
it 'returns friend servers' do
expect(subject).to eq []
end
end
end
end
end

View file

@ -64,6 +64,26 @@ RSpec.describe AdminMailer do
end
end
describe '.new_pending_friend_server' do
let(:recipient) { Fabricate(:account, username: 'Barklums') }
let(:friend) { Fabricate(:friend_domain, passive_state: :pending, domain: 'abc.com') }
let(:mail) { described_class.with(recipient: recipient).new_pending_friend_server(friend) }
before do
recipient.user.update(locale: :en)
end
it 'renders the headers' do
expect(mail.subject).to eq('New friend server up for review on cb6e6126.ngrok.io (abc.com)')
expect(mail.to).to eq [recipient.user_email]
expect(mail.from).to eq ['notifications@localhost']
end
it 'renders the body' do
expect(mail.body.encoded).to match 'The new friend server abc.com is waiting for your review. You can approve or reject this application.'
end
end
describe '.new_trends' do
let(:recipient) { Fabricate(:account, username: 'Snurf') }
let(:links) { [] }

View file

@ -8,6 +8,11 @@ class AdminMailerPreview < ActionMailer::Preview
AdminMailer.with(recipient: Account.first).new_pending_account(User.pending.first)
end
# Preview this email at http://localhost:3000/rails/mailers/admin_mailer/new_pending_friend_server
def new_pending_friend_server
AdminMailer.with(recipient: Account.first).new_pending_friend_server(User.pending.first)
end
# Preview this email at http://localhost:3000/rails/mailers/admin_mailer/new_trends
def new_trends
AdminMailer.with(recipient: Account.first).new_trends(PreviewCard.joins(:trend).limit(3), Tag.limit(3), Status.joins(:trend).where(reblog_of_id: nil).limit(3))

View file

@ -0,0 +1,83 @@
# frozen_string_literal: true
require 'rails_helper'
describe FriendDomain do
let(:friend) { Fabricate(:friend_domain, domain: 'foo.bar', inbox_url: 'https://foo.bar/inbox') }
before do
stub_request(:post, 'https://foo.bar/inbox')
end
describe '#follow!' do
it 'call inbox' do
friend.follow!
expect(friend.active_follow_activity_id).to_not be_nil
expect(friend.i_am_pending?).to be true
expect(a_request(:post, 'https://foo.bar/inbox').with(body: hash_including({
id: friend.active_follow_activity_id,
type: 'Follow',
actor: 'https://cb6e6126.ngrok.io/actor',
object: 'https://www.w3.org/ns/activitystreams#Public',
}))).to have_been_made.once
end
end
describe '#unfollow!' do
it 'call inbox' do
friend.update(active_follow_activity_id: 'ohagi')
friend.unfollow!
expect(friend.active_follow_activity_id).to be_nil
expect(friend.i_am_idle?).to be true
expect(a_request(:post, 'https://foo.bar/inbox').with(body: hash_including({
type: 'Undo',
object: {
id: 'ohagi',
type: 'Follow',
actor: 'https://cb6e6126.ngrok.io/actor',
object: 'https://www.w3.org/ns/activitystreams#Public',
},
}))).to have_been_made.once
end
end
describe '#accept!' do
it 'call inbox' do
friend.update(passive_follow_activity_id: 'ohagi', passive_state: :pending)
friend.accept!
expect(friend.they_are_accepted?).to be true
expect(a_request(:post, 'https://foo.bar/inbox').with(body: hash_including({
id: 'ohagi#accepts/friends',
type: 'Accept',
actor: 'https://cb6e6126.ngrok.io/actor',
object: 'ohagi',
}))).to have_been_made.once
end
end
describe '#reject!' do
it 'call inbox' do
friend.update(passive_follow_activity_id: 'ohagi', passive_state: :pending)
friend.reject!
expect(friend.they_are_rejected?).to be true
expect(a_request(:post, 'https://foo.bar/inbox').with(body: hash_including({
id: 'ohagi#rejects/friends',
type: 'Reject',
actor: 'https://cb6e6126.ngrok.io/actor',
object: 'ohagi',
}))).to have_been_made.once
end
end
describe '#delete!' do
it 'call inbox' do
friend.update(active_state: :pending)
friend.destroy
expect(a_request(:post, 'https://foo.bar/inbox').with(body: hash_including({
type: 'Delete',
actor: 'https://cb6e6126.ngrok.io/actor',
object: 'https://www.w3.org/ns/activitystreams#Public',
}))).to have_been_made.once
end
end
end

View file

@ -89,7 +89,7 @@ RSpec.describe PublicFeed do
end
it 'excludes public_unlisted statuses' do
expect(subject).to_not include(public_unlisted_status.id)
expect(subject).to include(public_unlisted_status.id)
end
end
@ -105,7 +105,7 @@ RSpec.describe PublicFeed do
end
it 'excludes public_unlisted statuses' do
expect(subject).to_not include(public_unlisted_status.id)
expect(subject).to include(public_unlisted_status.id)
end
end
end

View file

@ -114,7 +114,7 @@ RSpec.describe Status do
end
end
describe '#searchability' do
describe '#compute_searchability' do
subject { Fabricate(:status, account: account, searchability: status_searchability) }
let(:account_searchability) { :public }
@ -146,6 +146,18 @@ RSpec.describe Status do
end
end
context 'when public-public_unlisted' do
let(:status_searchability) { :public_unlisted }
it 'returns public' do
expect(subject.compute_searchability).to eq 'public'
end
it 'returns public_unlisted for local' do
expect(subject.compute_searchability_local).to eq 'public_unlisted'
end
end
context 'when public-private' do
let(:status_searchability) { :private }

View file

@ -10,9 +10,13 @@ RSpec.describe BlockDomainService, type: :service do
let!(:bad_status_with_attachment) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
let!(:bad_attachment) { Fabricate(:media_attachment, account: bad_account, status: bad_status_with_attachment, file: attachment_fixture('attachment.jpg')) }
let!(:already_banned_account) { Fabricate(:account, username: 'badguy', domain: 'evil.org', suspended: true, silenced: true) }
let!(:bad_friend) { Fabricate(:friend_domain, domain: 'evil.org', inbox_url: 'https://evil.org/inbox', active_state: :accepted, passive_state: :accepted) }
describe 'for a suspension' do
before do
stub_request(:post, 'https://evil.org/inbox').with(body: hash_including({
type: 'Delete',
}))
subject.call(DomainBlock.create!(domain: 'evil.org', severity: :suspend))
end
@ -41,6 +45,21 @@ RSpec.describe BlockDomainService, type: :service do
expect { bad_status_with_attachment.reload }.to raise_exception ActiveRecord::RecordNotFound
expect { bad_attachment.reload }.to raise_exception ActiveRecord::RecordNotFound
end
it 'removes remote friend from that domain' do
expect(FriendDomain.find_by(domain: 'evil.org')).to be_nil
end
end
describe 'for rejecting friend only' do
before do
stub_request(:post, 'https://evil.org/inbox')
subject.call(DomainBlock.create!(domain: 'evil.org', severity: :noop, reject_friend: true))
end
it 'removes remote friend from that domain' do
expect(FriendDomain.find_by(domain: 'evil.org')).to be_nil
end
end
describe 'for a silence with reject media' do

View file

@ -278,7 +278,7 @@ RSpec.describe FanOutOnWriteService, type: :service do
it 'is broadcast publicly' do
expect(redis).to have_received(:publish).with('timeline:hashtag:hoge', anything)
expect(redis).to have_received(:publish).with('timeline:public:local', anything)
expect(redis).to_not have_received(:publish).with('timeline:public', anything)
expect(redis).to have_received(:publish).with('timeline:public', anything)
end
context 'with list' do