Merge tag 'v2.9.2' into instance_only_statuses

This commit is contained in:
Renato "Lond" Cerqueira
2019-06-25 19:44:59 +02:00
534 changed files with 12629 additions and 7877 deletions

View File

@ -63,9 +63,9 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
service = double(call: true)
allow(UnblockDomainService).to receive(:new).and_return(service)
domain_block = Fabricate(:domain_block)
delete :destroy, params: { id: domain_block.id, domain_block: { retroactive: '1' } }
delete :destroy, params: { id: domain_block.id }
expect(service).to have_received(:call).with(domain_block, true)
expect(service).to have_received(:call).with(domain_block)
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.destroyed_msg')
expect(response).to redirect_to(admin_instances_path(limited: '1'))
end

View File

@ -61,7 +61,7 @@ describe Api::V1::Accounts::CredentialsController do
describe 'with invalid data' do
before do
patch :update, params: { note: 'This is too long. ' * 10 }
patch :update, params: { note: 'This is too long. ' * 30 }
end
it 'returns http unprocessable entity' do

View File

@ -0,0 +1,57 @@
require 'rails_helper'
RSpec.describe Api::V1::Admin::AccountActionsController, type: :controller do
render_views
let(:role) { 'moderator' }
let(:user) { Fabricate(:user, role: role, account: Fabricate(:account, username: 'alice')) }
let(:scopes) { 'admin:read admin:write' }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:account) { Fabricate(:user).account }
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { wrong_role }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'POST #create' do
before do
post :create, params: { account_id: account.id, type: 'disable' }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'performs action against account' do
expect(account.reload.user_disabled?).to be true
end
it 'logs action' do
log_item = Admin::ActionLog.last
expect(log_item).to_not be_nil
expect(log_item.action).to eq :disable
expect(log_item.account_id).to eq user.account_id
expect(log_item.target_id).to eq account.user.id
end
end
end

View File

