|
2 | 2 | describe "OmniAuth::LDAP::Adaptor" do
|
3 | 3 |
|
4 | 4 | describe 'initialize' do
|
5 |
| - |
6 | 5 | it 'should throw exception when must have field is not set' do
|
7 | 6 | #[:host, :port, :method, :bind_dn]
|
8 |
| - lambda { OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'plain'})}.should raise_error(ArgumentError) |
| 7 | + lambda { OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'plain'})}.should raise_error(ArgumentError) |
9 | 8 | end
|
| 9 | + |
10 | 10 | it 'should throw exception when method is not supported' do
|
11 |
| - lambda { OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'myplain', uid: 'uid', port: 389, base: 'dc=com'})}.should raise_error(OmniAuth::LDAP::Adaptor::ConfigurationError) |
| 11 | + lambda { OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'myplain', uid: 'uid', port: 389, base: 'dc=com'})}.should raise_error(OmniAuth::LDAP::Adaptor::ConfigurationError) |
12 | 12 | end
|
13 | 13 |
|
14 | 14 | it 'should setup ldap connection with anonymous' do
|
|
17 | 17 | adaptor.connection.host.should == '192.168.1.145'
|
18 | 18 | adaptor.connection.port.should == 389
|
19 | 19 | adaptor.connection.base.should == 'dc=intridea, dc=com'
|
20 |
| - adaptor.connection.instance_variable_get('@auth').should == {:method => :anonymous, :username => nil, :password => nil} |
| 20 | + adaptor.connection.instance_variable_get('@auth').should == {:method => :anonymous, :username => nil, :password => nil} |
21 | 21 | end
|
| 22 | + |
22 | 23 | it 'should setup ldap connection with simple' do
|
23 | 24 | adaptor = OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'plain', base: 'dc=intridea, dc=com', port: 389, uid: 'sAMAccountName', bind_dn: 'bind_dn', password: 'password'})
|
24 | 25 | adaptor.connection.should_not == nil
|
25 | 26 | adaptor.connection.host.should == '192.168.1.145'
|
26 | 27 | adaptor.connection.port.should == 389
|
27 | 28 | adaptor.connection.base.should == 'dc=intridea, dc=com'
|
28 |
| - adaptor.connection.instance_variable_get('@auth').should == {:method => :simple, :username => 'bind_dn', :password => 'password'} |
29 |
| - end |
| 29 | + adaptor.connection.instance_variable_get('@auth').should == {:method => :simple, :username => 'bind_dn', :password => 'password'} |
| 30 | + end |
| 31 | + |
30 | 32 | it 'should setup ldap connection with sasl-md5' do
|
31 | 33 | adaptor = OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'plain', base: 'dc=intridea, dc=com', port: 389, uid: 'sAMAccountName', try_sasl: true, sasl_mechanisms: ["DIGEST-MD5"], bind_dn: 'bind_dn', password: 'password'})
|
32 | 34 | adaptor.connection.should_not == nil
|
33 | 35 | adaptor.connection.host.should == '192.168.1.145'
|
34 | 36 | adaptor.connection.port.should == 389
|
35 | 37 | adaptor.connection.base.should == 'dc=intridea, dc=com'
|
36 |
| - adaptor.connection.instance_variable_get('@auth')[:method].should == :sasl |
37 |
| - adaptor.connection.instance_variable_get('@auth')[:mechanism].should == 'DIGEST-MD5' |
38 |
| - adaptor.connection.instance_variable_get('@auth')[:initial_credential].should == '' |
39 |
| - adaptor.connection.instance_variable_get('@auth')[:challenge_response].should_not be_nil |
| 38 | + adaptor.connection.instance_variable_get('@auth')[:method].should == :sasl |
| 39 | + adaptor.connection.instance_variable_get('@auth')[:mechanism].should == 'DIGEST-MD5' |
| 40 | + adaptor.connection.instance_variable_get('@auth')[:initial_credential].should == '' |
| 41 | + adaptor.connection.instance_variable_get('@auth')[:challenge_response].should_not be_nil |
40 | 42 | end
|
| 43 | + |
41 | 44 | it 'should setup ldap connection with sasl-gss' do
|
42 | 45 | adaptor = OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'plain', base: 'dc=intridea, dc=com', port: 389, uid: 'sAMAccountName', try_sasl: true, sasl_mechanisms: ["GSS-SPNEGO"], bind_dn: 'bind_dn', password: 'password'})
|
43 | 46 | adaptor.connection.should_not == nil
|
44 | 47 | adaptor.connection.host.should == '192.168.1.145'
|
45 | 48 | adaptor.connection.port.should == 389
|
46 | 49 | adaptor.connection.base.should == 'dc=intridea, dc=com'
|
47 |
| - adaptor.connection.instance_variable_get('@auth')[:method].should == :sasl |
48 |
| - adaptor.connection.instance_variable_get('@auth')[:mechanism].should == 'GSS-SPNEGO' |
49 |
| - adaptor.connection.instance_variable_get('@auth')[:initial_credential].should =~ /^NTLMSSP/ |
50 |
| - adaptor.connection.instance_variable_get('@auth')[:challenge_response].should_not be_nil |
| 50 | + adaptor.connection.instance_variable_get('@auth')[:method].should == :sasl |
| 51 | + adaptor.connection.instance_variable_get('@auth')[:mechanism].should == 'GSS-SPNEGO' |
| 52 | + adaptor.connection.instance_variable_get('@auth')[:initial_credential].should =~ /^NTLMSSP/ |
| 53 | + adaptor.connection.instance_variable_get('@auth')[:challenge_response].should_not be_nil |
51 | 54 | end
|
52 | 55 | end
|
53 |
| - |
| 56 | + |
54 | 57 | describe 'bind_as' do
|
55 | 58 | let(:args) { {:filter => Net::LDAP::Filter.eq('sAMAccountName', 'username'), :password => 'password', :size => 1} }
|
56 | 59 | let(:rs) { Struct.new(:dn).new('new dn') }
|
| 60 | + |
57 | 61 | it 'should bind simple' do
|
58 | 62 | adaptor = OmniAuth::LDAP::Adaptor.new({host: "192.168.1.126", method: 'plain', base: 'dc=score, dc=local', port: 389, uid: 'sAMAccountName', bind_dn: 'bind_dn', password: 'password'})
|
59 | 63 | adaptor.connection.should_receive(:open).and_yield(adaptor.connection)
|
60 |
| - adaptor.connection.should_receive(:search).with(args).and_return([rs]) |
| 64 | + adaptor.connection.should_receive(:search).with(args).and_return([rs]) |
61 | 65 | adaptor.connection.should_receive(:bind).with({:username => 'new dn', :password => args[:password], :method => :simple}).and_return(true)
|
62 | 66 | adaptor.bind_as(args).should == rs
|
63 | 67 | end
|
| 68 | + |
64 | 69 | it 'should bind sasl' do
|
65 | 70 | adaptor = OmniAuth::LDAP::Adaptor.new({host: "192.168.1.145", method: 'plain', base: 'dc=intridea, dc=com', port: 389, uid: 'sAMAccountName', try_sasl: true, sasl_mechanisms: ["GSS-SPNEGO"], bind_dn: 'bind_dn', password: 'password'})
|
66 | 71 | adaptor.connection.should_receive(:open).and_yield(adaptor.connection)
|
67 |
| - adaptor.connection.should_receive(:search).with(args).and_return([rs]) |
| 72 | + adaptor.connection.should_receive(:search).with(args).and_return([rs]) |
68 | 73 | adaptor.connection.should_receive(:bind).and_return(true)
|
69 | 74 | adaptor.bind_as(args).should == rs
|
70 | 75 | end
|
|
0 commit comments