2014-05-14 12:14:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::LDAP::Access do
|
2014-10-13 11:24:05 -04:00
|
|
|
let(:access) { Gitlab::LDAP::Access.new user }
|
2014-12-04 06:43:08 -05:00
|
|
|
let(:user) { create(:omniauth_user) }
|
2014-05-14 12:14:06 -04:00
|
|
|
|
|
|
|
describe :allowed? do
|
2014-10-13 11:24:05 -04:00
|
|
|
subject { access.allowed? }
|
2014-05-14 12:14:06 -04:00
|
|
|
|
|
|
|
context 'when the user cannot be found' do
|
|
|
|
before { Gitlab::LDAP::Person.stub(find_by_dn: nil) }
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to be_falsey }
|
2014-05-14 12:14:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is found' do
|
|
|
|
before { Gitlab::LDAP::Person.stub(find_by_dn: :ldap_user) }
|
|
|
|
|
2014-09-01 10:35:18 -04:00
|
|
|
context 'and the user is diabled via active directory' do
|
|
|
|
before { Gitlab::LDAP::Person.stub(disabled_via_active_directory?: true) }
|
2014-05-14 12:14:06 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to be_falsey }
|
2015-03-12 14:53:21 -04:00
|
|
|
|
|
|
|
it "should block user in GitLab" do
|
|
|
|
access.allowed?
|
|
|
|
user.should be_blocked
|
|
|
|
end
|
2014-05-14 12:14:06 -04:00
|
|
|
end
|
|
|
|
|
2014-09-01 10:35:18 -04:00
|
|
|
context 'and has no disabled flag in active diretory' do
|
2015-03-13 11:40:15 -04:00
|
|
|
before do
|
|
|
|
user.block
|
|
|
|
|
|
|
|
Gitlab::LDAP::Person.stub(disabled_via_active_directory?: false)
|
|
|
|
end
|
2014-05-14 12:14:06 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to be_truthy }
|
2015-03-13 11:40:15 -04:00
|
|
|
|
|
|
|
it "should unblock user in GitLab" do
|
|
|
|
access.allowed?
|
|
|
|
user.should_not be_blocked
|
|
|
|
end
|
2014-05-14 12:14:06 -04:00
|
|
|
end
|
2014-09-30 06:07:31 -04:00
|
|
|
|
2014-10-13 11:24:05 -04:00
|
|
|
context 'without ActiveDirectory enabled' do
|
|
|
|
before do
|
|
|
|
Gitlab::LDAP::Config.stub(enabled?: true)
|
|
|
|
Gitlab::LDAP::Config.any_instance.stub(active_directory: false)
|
|
|
|
end
|
2014-09-30 06:07:31 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to be_truthy }
|
2014-09-30 06:07:31 -04:00
|
|
|
end
|
2014-05-14 12:14:06 -04:00
|
|
|
end
|
|
|
|
end
|
2015-03-12 14:53:21 -04:00
|
|
|
end
|