1
0
Fork 0
forked from gitea/nas

Merge remote-tracking branch 'parent/main' into upstream-20240326

This commit is contained in:
KMY 2024-03-26 09:08:20 +09:00
commit 6c9b221cb2
263 changed files with 4628 additions and 1518 deletions

View file

@ -5,6 +5,8 @@ require 'rails_helper'
RSpec.describe BlockDomainService do
subject { described_class.new }
let(:local_account) { Fabricate(:account) }
let(:bystander) { Fabricate(:account, domain: 'evil.org') }
let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') }
let!(:bad_status_plain) { Fabricate(:status, account: bad_account, text: 'You suck') }
let!(:bad_status_with_attachment) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
@ -20,36 +22,38 @@ RSpec.describe BlockDomainService do
stub_request(:post, 'https://evil.org/inbox').with(body: hash_including({
type: 'Delete',
}))
local_account.follow!(bad_account)
bystander.follow!(local_account)
end
it 'creates a domain block, suspends remote accounts with appropriate suspension date, records severed relationships and sends notification', :aggregate_failures do
subject.call(DomainBlock.create!(domain: 'evil.org', severity: :suspend))
end
it 'creates a domain block' do
expect(DomainBlock.blocked?('evil.org')).to be true
end
it 'removes remote accounts from that domain' do
# Suspends account with appropriate suspension date
expect(bad_account.reload.suspended?).to be true
end
it 'records suspension date appropriately' do
expect(bad_account.reload.suspended_at).to eq DomainBlock.find_by(domain: 'evil.org').created_at
end
it 'keeps already-banned accounts banned' do
# Keep already-suspended account without updating the suspension date
expect(already_banned_account.reload.suspended?).to be true
end
it 'does not overwrite suspension date of already-banned accounts' do
expect(already_banned_account.reload.suspended_at).to_not eq DomainBlock.find_by(domain: 'evil.org').created_at
end
it 'removes the remote accounts\'s statuses and media attachments' do
# Removes content
expect { bad_status_plain.reload }.to raise_exception ActiveRecord::RecordNotFound
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
# Records severed relationships
severed_relationships = local_account.severed_relationships.to_a
expect(severed_relationships.count).to eq 2
expect(severed_relationships[0].relationship_severance_event).to eq severed_relationships[1].relationship_severance_event
expect(severed_relationships.map { |rel| [rel.account, rel.target_account] }).to contain_exactly([bystander, local_account], [local_account, bad_account])
# Sends severed relationships notification
expect(LocalNotificationWorker).to have_enqueued_sidekiq_job(local_account.id, anything, 'AccountRelationshipSeveranceEvent', 'severed_relationships')
# Removes remote friend from that domain
expect(FriendDomain.find_by(domain: 'evil.org')).to be_nil
end
end
@ -66,31 +70,20 @@ RSpec.describe BlockDomainService do
end
describe 'for a silence with reject media' do
before do
it 'does not mark the domain as blocked, but silences accounts with an appropriate silencing date, clears media', :aggregate_failures, :sidekiq_inline do
subject.call(DomainBlock.create!(domain: 'evil.org', severity: :silence, reject_media: true))
end
it 'does not create a domain block' do
expect(DomainBlock.blocked?('evil.org')).to be false
end
it 'silences remote accounts from that domain' do
# Silences account with appropriate silecing date
expect(bad_account.reload.silenced?).to be true
end
it 'records suspension date appropriately' do
expect(bad_account.reload.silenced_at).to eq DomainBlock.find_by(domain: 'evil.org').created_at
end
it 'keeps already-banned accounts banned' do
# Keeps already-silenced accounts without updating the silecing date
expect(already_banned_account.reload.silenced?).to be true
end
it 'does not overwrite suspension date of already-banned accounts' do
expect(already_banned_account.reload.silenced_at).to_not eq DomainBlock.find_by(domain: 'evil.org').created_at
end
it 'leaves the domains status and attachments, but clears media', :sidekiq_inline do
# Leaves posts but clears media
expect { bad_status_plain.reload }.to_not raise_error
expect { bad_status_with_attachment.reload }.to_not raise_error
expect { bad_attachment.reload }.to_not raise_error