admin_password_auth_verify_spec.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::AdminPasswordAuthVerify, type: :graphql do
  4. context 'when verifying' do
  5. let(:query) do
  6. <<~QUERY
  7. mutation adminPasswordAuthVerify($token: String!) {
  8. adminPasswordAuthVerify(token: $token) {
  9. login
  10. }
  11. }
  12. QUERY
  13. end
  14. let(:variables) { { token: token } }
  15. before do
  16. setup if defined?(setup)
  17. gql.execute(query, variables: variables)
  18. end
  19. context 'with enabled password login' do
  20. let(:setup) do
  21. Setting.set('user_show_password_login', true)
  22. end
  23. let(:token) { 'valid-token' }
  24. it 'raises an error' do
  25. expect(gql.result.error_message).to eq 'This feature is not enabled.'
  26. end
  27. end
  28. context 'with disabled password login' do
  29. context 'when no third-party authenticator is enabled' do
  30. let(:setup) do
  31. Setting.set('user_show_password_login', false)
  32. end
  33. let(:token) { 'dummy' }
  34. it 'raises an error' do
  35. expect(gql.result.error_message).to eq 'This feature is not enabled.'
  36. end
  37. end
  38. context 'when any third-party authenticator is enabled' do
  39. let(:setup) do
  40. Setting.set('user_show_password_login', false)
  41. Setting.set('auth_saml', true)
  42. user = create(:admin)
  43. Token.create(action: 'AdminAuth', user_id: user.id, persistent: false)
  44. end
  45. context 'with invalid token' do
  46. let(:token) { 'invalid' }
  47. it 'raises an error' do
  48. expect(gql.result.error_message).to eq 'The login is not possible.'
  49. end
  50. end
  51. context 'with valid token' do
  52. let(:token) { Token.last.token }
  53. it 'returns the login' do
  54. expect(gql.result.data[:login]).to eq User.last.login
  55. end
  56. end
  57. end
  58. end
  59. end
  60. end