after_auth_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Auth::AfterAuth do
  4. let(:customer) { create(:customer, roles: [role]) }
  5. let(:role) { create(:role, name: '2FA') }
  6. let(:session) { { authentication_type: authentication_type } }
  7. let(:authentication_type) { 'password' }
  8. context 'when after auth is triggered' do
  9. context 'with third-party login' do
  10. let(:authentication_type) { 'omniauth' }
  11. it 'returns nil' do
  12. expect(described_class.run(customer, session)).to be_nil
  13. end
  14. end
  15. context 'with no enforcing roles' do
  16. it 'returns nil' do
  17. expect(described_class.run(customer, session)).to be_nil
  18. end
  19. end
  20. context 'with enforcing roles' do
  21. before do
  22. Setting.set('two_factor_authentication_enforce_role_ids', [role.id])
  23. Setting.set('two_factor_authentication_method_authenticator_app', true)
  24. end
  25. it 'returns the after auth type' do
  26. expect(described_class.run(customer, session)).to eq({ type: 'TwoFactorConfiguration', data: {} })
  27. end
  28. end
  29. end
  30. end