two_factors_controller_policy_spec.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe Controllers::User::TwoFactorsControllerPolicy do
  4. subject { described_class.new(user, record) }
  5. let(:record_class) { User::TwoFactorsController }
  6. let(:record) { record_class.new }
  7. let(:user) { create(:agent) }
  8. let(:actions) do
  9. %i[
  10. enabled_authentication_methods personal_configuration authentication_method_initiate_configuration authentication_method_configuration
  11. verify_configuration default_authentication_method recovery_codes_generate
  12. remove_authentication_method authentication_remove_credentials
  13. ]
  14. end
  15. context 'when user has 2FA permission' do
  16. it { is_expected.to permit_actions(actions) }
  17. end
  18. context 'when user does not have 2FA permission' do
  19. before do
  20. user
  21. .roles
  22. .first
  23. .permission_revoke 'user_preferences.two_factor_authentication'
  24. end
  25. let(:user) { create(:customer) }
  26. it { is_expected.to forbid_actions(actions) }
  27. end
  28. end