Commit 6703354f authored by Jacob Vosmaer's avatar Jacob Vosmaer

Fix tests and other small improvements

parent f74cb73a
......@@ -3,7 +3,7 @@ class LdapGroupLinksWorker
def perform(user_id)
user = User.find(user_id)
logger.info "Updating LDAP group memberships for user #{user.id} (#{user.username})"
logger.info "Updating LDAP group memberships for user #{user.id} (#{user.email})"
access = Gitlab::LDAP::Access.new(user)
access.update_ldap_group_links
end
......
......@@ -8,7 +8,9 @@ class LdapSyncWorker
Rails.logger.info "Performing daily LDAP sync task."
User.ldap.find_each(batch_size: 100).each do |ldap_user|
Rails.logger.debug "Syncing user #{ldap_user.username}, #{ldap_user.email}"
Gitlab::LDAP::Access.allowed?(ldap_user, update_groups: true)
# Use the 'update_ldap_group_links_synchronously' option to avoid creating a ton
# of new Sidekiq jobs all at once.
Gitlab::LDAP::Access.allowed?(ldap_user, update_ldap_group_links_synchronously: true)
end
end
end
......@@ -77,7 +77,7 @@ module Gitlab
def update_permissions(options)
if group_base.present?
if options[:update_groups]
if options[:update_ldap_group_links_synchronously]
update_ldap_group_links
else
LdapGroupLinksWorker.perform_async(user.id)
......
......@@ -117,18 +117,19 @@ describe Gitlab::LDAP::Access, lib: true do
end
describe '#update_permissions' do
subject { access.update_permissions }
subject { access.update_permissions(options) }
let(:options) { Hash.new }
it 'does update group permissions with a group base configured' do
allow(access).to receive_messages(group_base: 'my-group-base')
expect(access).to receive(:update_ldap_group_links)
expect(LdapGroupLinksWorker).to receive(:perform_async).with(user.id)
subject
end
it 'does not update group permissions without a group base configured' do
allow(access).to receive_messages(group_base: '')
expect(access).not_to receive(:update_ldap_group_links)
expect(LdapGroupLinksWorker).not_to receive(:perform_async)
subject
end
......@@ -146,6 +147,18 @@ describe Gitlab::LDAP::Access, lib: true do
subject
end
context 'when synchronously updating group permissions' do
let(:options) { { update_ldap_group_links_synchronously: true } }
it 'updates group permissions directly' do
allow(access).to receive_messages(group_base: 'my-group-base')
expect(LdapGroupLinksWorker).not_to receive(:perform_async)
expect(access).to receive(:update_ldap_group_links)
subject
end
end
end
describe :update_kerberos_identity do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment