ldap_source_config_spec.rb 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe LdapSourceConfig, type: :db_migration do
  4. context 'with existing LDAP sources' do
  5. let!(:ldap_source) { create(:ldap_source, preferences: preferences) }
  6. let(:preferences) do
  7. {
  8. 'host_url' => host_url,
  9. 'options' => { 'dc=foo,dc=example,dc=com'=>'dc=foo,dc=example,dc=com' },
  10. 'option' => 'dc=foo,dc=example,dc=com',
  11. 'base_dn' => 'dc=foo,dc=example,dc=com',
  12. 'bind_user' => 'dummy',
  13. 'bind_pw' => 'dummy',
  14. 'user_uid' => 'uid',
  15. 'user_filter' => '(objectClass=posixaccount)',
  16. 'group_uid' => 'dn',
  17. 'group_filter' => '(objectClass=posixgroup)',
  18. 'user_attributes' => { 'cn' => 'firstname', 'sn' => 'lastname', 'mail' => 'email', 'uid' => 'login', 'telephonenumber' => 'phone' },
  19. 'group_role_map' => { 'cn=admin,ou=groups,dc=foo,dc=example,dc=com' => ['1'], 'cn=1st level,ou=groups,dc=foo,dc=example,dc=com' => ['2'] },
  20. 'unassigned_users' => 'sigup_roles',
  21. }
  22. end
  23. context 'with LDAPS' do
  24. let(:host_url) { 'ldaps://ldaps.example.com' }
  25. it 'migrates the LdapSource', :aggregate_failures do
  26. migrate
  27. ldap_source.reload
  28. expect(ldap_source.preferences['host']).to eq('ldaps.example.com')
  29. expect(ldap_source.preferences['ssl']).to eq('ssl')
  30. expect(ldap_source.preferences).not_to have_key('host_url')
  31. end
  32. end
  33. context 'with LDAP' do
  34. let(:host_url) { 'ldap://ldap.example.com' }
  35. it 'migrates the LdapSource', :aggregate_failures do
  36. migrate
  37. ldap_source.reload
  38. expect(ldap_source.preferences['host']).to eq('ldap.example.com')
  39. expect(ldap_source.preferences['ssl']).to eq('off')
  40. expect(ldap_source.preferences).not_to have_key('host_url')
  41. end
  42. end
  43. context 'without host_url' do
  44. let(:preferences) do
  45. {
  46. 'host' => 'ldap.example.com',
  47. 'ssl' => ssl,
  48. 'options' => { 'dc=foo,dc=example,dc=com'=>'dc=foo,dc=example,dc=com' },
  49. 'option' => 'dc=foo,dc=example,dc=com',
  50. 'base_dn' => 'dc=foo,dc=example,dc=com',
  51. 'bind_user' => 'dummy',
  52. 'bind_pw' => 'dummy',
  53. 'user_uid' => 'uid',
  54. 'user_filter' => '(objectClass=posixaccount)',
  55. 'group_uid' => 'dn',
  56. 'group_filter' => '(objectClass=posixgroup)',
  57. 'user_attributes' => { 'cn' => 'firstname', 'sn' => 'lastname', 'mail' => 'email', 'uid' => 'login', 'telephonenumber' => 'phone' },
  58. 'group_role_map' => { 'cn=admin,ou=groups,dc=foo,dc=example,dc=com' => ['1'], 'cn=1st level,ou=groups,dc=foo,dc=example,dc=com' => ['2'] },
  59. 'unassigned_users' => 'sigup_roles',
  60. }
  61. end
  62. context 'with ssl = true' do
  63. let(:ssl) { true }
  64. it 'migrates the LdapSource', :aggregate_failures do
  65. migrate
  66. ldap_source.reload
  67. expect(ldap_source.preferences['host']).to eq('ldap.example.com')
  68. expect(ldap_source.preferences['ssl']).to eq('ssl')
  69. expect(ldap_source.preferences).not_to have_key('host_url')
  70. end
  71. end
  72. context 'with ssl = false' do
  73. let(:ssl) { false }
  74. it 'migrates the LdapSource', :aggregate_failures do
  75. migrate
  76. ldap_source.reload
  77. expect(ldap_source.preferences['host']).to eq('ldap.example.com')
  78. expect(ldap_source.preferences['ssl']).to eq('off')
  79. expect(ldap_source.preferences).not_to have_key('host_url')
  80. end
  81. end
  82. end
  83. end
  84. end