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