exchange_spec.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe ExternalCredential::Exchange do
  4. describe '.refresh_token' do
  5. # https://github.com/zammad/zammad/issues/4454
  6. context 'when Exchange integration is not configured at all' do
  7. before do
  8. Setting.set('exchange_oauth', {})
  9. Setting.set('exchange_integration', true)
  10. end
  11. it 'does always return a value' do
  12. expect(described_class.refresh_token).to be_truthy
  13. end
  14. end
  15. # https://github.com/zammad/zammad/issues/4961
  16. context 'when Exchange integration is not enabled' do
  17. before do
  18. Setting.set('exchange_integration', false)
  19. end
  20. it 'does always return a value' do
  21. expect(described_class.refresh_token).to be_truthy
  22. end
  23. end
  24. end
  25. describe '.update_client_secret' do
  26. let(:external_credential) { create(:external_credential, name: 'exchange', credentials:) }
  27. let(:credentials) { { client_id: 'id1337', client_secret: 'dummy' } }
  28. context 'when Exchange integration is not completely configured' do
  29. before do
  30. Setting.set('exchange_oauth', { client_id: 'id1337' })
  31. end
  32. it 'does not update the setting' do
  33. external_credential.update!(credentials: credentials)
  34. expect(Setting.get('exchange_oauth')).to eq({ 'client_id' => 'id1337' })
  35. end
  36. end
  37. context 'when Exchange integration is completely configured' do
  38. before do
  39. Setting.set('exchange_oauth', { client_id: 'id1337', client_secret: 'dummy' })
  40. end
  41. context 'when client_secret is different' do
  42. let(:credentials) { { client_id: 'id1337', client_secret: 'dummy-other' } }
  43. it 'does not update the setting' do
  44. external_credential.update!(credentials: credentials.merge(client_secret: 'new-dummy'))
  45. expect(Setting.get('exchange_oauth')).to eq({ 'client_id' => 'id1337', 'client_secret' => 'dummy' })
  46. end
  47. end
  48. context 'when client_secret is the same' do
  49. it 'does update the setting' do
  50. external_credential.update!(credentials: credentials.merge(client_secret: 'new-dummy'))
  51. expect(Setting.get('exchange_oauth')).to eq({ 'client_id' => 'id1337', 'client_secret' => 'new-dummy' })
  52. end
  53. end
  54. end
  55. end
  56. end