ldap_samaccountname_to_uid_spec.rb 1.3 KB

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