2014-05-14 16:14:06 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 10:55:36 +00:00
|
|
|
describe Gitlab::LDAP::Access, lib: true do
|
2014-10-13 15:24:05 +00:00
|
|
|
let(:access) { Gitlab::LDAP::Access.new user }
|
2014-12-04 11:43:08 +00:00
|
|
|
let(:user) { create(:omniauth_user) }
|
2014-05-14 16:14:06 +00:00
|
|
|
|
|
|
|
describe :allowed? do
|
2014-10-13 15:24:05 +00:00
|
|
|
subject { access.allowed? }
|
2014-05-14 16:14:06 +00:00
|
|
|
|
|
|
|
context 'when the user cannot be found' do
|
2015-05-21 21:49:06 +00:00
|
|
|
before do
|
|
|
|
allow(Gitlab::LDAP::Person).to receive(:find_by_dn).and_return(nil)
|
|
|
|
end
|
2014-05-14 16:14:06 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to be_falsey }
|
2015-12-08 15:47:42 +00:00
|
|
|
|
|
|
|
it 'should block user in GitLab' do
|
|
|
|
access.allowed?
|
|
|
|
expect(user).to be_blocked
|
|
|
|
end
|
2014-05-14 16:14:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is found' do
|
2015-05-21 21:49:06 +00:00
|
|
|
before do
|
|
|
|
allow(Gitlab::LDAP::Person).
|
|
|
|
to receive(:find_by_dn).and_return(:ldap_user)
|
|
|
|
end
|
2014-05-14 16:14:06 +00:00
|
|
|
|
2015-05-12 09:21:56 +00:00
|
|
|
context 'and the user is disabled via active directory' do
|
2015-05-21 21:49:06 +00:00
|
|
|
before do
|
|
|
|
allow(Gitlab::LDAP::Person).
|
|
|
|
to receive(:disabled_via_active_directory?).and_return(true)
|
|
|
|
end
|
2014-05-14 16:14:06 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to be_falsey }
|
2015-03-12 18:53:21 +00:00
|
|
|
|
|
|
|
it "should block user in GitLab" do
|
|
|
|
access.allowed?
|
2015-06-13 22:24:51 +00:00
|
|
|
expect(user).to be_blocked
|
2015-03-12 18:53:21 +00:00
|
|
|
end
|
2014-05-14 16:14:06 +00:00
|
|
|
end
|
|
|
|
|
2014-09-01 14:35:18 +00:00
|
|
|
context 'and has no disabled flag in active diretory' do
|
2015-03-13 15:40:15 +00:00
|
|
|
before do
|
|
|
|
user.block
|
2015-05-21 21:49:06 +00:00
|
|
|
|
|
|
|
allow(Gitlab::LDAP::Person).
|
|
|
|
to receive(:disabled_via_active_directory?).and_return(false)
|
2015-03-13 15:40:15 +00:00
|
|
|
end
|
2014-05-14 16:14:06 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to be_truthy }
|
2015-03-13 15:40:15 +00:00
|
|
|
|
2015-05-12 09:21:56 +00:00
|
|
|
context 'when auto-created users are blocked' do
|
|
|
|
|
|
|
|
before do
|
2015-05-21 21:49:06 +00:00
|
|
|
allow_any_instance_of(Gitlab::LDAP::Config).
|
|
|
|
to receive(:block_auto_created_users).and_return(true)
|
2015-05-12 09:21:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not unblock user in GitLab" do
|
|
|
|
access.allowed?
|
2015-06-13 22:24:51 +00:00
|
|
|
expect(user).to be_blocked
|
2015-05-12 09:21:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when auto-created users are not blocked" do
|
|
|
|
|
|
|
|
before do
|
2015-05-21 21:49:06 +00:00
|
|
|
allow_any_instance_of(Gitlab::LDAP::Config).
|
|
|
|
to receive(:block_auto_created_users).and_return(false)
|
2015-05-12 09:21:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should unblock user in GitLab" do
|
|
|
|
access.allowed?
|
2015-06-13 22:19:24 +00:00
|
|
|
expect(user).not_to be_blocked
|
2015-05-12 09:21:56 +00:00
|
|
|
end
|
2015-03-13 15:40:15 +00:00
|
|
|
end
|
2014-05-14 16:14:06 +00:00
|
|
|
end
|
2014-09-30 10:07:31 +00:00
|
|
|
|
2014-10-13 15:24:05 +00:00
|
|
|
context 'without ActiveDirectory enabled' do
|
|
|
|
before do
|
2015-05-21 21:49:06 +00:00
|
|
|
allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
|
|
|
|
allow_any_instance_of(Gitlab::LDAP::Config).
|
|
|
|
to receive(:active_directory).and_return(false)
|
2014-10-13 15:24:05 +00:00
|
|
|
end
|
2014-09-30 10:07:31 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to be_truthy }
|
2014-09-30 10:07:31 +00:00
|
|
|
end
|
2014-05-14 16:14:06 +00:00
|
|
|
end
|
|
|
|
end
|
2015-03-12 18:53:21 +00:00
|
|
|
end
|