-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathldap_spec.rb
More file actions
57 lines (46 loc) · 1.58 KB
/
ldap_spec.rb
File metadata and controls
57 lines (46 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# encoding: UTF-8
require 'spec_helper'
describe "CASServer::Authenticators::LDAP" do
before do
pending("Skip LDAP test due to missing gems") unless gem_available?("net-ldap")
if $LOG.nil?
load_server('default_config') # a lazy way to make sure the logger is set up
end
# Trigger autoload to load net ldap
CASServer::Authenticators::LDAP
@ldap_entry = double(Net::LDAP::Entry.new)
@ldap_entry.stub(:[]).and_return("Test")
@ldap = double(Net::LDAP)
@ldap.stub(:host=)
@ldap.stub(:port=)
@ldap.stub(:encryption)
@ldap.stub(:bind_as).and_return(true)
@ldap.stub(:authenticate).and_return(true)
@ldap.stub(:search).and_return([@ldap_entry])
Net::LDAP.stub(:new).and_return(@ldap)
end
describe '#validate' do
it 'validate with preauthentication and with extra attributes' do
auth = CASServer::Authenticators::LDAP.new
auth_config = HashWithIndifferentAccess.new(
:ldap => {
:host => "ad.example.net",
:port => 389,
:base => "dc=example,dc=net",
:filter => "(objectClass=person)",
:auth_user => "authenticator",
:auth_password => "itsasecret"
},
:extra_attributes => [:full_name, :address]
)
auth.configure(auth_config.merge('auth_index' => 0))
auth.validate(
:username => 'validusername',
:password => 'validpassword',
:service => 'test.service',
:request => {}
).should == true
auth.extra_attributes.should == {"full_name" => 'Test', "address" => 'Test'}
end
end
end