Merge commit 'b85c387c5c0527b0ad31c27031a09d361826c5fc' into glitch-soc/merge-upstream

Conflicts:
- `config/initializers/content_security_policy.rb`:
  Kept our version, it was not affected by upstream's bug.
This commit is contained in:
Claire
2023-06-10 16:48:01 +02:00
178 changed files with 1616 additions and 1109 deletions

View File

@@ -0,0 +1,6 @@
inherit_from: ../../.rubocop.yml
# Anonymous controllers in specs cannot access described_class
# https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/cop/rspec/described_class.rb#L36-L39
RSpec/DescribedClass:
SkipBlocks: true

View File

@@ -99,7 +99,7 @@ RSpec.describe AccountsController do
end
end
context do
context 'with a normal account in an HTML request' do
before do
get :show, params: { username: account.username, format: format }
end
@@ -173,7 +173,7 @@ RSpec.describe AccountsController do
end
end
context do
context 'with a normal account in a JSON request' do
before do
get :show, params: { username: account.username, format: format }
end
@@ -314,7 +314,7 @@ RSpec.describe AccountsController do
it_behaves_like 'cacheable response'
end
context do
context 'with a normal account in an RSS request' do
before do
get :show, params: { username: account.username, format: format }
end

View File

@@ -88,7 +88,7 @@ RSpec.describe ActivityPub::CollectionsController do
context 'with signature' do
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
context do
context 'when getting a featured resource' do
before do
get :show, params: { id: 'featured', account_username: account.username }
end

View File

@@ -20,4 +20,16 @@ describe Admin::AccountActionsController do
expect(response).to have_http_status(:success)
end
end
describe 'POST #create' do
let(:account) { Fabricate(:account) }
it 'records the account action' do
expect do
post :create, params: { account_id: account.id, admin_account_action: { type: 'silence' } }
end.to change { account.strikes.count }.by(1)
expect(response).to redirect_to(admin_account_path(account.id))
end
end
end

View File

@@ -309,4 +309,128 @@ RSpec.describe Admin::AccountsController do
end
end
end
describe 'POST #unsensitive' do
subject { post :unsensitive, params: { id: account.id } }
let(:current_user) { Fabricate(:user, role: role) }
let(:account) { Fabricate(:account, sensitized_at: 1.year.ago) }
context 'when user is admin' do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'marks accounts not sensitized' do
subject
expect(account.reload).to_not be_sensitized
expect(response).to redirect_to admin_account_path(account.id)
end
end
context 'when user is not admin' do
let(:role) { UserRole.everyone }
it 'fails to change account' do
subject
expect(response).to have_http_status 403
end
end
end
describe 'POST #unsilence' do
subject { post :unsilence, params: { id: account.id } }
let(:current_user) { Fabricate(:user, role: role) }
let(:account) { Fabricate(:account, silenced_at: 1.year.ago) }
context 'when user is admin' do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'marks accounts not silenced' do
subject
expect(account.reload).to_not be_silenced
expect(response).to redirect_to admin_account_path(account.id)
end
end
context 'when user is not admin' do
let(:role) { UserRole.everyone }
it 'fails to change account' do
subject
expect(response).to have_http_status 403
end
end
end
describe 'POST #unsuspend' do
subject { post :unsuspend, params: { id: account.id } }
let(:current_user) { Fabricate(:user, role: role) }
let(:account) { Fabricate(:account) }
before do
account.suspend!
end
context 'when user is admin' do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'marks accounts not suspended' do
subject
expect(account.reload).to_not be_suspended
expect(response).to redirect_to admin_account_path(account.id)
end
end
context 'when user is not admin' do
let(:role) { UserRole.everyone }
it 'fails to change account' do
subject
expect(response).to have_http_status 403
end
end
end
describe 'POST #destroy' do
subject { post :destroy, params: { id: account.id } }
let(:current_user) { Fabricate(:user, role: role) }
let(:account) { Fabricate(:account) }
before do
account.suspend!
end
context 'when user is admin' do
let(:role) { UserRole.find_by(name: 'Admin') }
before do
allow(Admin::AccountDeletionWorker).to receive(:perform_async).with(account.id)
end
it 'destroys the account' do
subject
expect(Admin::AccountDeletionWorker).to have_received(:perform_async).with(account.id)
expect(response).to redirect_to admin_account_path(account.id)
end
end
context 'when user is not admin' do
let(:role) { UserRole.everyone }
it 'fails to change account' do
subject
expect(response).to have_http_status 403
end
end
end
end

View File

@@ -73,4 +73,30 @@ describe Admin::AnnouncementsController do
expect(flash.notice).to match(I18n.t('admin.announcements.destroyed_msg'))
end
end
describe 'POST #publish' do
subject { post :publish, params: { id: announcement.id } }
let(:announcement) { Fabricate(:announcement, published_at: nil) }
it 'marks announcement published' do
subject
expect(announcement.reload).to be_published
expect(response).to redirect_to admin_announcements_path
end
end
describe 'POST #unpublish' do
subject { post :unpublish, params: { id: announcement.id } }
let(:announcement) { Fabricate(:announcement, published_at: 4.days.ago) }
it 'marks announcement as not published' do
subject
expect(announcement.reload).to_not be_published
expect(response).to redirect_to admin_announcements_path
end
end
end

