2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-01-12 11:53:43 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2020-10-27 15:36:38 +00:00
|
|
|
RSpec.describe MigrateLdapSamaccountnameToUidJob, type: :job do
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
it 'performs no changes if no LDAP config present' do
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(Setting).to receive(:set)
|
|
|
|
allow(Import::Ldap).to receive(:config).and_return(nil)
|
2018-01-12 11:53:43 +00:00
|
|
|
|
2020-10-27 15:36:38 +00:00
|
|
|
described_class.perform_now
|
|
|
|
|
|
|
|
expect(Import::Ldap).to have_received(:config)
|
2020-10-22 13:57:01 +00:00
|
|
|
expect(Setting).not_to have_received(:set)
|
2018-01-12 11:53:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'performs no changes if uid attributes equals' do
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(Setting).to receive(:set)
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
ldap_config = {
|
|
|
|
'user_uid' => 'samaccountname'
|
|
|
|
}
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(Import::Ldap).to receive(:config).and_return(ldap_config)
|
2018-01-12 11:53:43 +00:00
|
|
|
|
2021-07-16 13:29:38 +00:00
|
|
|
ldap_user = double
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(ldap_user).to receive(:uid_attribute).and_return('samaccountname')
|
|
|
|
allow(::Ldap::User).to receive(:new).and_return(ldap_user)
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
allow(::Ldap).to receive(:new)
|
|
|
|
|
2020-10-27 15:36:38 +00:00
|
|
|
described_class.perform_now
|
|
|
|
|
2020-10-22 13:57:01 +00:00
|
|
|
expect(Setting).not_to have_received(:set)
|
2020-10-27 15:36:38 +00:00
|
|
|
expect(Import::Ldap).to have_received(:config)
|
|
|
|
expect(ldap_user).to have_received(:uid_attribute)
|
|
|
|
expect(::Ldap::User).to have_received(:new)
|
2018-01-12 11:53:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'performs Setting change if uid attribute differ' do
|
|
|
|
ldap_config_new = {
|
|
|
|
'user_uid' => 'objectguid'
|
|
|
|
}
|
|
|
|
ldap_config_obsolete = {
|
|
|
|
'user_uid' => 'samaccountname'
|
|
|
|
}
|
|
|
|
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(Setting).to receive(:set)
|
2020-10-27 15:36:38 +00:00
|
|
|
allow(Setting).to receive(:set).with('ldap_config', ldap_config_new)
|
2018-01-12 11:53:43 +00:00
|
|
|
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(Import::Ldap).to receive(:config).and_return(ldap_config_obsolete)
|
2018-01-12 11:53:43 +00:00
|
|
|
|
2021-07-16 13:29:38 +00:00
|
|
|
ldap_user = double
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(ldap_user).to receive(:uid_attribute).and_return('objectguid')
|
|
|
|
allow(::Ldap::User).to receive(:new).and_return(ldap_user)
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
allow(::Ldap).to receive(:new)
|
|
|
|
|
2020-10-27 15:36:38 +00:00
|
|
|
described_class.perform_now
|
2020-10-22 13:57:01 +00:00
|
|
|
|
|
|
|
expect(Setting).to have_received(:set).with('ldap_config', ldap_config_new)
|
2020-10-27 15:36:38 +00:00
|
|
|
expect(ldap_user).to have_received(:uid_attribute)
|
2018-01-12 11:53:43 +00:00
|
|
|
end
|
|
|
|
end
|