ldap_spec.rb 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ldap import', integration: true, required_envs: %w[IMPORT_LDAP_ENDPOINT IMPORT_LDAP_USER IMPORT_LDAP_PASSWORD], use_vcr: false do # rubocop:disable RSpec/DescribeClass
  4. let(:ldap_source) { create(:ldap_source, :with_config) }
  5. let(:expected_result) do
  6. { 'skipped' => 0,
  7. 'created' => 14,
  8. 'updated' => 0,
  9. 'unchanged' => 0,
  10. 'failed' => 0,
  11. 'deactivated' => 0,
  12. 'sum' => 14,
  13. 'total' => 14,
  14. 'role_ids' =>
  15. { 3 =>
  16. { 'skipped' => 0,
  17. 'created' => 10,
  18. 'updated' => 0,
  19. 'unchanged' => 0,
  20. 'failed' => 0,
  21. 'deactivated' => 0,
  22. 'sum' => 10,
  23. 'total' => 0 },
  24. 1 =>
  25. { 'skipped' => 0,
  26. 'created' => 2,
  27. 'updated' => 0,
  28. 'unchanged' => 0,
  29. 'failed' => 0,
  30. 'deactivated' => 0,
  31. 'sum' => 2,
  32. 'total' => 0 },
  33. 2 =>
  34. { 'skipped' => 0,
  35. 'created' => 2,
  36. 'updated' => 0,
  37. 'unchanged' => 0,
  38. 'failed' => 0,
  39. 'deactivated' => 0,
  40. 'sum' => 2,
  41. 'total' => 0 } } }
  42. end
  43. context 'when importing' do
  44. before do
  45. Setting.set('ldap_integration', true)
  46. TCR.turned_off do
  47. ldap_source
  48. ImportJob.start_registered
  49. end
  50. end
  51. it 'does import users and roles' do
  52. expect(ImportJob.last.result).to eq(expected_result)
  53. user_ab = User.find_by(login: 'ab')
  54. expect(user_ab.firstname).to eq('Albert')
  55. expect(user_ab.lastname).to eq('Braun')
  56. expect(user_ab.email).to eq('ab@example.com')
  57. expect(user_ab.roles.first.name).to eq('Admin')
  58. expect(user_ab.roles.count).to eq(1)
  59. user_lb = User.find_by(login: 'lb')
  60. expect(user_lb.firstname).to eq('Lena')
  61. expect(user_lb.lastname).to eq('Braun')
  62. expect(user_lb.email).to eq('lb@example.com')
  63. expect(user_lb.roles.first.name).to eq('Agent')
  64. expect(user_lb.roles.count).to eq(1)
  65. end
  66. end
  67. end