LDAP synchronization block/unblock new states
This commit is contained in:
parent
6e7db8e23e
commit
d6dc088aff
2 changed files with 17 additions and 23 deletions
|
@ -37,15 +37,15 @@ module Gitlab
|
|||
|
||||
# Block user in GitLab if he/she was blocked in AD
|
||||
if Gitlab::LDAP::Person.disabled_via_active_directory?(user.ldap_identity.extern_uid, adapter)
|
||||
user.block
|
||||
user.ldap_block
|
||||
false
|
||||
else
|
||||
user.activate if user.blocked? && !ldap_config.block_auto_created_users
|
||||
user.activate if (user.blocked? && !ldap_config.block_auto_created_users) || user.ldap_blocked?
|
||||
true
|
||||
end
|
||||
else
|
||||
# Block the user if they no longer exist in LDAP/AD
|
||||
user.block
|
||||
user.ldap_block
|
||||
false
|
||||
end
|
||||
rescue
|
||||
|
|
|
@ -13,64 +13,59 @@ describe Gitlab::LDAP::Access, lib: true do
|
|||
end
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
|
||||
|
||||
it 'should block user in GitLab' do
|
||||
access.allowed?
|
||||
expect(user).to be_blocked
|
||||
expect(user).to be_ldap_blocked
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user is found' do
|
||||
before do
|
||||
allow(Gitlab::LDAP::Person).
|
||||
to receive(:find_by_dn).and_return(:ldap_user)
|
||||
allow(Gitlab::LDAP::Person).to receive(:find_by_dn).and_return(:ldap_user)
|
||||
end
|
||||
|
||||
context 'and the user is disabled via active directory' do
|
||||
before do
|
||||
allow(Gitlab::LDAP::Person).
|
||||
to receive(:disabled_via_active_directory?).and_return(true)
|
||||
allow(Gitlab::LDAP::Person).to receive(:disabled_via_active_directory?).and_return(true)
|
||||
end
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
|
||||
it "should block user in GitLab" do
|
||||
it 'should block user in GitLab' do
|
||||
access.allowed?
|
||||
expect(user).to be_blocked
|
||||
expect(user).to be_ldap_blocked
|
||||
end
|
||||
end
|
||||
|
||||
context 'and has no disabled flag in active diretory' do
|
||||
before do
|
||||
user.block
|
||||
|
||||
allow(Gitlab::LDAP::Person).
|
||||
to receive(:disabled_via_active_directory?).and_return(false)
|
||||
allow(Gitlab::LDAP::Person).to receive(:disabled_via_active_directory?).and_return(false)
|
||||
end
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
|
||||
context 'when auto-created users are blocked' do
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Gitlab::LDAP::Config).
|
||||
to receive(:block_auto_created_users).and_return(true)
|
||||
allow_any_instance_of(Gitlab::LDAP::Config).to receive(:block_auto_created_users).and_return(true)
|
||||
end
|
||||
|
||||
it "does not unblock user in GitLab" do
|
||||
it 'does not unblock user in GitLab' do
|
||||
access.allowed?
|
||||
expect(user).to be_blocked
|
||||
expect(user).not_to be_ldap_blocked # this block is handled by omniauth not by our internal logic
|
||||
end
|
||||
end
|
||||
|
||||
context "when auto-created users are not blocked" do
|
||||
|
||||
context 'when auto-created users are not blocked' do
|
||||
before do
|
||||
allow_any_instance_of(Gitlab::LDAP::Config).
|
||||
to receive(:block_auto_created_users).and_return(false)
|
||||
allow_any_instance_of(Gitlab::LDAP::Config).to receive(:block_auto_created_users).and_return(false)
|
||||
end
|
||||
|
||||
it "should unblock user in GitLab" do
|
||||
it 'should unblock user in GitLab' do
|
||||
access.allowed?
|
||||
expect(user).not_to be_blocked
|
||||
end
|
||||
|
@ -80,8 +75,7 @@ describe Gitlab::LDAP::Access, lib: true do
|
|||
context 'without ActiveDirectory enabled' do
|
||||
before do
|
||||
allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
|
||||
allow_any_instance_of(Gitlab::LDAP::Config).
|
||||
to receive(:active_directory).and_return(false)
|
||||
allow_any_instance_of(Gitlab::LDAP::Config).to receive(:active_directory).and_return(false)
|
||||
end
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
|
|
Loading…
Reference in a new issue