2020-12-08 15:28:05 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe ConfirmationsController, feature_category: :system_access do
|
2020-12-08 15:28:05 +05:30
|
|
|
include DeviseHelpers
|
|
|
|
|
|
|
|
before do
|
|
|
|
set_devise_mapping(context: @request)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#show' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let_it_be_with_reload(:user) { create(:user, :unconfirmed) }
|
|
|
|
let(:confirmation_token) { user.confirmation_token }
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
render_views
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
def perform_request
|
|
|
|
get :show, params: { confirmation_token: confirmation_token }
|
|
|
|
end
|
2020-12-08 15:28:05 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'when signup info is required' do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:current_user) { user }
|
|
|
|
user.set_role_required!
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
it 'does not redirect' do
|
|
|
|
expect(perform_request).not_to redirect_to(users_sign_up_welcome_path)
|
|
|
|
end
|
|
|
|
end
|
2020-12-08 15:28:05 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'user is already confirmed' do
|
2020-12-08 15:28:05 +05:30
|
|
|
before do
|
|
|
|
user.confirm
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders `new`' do
|
2021-09-04 01:27:46 +05:30
|
|
|
perform_request
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
expect(response).to render_template(:new)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays an error message' do
|
2021-09-04 01:27:46 +05:30
|
|
|
perform_request
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
expect(response.body).to include('Email was already confirmed, please try signing in')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not display the email of the user' do
|
2021-09-04 01:27:46 +05:30
|
|
|
perform_request
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
expect(response.body).not_to include(user.email)
|
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
it 'sets the username and caller_id in the context' do
|
|
|
|
expect(controller).to receive(:show).and_wrap_original do |m, *args|
|
|
|
|
m.call(*args)
|
|
|
|
|
|
|
|
expect(Gitlab::ApplicationContext.current)
|
2023-05-27 22:25:52 +05:30
|
|
|
.to include('meta.user' => user.username, 'meta.caller_id' => 'ConfirmationsController#show')
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
perform_request
|
|
|
|
end
|
2020-12-08 15:28:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'user accesses the link after the expiry of confirmation token has passed' do
|
|
|
|
before do
|
|
|
|
allow(Devise).to receive(:confirm_within).and_return(1.day)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders `new`' do
|
2021-09-04 01:27:46 +05:30
|
|
|
travel_to(3.days.from_now) { perform_request }
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
expect(response).to render_template(:new)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays an error message' do
|
2021-09-04 01:27:46 +05:30
|
|
|
travel_to(3.days.from_now) { perform_request }
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
expect(response.body).to include('Email needs to be confirmed within 1 day, please request a new one below')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not display the email of the user' do
|
2021-09-04 01:27:46 +05:30
|
|
|
travel_to(3.days.from_now) { perform_request }
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
expect(response.body).not_to include(user.email)
|
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
it 'sets the username and caller_id in the context' do
|
|
|
|
expect(controller).to receive(:show).and_wrap_original do |m, *args|
|
|
|
|
m.call(*args)
|
|
|
|
|
|
|
|
expect(Gitlab::ApplicationContext.current)
|
2023-05-27 22:25:52 +05:30
|
|
|
.to include('meta.user' => user.username, 'meta.caller_id' => 'ConfirmationsController#show')
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
travel_to(3.days.from_now) { perform_request }
|
|
|
|
end
|
2020-12-08 15:28:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an invalid confirmation token' do
|
|
|
|
let(:confirmation_token) { 'invalid_confirmation_token' }
|
|
|
|
|
|
|
|
it 'renders `new`' do
|
2021-09-04 01:27:46 +05:30
|
|
|
perform_request
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
expect(response).to render_template(:new)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays an error message' do
|
2021-09-04 01:27:46 +05:30
|
|
|
perform_request
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
expect(response.body).to include('Confirmation token is invalid')
|
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
it 'sets the the caller_id in the context' do
|
|
|
|
expect(controller).to receive(:show).and_wrap_original do |m, *args|
|
|
|
|
expect(Gitlab::ApplicationContext.current)
|
|
|
|
.to include('meta.caller_id' => 'ConfirmationsController#show')
|
|
|
|
|
|
|
|
m.call(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
perform_request
|
|
|
|
end
|
2020-12-08 15:28:05 +05:30
|
|
|
end
|
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
describe '#create' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject(:perform_request) { post(:create, params: { user: { email: user.email } }) }
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
before do
|
|
|
|
stub_feature_flags(identity_verification: false)
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'when signup info is required' do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:current_user) { user }
|
|
|
|
user.set_role_required!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not redirect' do
|
|
|
|
expect(perform_request).not_to redirect_to(users_sign_up_welcome_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context "when `email_confirmation_setting` is set to `soft`" do
|
2021-12-11 22:18:48 +05:30
|
|
|
before do
|
2023-05-27 22:25:52 +05:30
|
|
|
stub_application_setting_enum('email_confirmation_setting', 'soft')
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context 'when reCAPTCHA is disabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(recaptcha_enabled: false)
|
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'successfully sends password reset when reCAPTCHA is not solved' do
|
|
|
|
perform_request
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(response).to redirect_to(dashboard_projects_path)
|
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context 'when reCAPTCHA is enabled' do
|
2022-07-23 23:45:48 +05:30
|
|
|
before do
|
2023-05-27 22:25:52 +05:30
|
|
|
stub_application_setting(recaptcha_enabled: true)
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context 'when the reCAPTCHA is not solved' do
|
|
|
|
before do
|
|
|
|
Recaptcha.configuration.skip_verify_env.delete('test')
|
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'displays an error' do
|
|
|
|
alert_text = _('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')
|
|
|
|
|
|
|
|
perform_request
|
|
|
|
|
|
|
|
expect(response).to render_template(:new)
|
|
|
|
expect(flash[:alert]).to include alert_text
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets gon variables' do
|
|
|
|
Gon.clear
|
|
|
|
|
|
|
|
perform_request
|
|
|
|
|
|
|
|
expect(response).to render_template(:new)
|
|
|
|
expect(Gon.all_variables).not_to be_empty
|
|
|
|
end
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'successfully sends password reset when reCAPTCHA is solved' do
|
|
|
|
Recaptcha.configuration.skip_verify_env << 'test'
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
perform_request
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(response).to redirect_to(dashboard_projects_path)
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
2023-05-27 22:25:52 +05:30
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context "when `email_confirmation_setting` is not set to `soft`" do
|
|
|
|
it 'redirects to the users_almost_there path' do
|
2021-12-11 22:18:48 +05:30
|
|
|
perform_request
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(response).to redirect_to(users_almost_there_path)
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-12-08 15:28:05 +05:30
|
|
|
end
|