Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from https://github.com/mastodon/mastodon, unmodified.
144 lines
4.3 KiB
Ruby
144 lines
4.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe 'OmniAuth callbacks' do
|
|
shared_examples 'omniauth provider callbacks' do |provider|
|
|
subject { post send :"user_#{provider}_omniauth_callback_path" }
|
|
|
|
context 'with full information in response' do
|
|
before do
|
|
mock_omniauth(provider, {
|
|
provider: provider.to_s,
|
|
uid: '123',
|
|
info: {
|
|
verified: 'true',
|
|
email: '[email protected]',
|
|
},
|
|
})
|
|
end
|
|
|
|
context 'without a matching user' do
|
|
it 'creates a user and an identity and redirects to root path' do
|
|
expect { subject }
|
|
.to change(User, :count)
|
|
.by(1)
|
|
.and change(Identity, :count)
|
|
.by(1)
|
|
.and change(LoginActivity, :count)
|
|
.by(1)
|
|
|
|
expect(User.last.email).to eq('[email protected]')
|
|
expect(Identity.find_by(user: User.last).uid).to eq('123')
|
|
expect(response).to redirect_to(root_path)
|
|
end
|
|
end
|
|
|
|
context 'with a matching user and no matching identity' do
|
|
before do
|
|
Fabricate(:user, email: '[email protected]')
|
|
end
|
|
|
|
context 'when ALLOW_UNSAFE_AUTH_PROVIDER_REATTACH is set to true' do
|
|
around do |example|
|
|
ClimateControl.modify ALLOW_UNSAFE_AUTH_PROVIDER_REATTACH: 'true' do
|
|
example.run
|
|
end
|
|
end
|
|
|
|
it 'matches the existing user, creates an identity, and redirects to root path' do
|
|
expect { subject }
|
|
.to not_change(User, :count)
|
|
.and change(Identity, :count)
|
|
.by(1)
|
|
.and change(LoginActivity, :count)
|
|
.by(1)
|
|
|
|
expect(Identity.find_by(user: User.last).uid).to eq('123')
|
|
expect(response).to redirect_to(root_path)
|
|
end
|
|
end
|
|
|
|
context 'when ALLOW_UNSAFE_AUTH_PROVIDER_REATTACH is not set to true' do
|
|
it 'does not match the existing user or create an identity, and redirects to login page' do
|
|
expect { subject }
|
|
.to not_change(User, :count)
|
|
.and not_change(Identity, :count)
|
|
.and not_change(LoginActivity, :count)
|
|
|
|
expect(response).to redirect_to(new_user_session_url)
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'with a matching user and a matching identity' do
|
|
before do
|
|
user = Fabricate(:user, email: '[email protected]')
|
|
Fabricate(:identity, user: user, uid: '123', provider: provider)
|
|
end
|
|
|
|
it 'matches the existing records and redirects to root path' do
|
|
expect { subject }
|
|
.to not_change(User, :count)
|
|
.and not_change(Identity, :count)
|
|
.and change(LoginActivity, :count)
|
|
.by(1)
|
|
|
|
expect(response).to redirect_to(root_path)
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'with a response missing email address' do
|
|
before do
|
|
mock_omniauth(provider, {
|
|
provider: provider.to_s,
|
|
uid: '123',
|
|
info: {
|
|
verified: 'true',
|
|
},
|
|
})
|
|
end
|
|
|
|
it 'redirects to the auth setup page' do
|
|
expect { subject }
|
|
.to change(User, :count)
|
|
.by(1)
|
|
.and change(Identity, :count)
|
|
.by(1)
|
|
.and change(LoginActivity, :count)
|
|
.by(1)
|
|
|
|
expect(response).to redirect_to(auth_setup_path(missing_email: '1'))
|
|
end
|
|
end
|
|
|
|
context 'when a user cannot be built' do
|
|
before do
|
|
allow(User).to receive(:find_for_omniauth).and_return(User.new)
|
|
end
|
|
|
|
it 'redirects to the new user signup page' do
|
|
expect { subject }
|
|
.to not_change(User, :count)
|
|
.and not_change(Identity, :count)
|
|
.and not_change(LoginActivity, :count)
|
|
|
|
expect(response).to redirect_to(new_user_registration_url)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '#openid_connect', if: Rails.configuration.x.omniauth.oidc_enabled? && ENV['OIDC_SCOPE'].present? do
|
|
it_behaves_like 'omniauth provider callbacks', :openid_connect
|
|
end
|
|
|
|
describe '#cas', if: Rails.configuration.x.omniauth.cas_enabled? do
|
|
it_behaves_like 'omniauth provider callbacks', :cas
|
|
end
|
|
|
|
describe '#saml', if: Rails.configuration.x.omniauth.saml_enabled? do
|
|
it_behaves_like 'omniauth provider callbacks', :saml
|
|
end
|
|
end
|