summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2016-11-09 15:37:23 +0000
committerSean McGivern <sean@mcgivern.me.uk>2016-11-09 15:37:23 +0000
commitde8c2b79c03507bd7da9ca746fb5ba71aec4ad0a (patch)
treea4c2a1dbb1f59f2d3dc27ea3e978a9feb6810f71 /spec/lib
parent35aca1dbcf5862e3335b8acba8b730b558382ca8 (diff)
parentdc307830571aaca1ff20b409d7075eee83f21fb9 (diff)
downloadgitlab-ce-de8c2b79c03507bd7da9ca746fb5ba71aec4ad0a.tar.gz
Merge branch 'ldap_check_bind' into 'master'
Improve ldap:check errors Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/21621. See merge request !6601
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/ldap/config_spec.rb39
1 files changed, 35 insertions, 4 deletions
diff --git a/spec/lib/gitlab/ldap/config_spec.rb b/spec/lib/gitlab/ldap/config_spec.rb
index 835853a83a4..f5ebe703083 100644
--- a/spec/lib/gitlab/ldap/config_spec.rb
+++ b/spec/lib/gitlab/ldap/config_spec.rb
@@ -1,20 +1,51 @@
require 'spec_helper'
describe Gitlab::LDAP::Config, lib: true do
- let(:config) { Gitlab::LDAP::Config.new provider }
- let(:provider) { 'ldapmain' }
+ include LdapHelpers
+
+ let(:config) { Gitlab::LDAP::Config.new('ldapmain') }
describe '#initalize' do
it 'requires a provider' do
expect{ Gitlab::LDAP::Config.new }.to raise_error ArgumentError
end
- it "works" do
+ it 'works' do
expect(config).to be_a described_class
end
- it "raises an error if a unknow provider is used" do
+ it 'raises an error if a unknown provider is used' do
expect{ Gitlab::LDAP::Config.new 'unknown' }.to raise_error(RuntimeError)
end
end
+
+ describe '#has_auth?' do
+ it 'is true when password is set' do
+ stub_ldap_config(
+ options: {
+ 'bind_dn' => 'uid=admin,dc=example,dc=com',
+ 'password' => 'super_secret'
+ }
+ )
+
+ expect(config.has_auth?).to be_truthy
+ end
+
+ it 'is true when bind_dn is set and password is empty' do
+ stub_ldap_config(
+ options: {
+ 'bind_dn' => 'uid=admin,dc=example,dc=com',
+ 'password' => ''
+ }
+ )
+
+ expect(config.has_auth?).to be_truthy
+ end
+
+ it 'is false when password and bind_dn are not set' do
+ stub_ldap_config(options: { 'bind_dn' => nil, 'password' => nil })
+
+ expect(config.has_auth?).to be_falsey
+ end
+ end
end