after_auth_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Mobile > After Auth', :aggregate_failures, app: :mobile, authenticated_as: :agent, type: :system do
  4. let(:agent) { create(:agent) }
  5. before do
  6. allow_any_instance_of(Auth::AfterAuth::TwoFactorConfiguration).to receive(:check).and_return(true)
  7. end
  8. context 'when user is logged in, but after auth is required' do
  9. it 'requires setting up two factor auth' do
  10. visit '/', skip_waiting: true
  11. expect(page).to have_content('The two-factor authentication is not configured yet')
  12. expect_current_route '/login/after-auth'
  13. end
  14. end
  15. context 'when user is not authenticated, but 2FA is required', authenticated_as: false do
  16. it 'provides a link for setting up 2FA by using the desktop view' do
  17. allow_any_instance_of(Auth::AfterAuth::TwoFactorConfiguration).to receive(:check).and_return(true)
  18. visit '/', skip_waiting: true
  19. find_input('Username / Email').type(agent.login)
  20. find_input('Password').type('test')
  21. click_on('Sign in')
  22. expect(page).to have_content('The two-factor authentication is not configured yet')
  23. expect(page).to have_link('Click here to set up a two-factor authentication method.', href: '/#')
  24. click 'a', text: 'Click here to set up a two-factor authentication method.'
  25. expect_current_route('dashboard', app: :desktop)
  26. expect(page).to have_content('You must protect your account with two-factor authentication.')
  27. end
  28. end
  29. end