debian-mirror-gitlab/spec/lib/gitlab/ldap/access_spec.rb

110 lines
2.9 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe Gitlab::LDAP::Access, lib: true do
2015-04-26 12:48:37 +05:30
let(:access) { Gitlab::LDAP::Access.new user }
let(:user) { create(:omniauth_user) }
describe :allowed? do
subject { access.allowed? }
context 'when the user cannot be found' do
2015-09-11 14:41:01 +05:30
before do
allow(Gitlab::LDAP::Person).to receive(:find_by_dn).and_return(nil)
end
2015-04-26 12:48:37 +05:30
it { is_expected.to be_falsey }
2015-12-23 02:04:40 +05:30
it 'should block user in GitLab' do
access.allowed?
expect(user).to be_blocked
expect(user).to be_ldap_blocked
2015-12-23 02:04:40 +05:30
end
2015-04-26 12:48:37 +05:30
end
context 'when the user is found' do
2015-09-11 14:41:01 +05:30
before do
allow(Gitlab::LDAP::Person).to receive(:find_by_dn).and_return(:ldap_user)
2015-09-11 14:41:01 +05:30
end
2015-04-26 12:48:37 +05:30
2015-09-11 14:41:01 +05:30
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)
2015-09-11 14:41:01 +05:30
end
2015-04-26 12:48:37 +05:30
it { is_expected.to be_falsey }
2016-06-02 11:05:42 +05:30
it 'blocks user in GitLab' do
2015-04-26 12:48:37 +05:30
access.allowed?
2015-09-11 14:41:01 +05:30
expect(user).to be_blocked
expect(user).to be_ldap_blocked
2015-04-26 12:48:37 +05:30
end
end
context 'and has no disabled flag in active diretory' do
before do
allow(Gitlab::LDAP::Person).to receive(:disabled_via_active_directory?).and_return(false)
2015-04-26 12:48:37 +05:30
end
it { is_expected.to be_truthy }
2015-09-11 14:41:01 +05:30
context 'when auto-created users are blocked' do
before do
user.block
2015-09-11 14:41:01 +05:30
end
it 'does not unblock user in GitLab' do
2015-09-11 14:41:01 +05:30
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
2015-09-11 14:41:01 +05:30
end
end
context 'when auto-created users are not blocked' do
2015-09-11 14:41:01 +05:30
before do
user.ldap_block
2015-09-11 14:41:01 +05:30
end
it 'should unblock user in GitLab' do
2015-09-11 14:41:01 +05:30
access.allowed?
expect(user).not_to be_blocked
end
2015-04-26 12:48:37 +05:30
end
end
context 'without ActiveDirectory enabled' do
before do
2015-09-11 14:41:01 +05:30
allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
allow_any_instance_of(Gitlab::LDAP::Config).to receive(:active_directory).and_return(false)
2015-04-26 12:48:37 +05:30
end
it { is_expected.to be_truthy }
2016-06-02 11:05:42 +05:30
context 'when user cannot be found' do
before do
allow(Gitlab::LDAP::Person).to receive(:find_by_dn).and_return(nil)
end
it { is_expected.to be_falsey }
it 'blocks user in GitLab' do
access.allowed?
expect(user).to be_blocked
expect(user).to be_ldap_blocked
end
end
context 'when user was previously ldap_blocked' do
before do
user.ldap_block
end
it 'unblocks the user if it exists' do
access.allowed?
expect(user).not_to be_blocked
end
end
2015-04-26 12:48:37 +05:30
end
end
end
end