@ -0,0 +1,147 @@
require 'rails_helper'
RSpec.describe Api::V1::Admin::AccountsController, type: :controller do
render_views
let(:role) { 'moderator' }
let(:user) { Fabricate(:user, role: role, account: Fabricate(:account, username: 'alice')) }
let(:scopes) { 'admin:read admin:write' }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:account) { Fabricate(:user).account }
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { wrong_role }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'GET #index' do
before do
get :index
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'GET #show' do
before do
get :show, params: { id: account.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'POST #approve' do
before do
account.user.update(approved: false)
post :approve, params: { id: account.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'approves user' do
expect(account.reload.user_approved?).to be true
end
end
describe 'POST #reject' do
before do
account.user.update(approved: false)
post :reject, params: { id: account.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'removes user' do
expect(User.where(id: account.user.id).count).to eq 0
end
end
describe 'POST #enable' do
before do
account.user.update(disabled: true)
post :enable, params: { id: account.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'enables user' do
expect(account.reload.user_disabled?).to be false
end
end
describe 'POST #unsuspend' do
before do
account.touch(:suspended_at)
post :unsuspend, params: { id: account.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'unsuspends account' do
expect(account.reload.suspended?).to be false
end
end
describe 'POST #unsilence' do
before do
account.touch(:silenced_at)
post :unsilence, params: { id: account.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'unsilences account' do
expect(account.reload.silenced?).to be false
end
end
end

View File

@ -0,0 +1,109 @@
require 'rails_helper'
RSpec.describe Api::V1::Admin::ReportsController, type: :controller do
render_views
let(:role) { 'moderator' }
let(:user) { Fabricate(:user, role: role, account: Fabricate(:account, username: 'alice')) }
let(:scopes) { 'admin:read admin:write' }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:report) { Fabricate(:report) }
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { wrong_role }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'GET #index' do
before do
get :index
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'GET #show' do
before do
get :show, params: { id: report.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'POST #resolve' do
before do
post :resolve, params: { id: report.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'POST #reopen' do
before do
post :reopen, params: { id: report.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'POST #assign_to_self' do
before do
post :assign_to_self, params: { id: report.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'POST #unassign' do
before do
post :unassign, params: { id: report.id }
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', 'user'
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
end

View File

@ -6,6 +6,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:other) { Fabricate(:user, account: Fabricate(:account, username: 'bob')) }
let(:third) { Fabricate(:user, account: Fabricate(:account, username: 'carol')) }
before do
allow(controller).to receive(:doorkeeper_token) { token }
@ -55,6 +56,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
mentioning_status = PostStatusService.new.call(other.account, text: 'Hello @alice')
@mention_from_status = mentioning_status.mentions.first
@favourite = FavouriteService.new.call(other.account, first_status)
@second_favourite = FavouriteService.new.call(third.account, first_status)
@follow = FollowService.new.call(other.account, 'alice')
end
@ -84,6 +86,66 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
end
end
describe 'from specified user' do
before do
get :index, params: { account_id: third.account.id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'includes favourite' do
expect(assigns(:notifications).map(&:activity)).to include(@second_favourite)
end
it 'excludes favourite' do
expect(assigns(:notifications).map(&:activity)).to_not include(@favourite)
end
it 'excludes mention' do
expect(assigns(:notifications).map(&:activity)).to_not include(@mention_from_status)
end
it 'excludes reblog' do
expect(assigns(:notifications).map(&:activity)).to_not include(@reblog_of_first_status)
end
it 'excludes follow' do
expect(assigns(:notifications).map(&:activity)).to_not include(@follow)
end
end
describe 'from nonexistent user' do
before do
get :index, params: { account_id: 'foo' }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'excludes favourite' do
expect(assigns(:notifications).map(&:activity)).to_not include(@favourite)
end
it 'excludes second favourite' do
expect(assigns(:notifications).map(&:activity)).to_not include(@second_favourite)
end
it 'excludes mention' do
expect(assigns(:notifications).map(&:activity)).to_not include(@mention_from_status)
end
it 'excludes reblog' do
expect(assigns(:notifications).map(&:activity)).to_not include(@reblog_of_first_status)
end
it 'excludes follow' do
expect(assigns(:notifications).map(&:activity)).to_not include(@follow)
end
end
describe 'with excluded mentions' do
before do
get :index, params: { exclude_types: ['mention'] }
@ -105,6 +167,10 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
expect(assigns(:notifications).map(&:activity)).to include(@favourite)
end
it 'includes third favourite' do
expect(assigns(:notifications).map(&:activity)).to include(@second_favourite)
end
it 'includes follow' do
expect(assigns(:notifications).map(&:activity)).to include(@follow)
end

View File

@ -10,14 +10,26 @@ RSpec.describe Api::V1::PollsController, type: :controller do
before { allow(controller).to receive(:doorkeeper_token) { token } }
describe 'GET #show' do
let(:poll) { Fabricate(:poll) }
let(:poll) { Fabricate(:poll, status: Fabricate(:status, visibility: visibility)) }
before do
get :show, params: { id: poll.id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
context 'when parent status is public' do
let(:visibility) { 'public' }
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
context 'when parent status is private' do
let(:visibility) { 'private' }
it 'returns http not found' do
expect(response).to have_http_status(404)
end
end
end
end

View File

@ -1,6 +1,6 @@
require 'rails_helper'
describe Settings::NotificationsController do
describe Settings::Preferences::NotificationsController do
render_views
let(:user) { Fabricate(:user) }
@ -28,7 +28,7 @@ describe Settings::NotificationsController do
}
}
expect(response).to redirect_to(settings_notifications_path)
expect(response).to redirect_to(settings_preferences_notifications_path)
user.reload
expect(user.settings['notification_emails']['follow']).to be true
expect(user.settings['interactions']['must_be_follower']).to be false

View File

@ -1,6 +1,6 @@
require 'rails_helper'
describe Settings::PreferencesController do
describe Settings::Preferences::OtherController do
render_views
let(:user) { Fabricate(:user, filtered_languages: []) }
@ -20,7 +20,7 @@ describe Settings::PreferencesController do
it 'updates the user record' do
put :update, params: { user: { locale: 'en', chosen_languages: ['es', 'fr', ''] } }
expect(response).to redirect_to(settings_preferences_path)
expect(response).to redirect_to(settings_preferences_other_path)
user.reload
expect(user.locale).to eq 'en'
expect(user.chosen_languages).to eq ['es', 'fr']
@ -37,7 +37,7 @@ describe Settings::PreferencesController do
}
}
expect(response).to redirect_to(settings_preferences_path)
expect(response).to redirect_to(settings_preferences_other_path)
user.reload
expect(user.settings['boost_modal']).to be true
expect(user.settings['delete_modal']).to be false

View File

@ -3,8 +3,11 @@ public_key = keypair.public_key.to_pem
private_key = keypair.to_pem
Fabricator(:account) do
transient :suspended, :silenced
username { sequence(:username) { |i| "#{Faker::Internet.user_name(nil, %w(_))}#{i}" } }
last_webfingered_at { Time.now.utc }
public_key { public_key }
private_key { private_key }
suspended_at { |attrs| attrs[:suspended] ? Time.now.utc : nil }
silenced_at { |attrs| attrs[:silenced] ? Time.now.utc : nil }
end

View File

@ -58,21 +58,6 @@ RSpec.describe ActivityPub::Activity::Announce do
end
end
context 'self-boost of a previously unknown status with missing attributedTo' do
let(:object_json) do
{
id: 'https://example.com/actor#bar',
type: 'Note',
content: 'Lorem ipsum',
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
context 'self-boost of a previously unknown status with correct attributedTo' do
let(:object_json) do
{
@ -122,6 +107,7 @@ RSpec.describe ActivityPub::Activity::Announce do
type: 'Note',
content: 'Lorem ipsum',
to: 'http://example.com/followers',
attributedTo: 'https://example.com/actor',
}
end
@ -141,6 +127,7 @@ RSpec.describe ActivityPub::Activity::Announce do
type: 'Note',
content: 'Lorem ipsum',
to: 'http://example.com/followers',
attributedTo: 'https://example.com/actor',
}
end
@ -161,6 +148,7 @@ RSpec.describe ActivityPub::Activity::Announce do
type: 'Note',
content: 'Lorem ipsum',
to: 'http://example.com/followers',
attributedTo: 'https://example.com/actor',
}
end

View File

@ -41,6 +41,22 @@ RSpec.describe ActivityPub::TagManager do
status.mentions.create(account: mentioned)
expect(subject.to(status)).to eq [subject.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')
foo = Fabricate(:account)
author = Fabricate(:account, username: 'author', silenced: true)
status = Fabricate(:status, visibility: :direct, account: author)
bob.follow!(author)
FollowRequest.create!(account: foo, target_account: author)
status.mentions.create(account: alice)
status.mentions.create(account: bob)
status.mentions.create(account: foo)
expect(subject.to(status)).to include(subject.uri_for(bob))
expect(subject.to(status)).to include(subject.uri_for(foo))
expect(subject.to(status)).to_not include(subject.uri_for(alice))
end
end
describe '#cc' do
@ -70,6 +86,22 @@ RSpec.describe ActivityPub::TagManager do
status.mentions.create(account: mentioned)
expect(subject.cc(status)).to include(subject.uri_for(mentioned))
end
it "returns URIs of mentions for silenced author's non-direct status only if they are followers or requesting to be" do
bob = Fabricate(:account, username: 'bob')
alice = Fabricate(:account, username: 'alice')
foo = Fabricate(:account)
author = Fabricate(:account, username: 'author', silenced: true)
status = Fabricate(:status, visibility: :public, account: author)
bob.follow!(author)
FollowRequest.create!(account: foo, target_account: author)
status.mentions.create(account: alice)
status.mentions.create(account: bob)
status.mentions.create(account: foo)
expect(subject.cc(status)).to include(subject.uri_for(bob))
expect(subject.cc(status)).to include(subject.uri_for(foo))
expect(subject.cc(status)).to_not include(subject.uri_for(alice))
end
end
describe '#local_uri?' do

View File

@ -168,13 +168,13 @@ RSpec.describe FeedManager do
it 'returns true for status by silenced account who recipient is not following' do
status = Fabricate(:status, text: 'Hello world', account: alice)
alice.update(silenced: true)
alice.silence!
expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be true
end
it 'returns false for status by followed silenced account' do
status = Fabricate(:status, text: 'Hello world', account: alice)
alice.update(silenced: true)
alice.silence!
bob.follow!(alice)
expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be false
end

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
require 'rails_helper'
require Rails.root.join('app', 'lib', 'sanitize_config.rb')
describe Sanitize::Config do
describe '::MASTODON_STRICT' do
subject { Sanitize::Config::MASTODON_STRICT }
it 'converts h1 to p' do
expect(Sanitize.fragment('<h1>Foo</h1>', subject)).to eq '<p>Foo</p>'
end
it 'converts ul to p' do
expect(Sanitize.fragment('<p>Check out:</p><ul><li>Foo</li><li>Bar</li></ul>', subject)).to eq '<p>Check out:</p><p>Foo<br>Bar</p>'
end
it 'converts p inside ul' do
expect(Sanitize.fragment('<ul><li><p>Foo</p><p>Bar</p></li><li>Baz</li></ul>', subject)).to eq '<p>Foo<br>Bar<br>Baz</p>'
end
it 'converts ul inside ul' do
expect(Sanitize.fragment('<ul><li>Foo</li><li><ul><li>Bar</li><li>Baz</li></ul></li></ul>', subject)).to eq '<p>Foo<br>Bar<br>Baz</p>'
end
end
end

View File

@ -15,7 +15,7 @@ describe StatusFilter do
context 'when status account is silenced' do
before do
status.account.update(silenced: true)
status.account.silence!
end
it { is_expected.to be_filtered }
@ -65,7 +65,7 @@ describe StatusFilter do
context 'when status account is silenced' do
before do
status.account.update(silenced: true)
status.account.silence!
end
it { is_expected.to be_filtered }

View File

@ -601,8 +601,8 @@ RSpec.describe Account, type: :model do
expect(account).to model_have_error_on_field(:display_name)
end
it 'is invalid if the note is longer than 160 characters' do
account = Fabricate.build(:account, note: Faker::Lorem.characters(161))
it 'is invalid if the note is longer than 500 characters' do
account = Fabricate.build(:account, note: Faker::Lorem.characters(501))
account.valid?
expect(account).to model_have_error_on_field(:note)
end
@ -647,8 +647,8 @@ RSpec.describe Account, type: :model do
expect(account).not_to model_have_error_on_field(:display_name)
end
it 'is valid even if the note is longer than 160 characters' do
account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(161))
it 'is valid even if the note is longer than 500 characters' do
account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(501))
account.valid?
expect(account).not_to model_have_error_on_field(:note)
end
@ -687,6 +687,23 @@ RSpec.describe Account, type: :model do
end
end
describe 'by_domain_and_subdomains' do
it 'returns exact domain matches' do
account = Fabricate(:account, domain: 'example.com')
expect(Account.by_domain_and_subdomains('example.com')).to eq [account]
end
it 'returns subdomains' do
account = Fabricate(:account, domain: 'foo.example.com')
expect(Account.by_domain_and_subdomains('example.com')).to eq [account]
end
it 'does not return partially matching domains' do
account = Fabricate(:account, domain: 'grexample.com')
expect(Account.by_domain_and_subdomains('example.com')).to_not eq [account]
end
end
describe 'expiring' do
it 'returns remote accounts with followers whose subscription expiration date is past or not given' do
local = Fabricate(:account, domain: nil)

View File

@ -35,7 +35,7 @@ describe StatusThreadingConcern do
end
it 'does not return conversation history from silenced and not followed users' do
jeff.update(silenced: true)
jeff.silence!
expect(reply3.ancestors(4, viewer)).to_not include(reply1)
end
@ -110,7 +110,7 @@ describe StatusThreadingConcern do
end
it 'does not return replies from silenced and not followed users' do
jeff.update(silenced: true)
jeff.silence!
expect(status.descendants(4, viewer)).to_not include(reply3)
end

View File

@ -21,23 +21,40 @@ RSpec.describe DomainBlock, type: :model do
end
end
describe 'blocked?' do
describe '.blocked?' do
it 'returns true if the domain is suspended' do
Fabricate(:domain_block, domain: 'domain', severity: :suspend)
expect(DomainBlock.blocked?('domain')).to eq true
Fabricate(:domain_block, domain: 'example.com', severity: :suspend)
expect(DomainBlock.blocked?('example.com')).to eq true
end
it 'returns false even if the domain is silenced' do
Fabricate(:domain_block, domain: 'domain', severity: :silence)
expect(DomainBlock.blocked?('domain')).to eq false
Fabricate(:domain_block, domain: 'example.com', severity: :silence)
expect(DomainBlock.blocked?('example.com')).to eq false
end
it 'returns false if the domain is not suspended nor silenced' do
expect(DomainBlock.blocked?('domain')).to eq false
expect(DomainBlock.blocked?('example.com')).to eq false
end
end
describe 'stricter_than?' do
describe '.rule_for' do
it 'returns rule matching a blocked domain' do
block = Fabricate(:domain_block, domain: 'example.com')
expect(DomainBlock.rule_for('example.com')).to eq block
end
it 'returns a rule matching a subdomain of a blocked domain' do
block = Fabricate(:domain_block, domain: 'example.com')
expect(DomainBlock.rule_for('sub.example.com')).to eq block
end
it 'returns a rule matching a blocked subdomain' do
block = Fabricate(:domain_block, domain: 'sub.example.com')
expect(DomainBlock.rule_for('sub.example.com')).to eq block
end
end
describe '#stricter_than?' do
it 'returns true if the new block has suspend severity while the old has lower severity' do
suspend = DomainBlock.new(domain: 'domain', severity: :suspend)
silence = DomainBlock.new(domain: 'domain', severity: :silence)

View File

@ -1,20 +1,14 @@
require 'rails_helper'
RSpec.describe BlockDomainService, type: :service do
let(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') }
let(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') }
let(:bad_status2) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
let(:bad_attachment) { Fabricate(:media_attachment, account: bad_account, status: bad_status2, file: attachment_fixture('attachment.jpg')) }
let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') }
let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') }
let!(:bad_status2) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
let!(:bad_attachment) { Fabricate(:media_attachment, account: bad_account, status: bad_status2, file: attachment_fixture('attachment.jpg')) }
let!(:already_banned_account) { Fabricate(:account, username: 'badguy', domain: 'evil.org', suspended: true, silenced: true) }
subject { BlockDomainService.new }
before do
bad_account
bad_status1
bad_status2
bad_attachment
end
describe 'for a suspension' do
before do
subject.call(DomainBlock.create!(domain: 'evil.org', severity: :suspend))
@ -28,6 +22,18 @@ RSpec.describe BlockDomainService, type: :service do
expect(Account.find_remote('badguy666', 'evil.org').suspended?).to be true
end
it 'records suspension date appropriately' do
expect(Account.find_remote('badguy666', 'evil.org').suspended_at).to eq DomainBlock.find_by(domain: 'evil.org').created_at
end
it 'keeps already-banned accounts banned' do
expect(Account.find_remote('badguy', 'evil.org').suspended?).to be true
end
it 'does not overwrite suspension date of already-banned accounts' do
expect(Account.find_remote('badguy', 'evil.org').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
expect { bad_status1.reload }.to raise_exception ActiveRecord::RecordNotFound
expect { bad_status2.reload }.to raise_exception ActiveRecord::RecordNotFound
@ -48,6 +54,18 @@ RSpec.describe BlockDomainService, type: :service do
expect(Account.find_remote('badguy666', 'evil.org').silenced?).to be true
end
it 'records suspension date appropriately' do
expect(Account.find_remote('badguy666', 'evil.org').silenced_at).to eq DomainBlock.find_by(domain: 'evil.org').created_at
end
it 'keeps already-banned accounts banned' do
expect(Account.find_remote('badguy', 'evil.org').silenced?).to be true
end
it 'does not overwrite suspension date of already-banned accounts' do
expect(Account.find_remote('badguy', 'evil.org').silenced_at).to_not eq DomainBlock.find_by(domain: 'evil.org').created_at
end
it 'leaves the domains status and attachements, but clears media' do
expect { bad_status1.reload }.not_to raise_error
expect { bad_status2.reload }.not_to raise_error

View File

@ -39,12 +39,12 @@ RSpec.describe NotifyService, type: :service do
end
it 'does not notify when sender is silenced and not followed' do
sender.update(silenced: true)
sender.silence!
is_expected.to_not change(Notification, :count)
end
it 'does not notify when recipient is suspended' do
recipient.update(suspended: true)
recipient.suspend!
is_expected.to_not change(Notification, :count)
end
@ -105,7 +105,7 @@ RSpec.describe NotifyService, type: :service do
end
it 'shows reblogs when disabled' do
recipient.follow!(sender, reblogs: true)
recipient.follow!(sender, reblogs: false)
is_expected.to change(Notification, :count)
end
end

View File

@ -1,10 +1,11 @@
require 'rails_helper'
RSpec.describe ProcessMentionsService, type: :service do
let(:account) { Fabricate(:account, username: 'alice') }
let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}") }
let(:account) { Fabricate(:account, username: 'alice') }
let(:visibility) { :public }
let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}", visibility: visibility) }
context 'OStatus' do
context 'OStatus with public toot' do
let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com') }
subject { ProcessMentionsService.new }
@ -23,6 +24,26 @@ RSpec.describe ProcessMentionsService, type: :service do
end
end
context 'OStatus with private toot' do
let(:visibility) { :private }
let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com') }
subject { ProcessMentionsService.new }
before do
stub_request(:post, remote_user.salmon_url)
subject.call(status)
end
it 'does not create a mention' do
expect(remote_user.mentions.where(status: status).count).to eq 0
end
it 'does not post to remote user\'s Salmon end point' do
expect(a_request(:post, remote_user.salmon_url)).to_not have_been_made
end
end
context 'ActivityPub' do
let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }

View File

@ -7,36 +7,33 @@ describe UnblockDomainService, type: :service do
describe 'call' do
before do
@silenced = Fabricate(:account, domain: 'example.com', silenced: true)
@suspended = Fabricate(:account, domain: 'example.com', suspended: true)
@independently_suspended = Fabricate(:account, domain: 'example.com', suspended_at: 1.hour.ago)
@independently_silenced = Fabricate(:account, domain: 'example.com', silenced_at: 1.hour.ago)
@domain_block = Fabricate(:domain_block, domain: 'example.com')
@silenced = Fabricate(:account, domain: 'example.com', silenced_at: @domain_block.created_at)
@suspended = Fabricate(:account, domain: 'example.com', suspended_at: @domain_block.created_at)
end
context 'without retroactive' do
it 'removes the domain block' do
subject.call(@domain_block, false)
expect_deleted_domain_block
end
it 'unsilences accounts and removes block' do
@domain_block.update(severity: :silence)
subject.call(@domain_block)
expect_deleted_domain_block
expect(@silenced.reload.silenced?).to be false
expect(@suspended.reload.suspended?).to be true
expect(@independently_suspended.reload.suspended?).to be true
expect(@independently_silenced.reload.silenced?).to be true
end
context 'with retroactive' do
it 'unsilences accounts and removes block' do
@domain_block.update(severity: :silence)
it 'unsuspends accounts and removes block' do
@domain_block.update(severity: :suspend)
subject.call(@domain_block, true)
expect_deleted_domain_block
expect(@silenced.reload.silenced).to be false
expect(@suspended.reload.suspended).to be true
end
it 'unsuspends accounts and removes block' do
@domain_block.update(severity: :suspend)
subject.call(@domain_block, true)
expect_deleted_domain_block
expect(@suspended.reload.suspended).to be false
expect(@silenced.reload.silenced).to be true
end
subject.call(@domain_block)
expect_deleted_domain_block
expect(@suspended.reload.suspended?).to be false
expect(@silenced.reload.silenced?).to be true
expect(@independently_suspended.reload.suspended?).to be true
expect(@independently_silenced.reload.silenced?).to be true
end
end