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

This commit is contained in:
KMY 2023-12-21 08:37:12 +09:00
commit a6b57e3890
154 changed files with 7762 additions and 1748 deletions

View file

@ -123,7 +123,7 @@ RSpec.describe ActivityPub::RepliesController do
end
it 'uses ids for remote toots' do
remote_replies = page_json[:items].select { |x| !x.is_a?(Hash) }
remote_replies = page_json[:items].reject { |x| x.is_a?(Hash) }
expect(remote_replies.all? { |item| item.is_a?(String) && !ActivityPub::TagManager.instance.local_uri?(item) }).to be true
end

View file

@ -19,14 +19,6 @@ RSpec.describe Admin::Settings::BrandingController do
end
describe 'PUT #update' do
around do |example|
before = Setting.site_short_description
Setting.site_short_description = nil
example.run
Setting.site_short_description = before
Setting.new_setting_key = nil
end
it 'cannot create a setting value for a non-admin key' do
expect(Setting.new_setting_key).to be_blank

View file

@ -1,135 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::DirectoriesController do
render_views
let(:user) { Fabricate(:user, confirmed_at: nil) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:follows') }
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
describe 'GET #show' do
context 'with no params' do
before do
local_unconfirmed_account = Fabricate(
:account,
domain: nil,
user: Fabricate(:user, confirmed_at: nil, approved: true),
username: 'local_unconfirmed'
)
local_unconfirmed_account.create_account_stat!
local_unapproved_account = Fabricate(
:account,
domain: nil,
user: Fabricate(:user, confirmed_at: 10.days.ago),
username: 'local_unapproved'
)
local_unapproved_account.create_account_stat!
local_unapproved_account.user.update(approved: false)
local_undiscoverable_account = Fabricate(
:account,
domain: nil,
user: Fabricate(:user, confirmed_at: 10.days.ago, approved: true),
discoverable: false,
username: 'local_undiscoverable'
)
local_undiscoverable_account.create_account_stat!
excluded_from_timeline_account = Fabricate(
:account,
domain: 'host.example',
discoverable: true,
username: 'remote_excluded_from_timeline'
)
excluded_from_timeline_account.create_account_stat!
Fabricate(:block, account: user.account, target_account: excluded_from_timeline_account)
domain_blocked_account = Fabricate(
:account,
domain: 'test.example',
discoverable: true,
username: 'remote_domain_blocked'
)
domain_blocked_account.create_account_stat!
Fabricate(:account_domain_block, account: user.account, domain: 'test.example')
end
it 'returns the local discoverable account and the remote discoverable account' do
local_discoverable_account = Fabricate(
:account,
domain: nil,
user: Fabricate(:user, confirmed_at: 10.days.ago, approved: true),
discoverable: true,
username: 'local_discoverable'
)
local_discoverable_account.create_account_stat!
eligible_remote_account = Fabricate(
:account,
domain: 'host.example',
discoverable: true,
username: 'eligible_remote'
)
eligible_remote_account.create_account_stat!
get :show
expect(response).to have_http_status(200)
expect(body_as_json.size).to eq(2)
expect(body_as_json.pluck(:id)).to contain_exactly(eligible_remote_account.id.to_s, local_discoverable_account.id.to_s)
end
end
context 'when asking for local accounts only' do
it 'returns only the local accounts' do
user = Fabricate(:user, confirmed_at: 10.days.ago, approved: true)
local_account = Fabricate(:account, domain: nil, user: user)
remote_account = Fabricate(:account, domain: 'host.example')
local_account.create_account_stat!
remote_account.create_account_stat!
get :show, params: { local: '1' }
expect(response).to have_http_status(200)
expect(body_as_json.size).to eq(1)
expect(body_as_json.first[:id]).to include(local_account.id.to_s)
expect(response.body).to_not include(remote_account.id.to_s)
end
end
context 'when ordered by active' do
it 'returns accounts in order of most recent status activity' do
old_stat = Fabricate(:account_stat, last_status_at: 1.day.ago)
new_stat = Fabricate(:account_stat, last_status_at: 1.minute.ago)
get :show, params: { order: 'active' }
expect(response).to have_http_status(200)
expect(body_as_json.size).to eq(2)
expect(body_as_json.first[:id]).to include(new_stat.account_id.to_s)
expect(body_as_json.second[:id]).to include(old_stat.account_id.to_s)
end
end
context 'when ordered by new' do
it 'returns accounts in order of creation' do
account_old = Fabricate(:account_stat).account
travel_to 10.seconds.from_now
account_new = Fabricate(:account_stat).account
get :show, params: { order: 'new' }
expect(response).to have_http_status(200)
expect(body_as_json.size).to eq(2)
expect(body_as_json.first[:id]).to include(account_new.id.to_s)
expect(body_as_json.second[:id]).to include(account_old.id.to_s)
end
end
end
end

View file

@ -6,12 +6,6 @@ RSpec.describe Api::V1::Trends::LinksController do
render_views
describe 'GET #index' do
around do |example|
previous = Setting.trends
example.run
Setting.trends = previous
end
context 'when trends are disabled' do
before { Setting.trends = false }

View file

@ -6,12 +6,6 @@ RSpec.describe Api::V1::Trends::StatusesController do
render_views
describe 'GET #index' do
around do |example|
previous = Setting.trends
example.run
Setting.trends = previous
end
context 'when trends are disabled' do
before { Setting.trends = false }

View file

@ -6,12 +6,6 @@ RSpec.describe Api::V1::Trends::TagsController do
render_views
describe 'GET #index' do
around do |example|
previous = Setting.trends
example.run
Setting.trends = previous
end
context 'when trends are disabled' do
before { Setting.trends = false }

View file

@ -6,12 +6,6 @@ RSpec.describe Auth::RegistrationsController do
render_views
shared_examples 'checks for enabled registrations' do |path|
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects if it is in single user mode while it is open for registration' do
Fabricate(:account)
Setting.registrations_mode = 'open'
@ -82,12 +76,6 @@ RSpec.describe Auth::RegistrationsController do
end
context 'with open registrations' do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'returns http success' do
Setting.registrations_mode = 'open'
get :new
@ -120,12 +108,6 @@ RSpec.describe Auth::RegistrationsController do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@ -146,12 +128,6 @@ RSpec.describe Auth::RegistrationsController do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'false' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'does not create user' do
subject
user = User.find_by(email: 'test@example.com')
@ -166,12 +142,6 @@ RSpec.describe Auth::RegistrationsController do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@ -194,12 +164,6 @@ RSpec.describe Auth::RegistrationsController do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', invite_code: invite.code, agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@ -224,14 +188,6 @@ RSpec.describe Auth::RegistrationsController do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', invite_code: invite.code, agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
require_invite_text = Setting.require_invite_text
example.run
Setting.require_invite_text = require_invite_text
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path

View file

@ -11,12 +11,6 @@ describe AccountControllerConcern do
end
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
before do
routes.draw { get 'success' => 'anonymous#success' }
end

View file

@ -5,7 +5,7 @@ require 'rails_helper'
describe EmojisController do
render_views
let(:emoji) { Fabricate(:custom_emoji) }
let(:emoji) { Fabricate(:custom_emoji, shortcode: 'coolcat') }
describe 'GET #show' do
let(:response) { get :show, params: { id: emoji.id, format: :json } }

View file

@ -194,60 +194,49 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
add_webauthn_credential(user)
end
context 'when creation succeeds' do
it 'adds a new credential to user credentials and does not change webauthn_id', :aggregate_failures do
controller.session[:webauthn_challenge] = challenge
expect do
post :create, params: { credential: new_webauthn_credential, nickname: nickname }
end.to change { user.webauthn_credentials.count }.by(1)
.and not_change(user, :webauthn_id)
expect(response).to have_http_status(200)
end
end
context 'when the nickname is already used' do
it 'fails' do
controller.session[:webauthn_challenge] = challenge
post :create, params: { credential: new_webauthn_credential, nickname: 'USB Key' }
expect(response).to have_http_status(422)
expect(flash[:error]).to be_present
end
end
context 'when the credential already exists' do
before do
user2 = Fabricate(:user)
public_key_credential = WebAuthn::Credential.from_create(new_webauthn_credential)
Fabricate(:webauthn_credential,
user_id: user2.id,
external_id: public_key_credential.id,
public_key: public_key_credential.public_key)
end
it 'fails' do
controller.session[:webauthn_challenge] = challenge
it 'adds a new credential to user credentials and does not change webauthn_id when creation succeeds', :aggregate_failures do
controller.session[:webauthn_challenge] = challenge
expect do
post :create, params: { credential: new_webauthn_credential, nickname: nickname }
end.to change { user.webauthn_credentials.count }.by(1)
.and not_change(user, :webauthn_id)
expect(response).to have_http_status(422)
expect(flash[:error]).to be_present
end
expect(response).to have_http_status(200)
end
it 'fails when the nickname is already used' do
controller.session[:webauthn_challenge] = challenge
post :create, params: { credential: new_webauthn_credential, nickname: 'USB Key' }
expect(response).to have_http_status(422)
expect(flash[:error]).to be_present
end
it 'fails when the credential already exists' do
public_key_credential = WebAuthn::Credential.from_create(new_webauthn_credential)
Fabricate(:webauthn_credential,
user_id: Fabricate(:user).id,
external_id: public_key_credential.id,
public_key: public_key_credential.public_key)
controller.session[:webauthn_challenge] = challenge
post :create, params: { credential: new_webauthn_credential, nickname: nickname }
expect(response).to have_http_status(422)
expect(flash[:error]).to be_present
end
end
context 'when user have not enabled webauthn' do
context 'when creation succeeds' do
it 'creates a webauthn credential' do
controller.session[:webauthn_challenge] = challenge
context 'when user have not enabled webauthn and creation succeeds' do
it 'creates a webauthn credential' do
controller.session[:webauthn_challenge] = challenge
expect do
post :create, params: { credential: new_webauthn_credential, nickname: nickname }
end.to change { user.webauthn_credentials.count }.by(1)
end
expect do
post :create, params: { credential: new_webauthn_credential, nickname: nickname }
end.to change { user.webauthn_credentials.count }.by(1)
end
end
end
@ -292,15 +281,13 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
add_webauthn_credential(user)
end
context 'when deletion succeeds' do
it 'redirects to 2FA methods list and shows flash success and deletes the credential', :aggregate_failures do
expect do
delete :destroy, params: { id: user.webauthn_credentials.take.id }
end.to change { user.webauthn_credentials.count }.by(-1)
it 'redirects to 2FA methods list and shows flash success and deletes the credential when deletion succeeds', :aggregate_failures do
expect do
delete :destroy, params: { id: user.webauthn_credentials.take.id }
end.to change { user.webauthn_credentials.count }.by(-1)
expect(response).to redirect_to settings_two_factor_authentication_methods_path
expect(flash[:success]).to be_present
end
expect(response).to redirect_to settings_two_factor_authentication_methods_path
expect(flash[:success]).to be_present
end
end