add email OTP
This commit is contained in:
@@ -71,6 +71,10 @@ RSpec.configure do |config|
|
||||
Sidekiq::Testing.inline! if example.metadata[:sidekiq] == :inline
|
||||
end
|
||||
|
||||
config.after do |example|
|
||||
Sidekiq::Testing.fake! if example.metadata[:sidekiq] == :inline
|
||||
end
|
||||
|
||||
config.before(multitenant: true) do
|
||||
allow(Docuseal).to receive(:multitenant?).and_return(true)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Sign In', type: :system do
|
||||
let(:account) { create(:account) }
|
||||
let!(:user) { create(:user, account:, email: 'john.dou@example.com', password: 'strong_password') }
|
||||
|
||||
before do
|
||||
visit new_user_session_path
|
||||
end
|
||||
|
||||
context 'when only with email and password' do
|
||||
it 'signs in successfully with valid email and password' do
|
||||
fill_in 'Email', with: 'john.dou@example.com'
|
||||
fill_in 'Password', with: 'strong_password'
|
||||
click_button 'Sign In'
|
||||
|
||||
expect(page).to have_content('Signed in successfully')
|
||||
expect(page).to have_content('Document Templates')
|
||||
end
|
||||
|
||||
it "doesn't sign in if the email or password are incorrect" do
|
||||
fill_in 'Email', with: 'john.dou@example.com'
|
||||
fill_in 'Password', with: 'wrong_password'
|
||||
click_button 'Sign In'
|
||||
|
||||
expect(page).to have_content('Invalid Email or password')
|
||||
expect(page).not_to have_content('Document Templates')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when 2FA is required' do
|
||||
before do
|
||||
user.update(otp_required_for_login: true, otp_secret: User.generate_otp_secret)
|
||||
end
|
||||
|
||||
it 'signs in successfully with valid OTP code' do
|
||||
fill_in 'Email', with: 'john.dou@example.com'
|
||||
fill_in 'Password', with: 'strong_password'
|
||||
click_button 'Sign In'
|
||||
fill_in 'Two-Factor Code from Authenticator App', with: user.current_otp
|
||||
click_button 'Sign In'
|
||||
|
||||
expect(page).to have_content('Signed in successfully')
|
||||
expect(page).to have_content('Document Templates')
|
||||
end
|
||||
|
||||
it 'fails to sign in with invalid OTP code' do
|
||||
fill_in 'Email', with: 'john.dou@example.com'
|
||||
fill_in 'Password', with: 'strong_password'
|
||||
click_button 'Sign In'
|
||||
fill_in 'Two-Factor Code from Authenticator App', with: '123456'
|
||||
click_button 'Sign In'
|
||||
|
||||
expect(page).to have_content('Invalid Email or password')
|
||||
expect(page).not_to have_content('Document Templates')
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user