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-17 10:26:41 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence do
|
|
|
|
|
|
|
|
context 'lost group assignment' do
|
|
|
|
|
|
|
|
context 'config "unassigned_users": "skip_sync"' do
|
|
|
|
|
2018-09-28 12:52:06 +00:00
|
|
|
it 'disables user', last_admin_check: false do
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
user_entry = build(:ldap_entry)
|
|
|
|
user_entry['objectguid'] = ['user1337']
|
|
|
|
user_entry['samaccountname'] = ['login123']
|
|
|
|
user_entry['first_name'] = ['Hans']
|
|
|
|
|
|
|
|
group_entry = build(:ldap_entry)
|
|
|
|
group_entry['member'] = [user_entry.dn]
|
|
|
|
|
|
|
|
payload = {
|
|
|
|
ldap_config: {
|
2018-12-19 17:31:51 +00:00
|
|
|
user_filter: 'user=filter',
|
|
|
|
group_role_map: {
|
2018-01-17 10:26:41 +00:00
|
|
|
group_entry.dn => [1, 2]
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
user_attributes: {
|
2021-01-18 15:30:49 +00:00
|
|
|
'samaccountname' => 'login',
|
|
|
|
'first_name' => 'firstname',
|
2018-01-17 10:26:41 +00:00
|
|
|
},
|
|
|
|
user_uid: 'objectguid',
|
|
|
|
unassigned_users: 'skip_sync',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
import_job = build_stubbed(:import_job, name: 'Import::Ldap', payload: payload)
|
|
|
|
|
|
|
|
connection = double(
|
|
|
|
host: 'example.com',
|
|
|
|
port: 1337,
|
|
|
|
ssl: true,
|
|
|
|
base_dn: 'test'
|
|
|
|
)
|
|
|
|
|
|
|
|
# LDAP::Group
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(connection).to receive(:search).and_yield(group_entry)
|
|
|
|
allow(connection).to receive(:entries?).and_return(true)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
# Sequencer::Unit::Import::Ldap::Users::Total
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(connection).to receive(:count).and_return(1)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
# Sequencer::Unit::Import::Ldap::Users::SubSequence
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(connection).to receive(:search).and_yield(user_entry)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
process(
|
|
|
|
ldap_connection: connection,
|
|
|
|
import_job: import_job,
|
|
|
|
)
|
2019-04-15 01:41:17 +00:00
|
|
|
end.to change(User, :count).by(1)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
imported_user = User.last
|
|
|
|
|
|
|
|
expect(imported_user.active).to be true
|
|
|
|
|
|
|
|
connection = double(
|
|
|
|
host: 'example.com',
|
|
|
|
port: 1337,
|
|
|
|
ssl: true,
|
|
|
|
base_dn: 'test'
|
|
|
|
)
|
|
|
|
|
|
|
|
group_entry['member'] = ['some.other.dn']
|
|
|
|
|
|
|
|
# LDAP::Group
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(connection).to receive(:search).and_yield(group_entry)
|
|
|
|
allow(connection).to receive(:entries?).and_return(true)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
process(
|
|
|
|
ldap_connection: connection,
|
|
|
|
import_job: import_job,
|
|
|
|
)
|
2019-04-15 01:41:17 +00:00
|
|
|
end.not_to change(User, :count)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
imported_user.reload
|
|
|
|
|
|
|
|
expect(imported_user.active).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'config "unassigned_users": nil / "sigup_roles"' do
|
|
|
|
|
2018-09-28 12:52:06 +00:00
|
|
|
it 'assigns signup roles', last_admin_check: false do
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
user_entry = build(:ldap_entry)
|
|
|
|
user_entry['objectguid'] = ['user1337']
|
|
|
|
user_entry['samaccountname'] = ['login123']
|
|
|
|
user_entry['first_name'] = ['Hans']
|
|
|
|
|
|
|
|
group_entry = build(:ldap_entry)
|
|
|
|
group_entry['member'] = [user_entry.dn]
|
|
|
|
|
|
|
|
agent_admin_role_ids = [1, 2]
|
|
|
|
|
|
|
|
payload = {
|
|
|
|
ldap_config: {
|
2018-12-19 17:31:51 +00:00
|
|
|
user_filter: 'user=filter',
|
|
|
|
group_role_map: {
|
2018-01-17 10:26:41 +00:00
|
|
|
group_entry.dn => agent_admin_role_ids
|
|
|
|
},
|
|
|
|
user_attributes: {
|
2021-01-18 15:30:49 +00:00
|
|
|
'samaccountname' => 'login',
|
|
|
|
'first_name' => 'firstname',
|
2018-01-17 10:26:41 +00:00
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
user_uid: 'objectguid',
|
2018-01-17 10:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
import_job = build_stubbed(:import_job, name: 'Import::Ldap', payload: payload)
|
|
|
|
|
|
|
|
connection = double(
|
|
|
|
host: 'example.com',
|
|
|
|
port: 1337,
|
|
|
|
ssl: true,
|
|
|
|
base_dn: 'test'
|
|
|
|
)
|
|
|
|
|
2020-10-22 13:57:01 +00:00
|
|
|
# LDAP::Group and Sequencer::Unit::Import::Ldap::Users::SubSequence
|
|
|
|
allow(connection).to receive(:search).and_yield(group_entry).and_yield(user_entry)
|
|
|
|
allow(connection).to receive(:entries?).and_return(true)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
# Sequencer::Unit::Import::Ldap::Users::Total
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(connection).to receive(:count).and_return(1)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
process(
|
|
|
|
ldap_connection: connection,
|
|
|
|
import_job: import_job,
|
|
|
|
)
|
2019-04-15 01:41:17 +00:00
|
|
|
end.to change(User, :count).by(1)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
imported_user = User.last
|
|
|
|
|
|
|
|
expect(imported_user.role_ids).to eq(agent_admin_role_ids)
|
|
|
|
|
|
|
|
connection = double(
|
|
|
|
host: 'example.com',
|
|
|
|
port: 1337,
|
|
|
|
ssl: true,
|
|
|
|
base_dn: 'test'
|
|
|
|
)
|
|
|
|
|
|
|
|
group_entry['member'] = ['some.other.dn']
|
|
|
|
|
|
|
|
# LDAP::Group
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(connection).to receive(:search).and_yield(group_entry)
|
|
|
|
allow(connection).to receive(:entries?).and_return(true)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
# Sequencer::Unit::Import::Ldap::Users::Total
|
|
|
|
# cached
|
|
|
|
# expect(connection).to receive(:count).and_return(1)
|
|
|
|
|
|
|
|
# Sequencer::Unit::Import::Ldap::Users::SubSequence
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(connection).to receive(:search).and_yield(user_entry)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
process(
|
|
|
|
ldap_connection: connection,
|
|
|
|
import_job: import_job,
|
|
|
|
)
|
2019-04-15 01:41:17 +00:00
|
|
|
end.not_to change(User, :count)
|
2018-01-17 10:26:41 +00:00
|
|
|
|
|
|
|
imported_user.reload
|
|
|
|
|
|
|
|
expect(imported_user.roles).to eq(Role.signup_roles)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|