View File

@@ -56,4 +56,45 @@ describe Admin::RelaysController do
end
end
end
describe 'DELETE #destroy' do
let(:relay) { Fabricate(:relay) }
it 'deletes an existing relay' do
delete :destroy, params: { id: relay.id }
expect { relay.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(response).to redirect_to(admin_relays_path)
end
end
describe 'POST #enable' do
let(:relay) { Fabricate(:relay, state: :idle) }
before do
stub_request(:post, /example.com/).to_return(status: 200)
end
it 'updates a relay from idle to pending' do
post :enable, params: { id: relay.id }
expect(relay.reload).to be_pending
expect(response).to redirect_to(admin_relays_path)
end
end
describe 'POST #disable' do
let(:relay) { Fabricate(:relay, state: :pending) }
before do
stub_request(:post, /example.com/).to_return(status: 200)
end
it 'updates a relay from pending to idle' do
post :disable, params: { id: relay.id }
expect(relay.reload).to be_idle
expect(response).to redirect_to(admin_relays_path)
end
end
end

View File

@@ -20,7 +20,7 @@ describe Admin::StatusesController do
end
describe 'GET #index' do
context do
context 'with a valid account' do
before do
get :index, params: { account_id: account.id }
end
@@ -41,6 +41,16 @@ describe Admin::StatusesController do
end
end
describe 'GET #show' do
before do
get :show, params: { account_id: account.id, id: status.id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'POST #batch' do
before do
post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } }

View File

@@ -40,7 +40,7 @@ describe Admin::Users::RolesController do
put :update, params: { user_id: user.id, user: { role_id: selected_role.id } }
end
context do
context 'with manage roles permissions' do
let(:permissions) { UserRole::FLAGS[:manage_roles] }
let(:position) { 1 }

View File

@@ -18,4 +18,68 @@ describe Admin::WarningPresetsController do
expect(response).to have_http_status(:success)
end
end
describe 'GET #edit' do
let(:account_warning_preset) { Fabricate(:account_warning_preset) }
it 'returns http success and renders edit' do
get :edit, params: { id: account_warning_preset.id }
expect(response).to have_http_status(:success)
expect(response).to render_template(:edit)
end
end
describe 'POST #create' do
context 'with valid data' do
it 'creates a new account_warning_preset and redirects' do
expect do
post :create, params: { account_warning_preset: { text: 'The account_warning_preset text.' } }
end.to change(AccountWarningPreset, :count).by(1)
expect(response).to redirect_to(admin_warning_presets_path)
end
end
context 'with invalid data' do
it 'does creates a new account_warning_preset and renders index' do
expect do
post :create, params: { account_warning_preset: { text: '' } }
end.to_not change(AccountWarningPreset, :count)
expect(response).to render_template(:index)
end
end
end
describe 'PUT #update' do
let(:account_warning_preset) { Fabricate(:account_warning_preset, text: 'Original text') }
context 'with valid data' do
it 'updates the account_warning_preset and redirects' do
put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: 'Updated text.' } }
expect(response).to redirect_to(admin_warning_presets_path)
end
end
context 'with invalid data' do
it 'does not update the account_warning_preset and renders index' do
put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: '' } }
expect(response).to render_template(:edit)
end
end
end
describe 'DELETE #destroy' do
let!(:account_warning_preset) { Fabricate(:account_warning_preset) }
it 'destroys the account_warning_preset and redirects' do
delete :destroy, params: { id: account_warning_preset.id }
expect { account_warning_preset.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(response).to redirect_to(admin_warning_presets_path)
end
end
end

View File

@@ -73,7 +73,7 @@ RSpec.describe Api::V1::AccountsController do
let(:scopes) { 'write:follows' }
let(:other_account) { Fabricate(:account, username: 'bob', locked: locked) }
context do
context 'when posting to an other account' do
before do
post :follow, params: { id: other_account.id }
end

View File

@@ -32,7 +32,7 @@ RSpec.describe Api::V1::Admin::AccountActionsController do
end
describe 'POST #create' do
context do
context 'with type of disable' do
before do
post :create, params: { account_id: account.id, type: 'disable' }
end

View File

@@ -96,7 +96,7 @@ RSpec.describe Api::V1::Admin::DomainAllowsController do
describe 'POST #create' do
let!(:domain_allow) { Fabricate(:domain_allow, domain: 'example.com') }
context do
context 'with a valid domain' do
before do
post :create, params: { domain: 'foo.bar.com' }
end

View File

@@ -120,7 +120,7 @@ RSpec.describe Api::V1::StatusesController do
describe 'POST #create' do
let(:scopes) { 'write:statuses' }
context do
context 'with a basic status body' do
before do
post :create, params: { status: 'Hello world' }
end

View File

@@ -79,7 +79,7 @@ RSpec.describe Auth::RegistrationsController do
request.env['devise.mapping'] = Devise.mappings[:user]
end
context do
context 'with open registrations' do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
@@ -111,7 +111,7 @@ RSpec.describe Auth::RegistrationsController do
end
end
context do
context 'when an accept language is present in headers' do
subject do
Setting.registrations_mode = 'open'
request.headers['Accept-Language'] = accept_language