migrate_ldap_samaccountname_to_uid_job_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. require 'rails_helper'
  2. RSpec.describe MigrateLdapSamaccountnameToUidJob, type: :job do
  3. it 'performs no changes if no LDAP config present' do
  4. allow(Setting).to receive(:set)
  5. allow(Import::Ldap).to receive(:config).and_return(nil)
  6. described_class.perform_now
  7. expect(Import::Ldap).to have_received(:config)
  8. expect(Setting).not_to have_received(:set)
  9. end
  10. it 'performs no changes if uid attributes equals' do
  11. allow(Setting).to receive(:set)
  12. ldap_config = {
  13. 'user_uid' => 'samaccountname'
  14. }
  15. allow(Import::Ldap).to receive(:config).and_return(ldap_config)
  16. ldap_user = double()
  17. allow(ldap_user).to receive(:uid_attribute).and_return('samaccountname')
  18. allow(::Ldap::User).to receive(:new).and_return(ldap_user)
  19. allow(::Ldap).to receive(:new)
  20. described_class.perform_now
  21. expect(Setting).not_to have_received(:set)
  22. expect(Import::Ldap).to have_received(:config)
  23. expect(ldap_user).to have_received(:uid_attribute)
  24. expect(::Ldap::User).to have_received(:new)
  25. end
  26. it 'performs Setting change if uid attribute differ' do
  27. ldap_config_new = {
  28. 'user_uid' => 'objectguid'
  29. }
  30. ldap_config_obsolete = {
  31. 'user_uid' => 'samaccountname'
  32. }
  33. allow(Setting).to receive(:set)
  34. allow(Setting).to receive(:set).with('ldap_config', ldap_config_new)
  35. allow(Import::Ldap).to receive(:config).and_return(ldap_config_obsolete)
  36. ldap_user = double()
  37. allow(ldap_user).to receive(:uid_attribute).and_return('objectguid')
  38. allow(::Ldap::User).to receive(:new).and_return(ldap_user)
  39. allow(::Ldap).to receive(:new)
  40. described_class.perform_now
  41. expect(Setting).to have_received(:set).with('ldap_config', ldap_config_new)
  42. expect(ldap_user).to have_received(:uid_attribute)
  43. end
  44. end