after_auth_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'system/examples/security_keys_setup_examples'
  4. require 'system/examples/authenticator_app_setup_examples'
  5. RSpec.describe 'After Auth', type: :system do
  6. context 'with after auth module for 2FA', authenticated_as: :agent do
  7. let(:agent) { create(:agent, roles: [role]) }
  8. let(:role) { create(:role, :agent, name: '2FA') }
  9. before do
  10. Setting.set('two_factor_authentication_enforce_role_ids', [role.id])
  11. Setting.set('two_factor_authentication_method_authenticator_app', true)
  12. end
  13. shared_examples 'showing the modal' do
  14. it 'shows the modal' do
  15. expect_current_route 'dashboard'
  16. in_modal do
  17. expect(page).to have_text('Set up two-factor authentication')
  18. end
  19. end
  20. end
  21. context 'when logging in', authenticated_as: false do
  22. before do
  23. login(
  24. username: agent.login,
  25. password: 'test',
  26. )
  27. end
  28. it_behaves_like 'showing the modal'
  29. end
  30. context 'when already logged in' do
  31. before do
  32. visit '/'
  33. end
  34. it_behaves_like 'showing the modal'
  35. context 'with security keys method' do
  36. before do
  37. click_on 'Security Keys'
  38. end
  39. include_examples 'security keys setup' do
  40. let(:password_check) { false }
  41. end
  42. end
  43. context 'with authenticator app method' do
  44. before do
  45. click_on 'Authenticator App'
  46. end
  47. include_examples 'authenticator app setup' do
  48. let(:password_check) { false }
  49. end
  50. end
  51. end
  52. end
  53. end