2
2
3
3
class TestBindIntegration < LDAPIntegrationTestCase
4
4
def test_bind_success
5
- assert @ldap . bind ( method : :simple , username : "uid=user1,ou=People,dc=rubyldap,dc=com" , password : "passworD1" ) , @ldap . get_operation_result . inspect
5
+ assert @ldap . bind ( BIND_CREDS ) ,
6
+ @ldap . get_operation_result . inspect
6
7
end
7
8
8
9
def test_bind_timeout
9
10
@ldap . port = 8389
10
11
error = assert_raise Net ::LDAP ::Error do
11
- @ldap . bind ( method : :simple , username : "uid=user1,ou=People,dc=rubyldap,dc=com" , password : "passworD1" )
12
+ @ldap . bind BIND_CREDS
12
13
end
13
14
msgs = [ 'Operation timed out - user specified timeout' ,
14
15
'Connection timed out - user specified timeout' ]
15
16
assert_send ( [ msgs , :include? , error . message ] )
16
17
end
17
18
18
19
def test_bind_anonymous_fail
19
- refute @ldap . bind ( method : :simple , username : "uid=user1,ou=People,dc=rubyldap,dc=com" , password : "" ) , @ldap . get_operation_result . inspect
20
+ refute @ldap . bind ( BIND_CREDS . merge ( password : '' ) ) ,
21
+ @ldap . get_operation_result . inspect
20
22
21
23
result = @ldap . get_operation_result
22
24
assert_equal Net ::LDAP ::ResultCodeUnwillingToPerform , result . code
@@ -27,37 +29,40 @@ def test_bind_anonymous_fail
27
29
end
28
30
29
31
def test_bind_fail
30
- refute @ldap . bind ( method : :simple , username : "uid=user1,ou=People,dc=rubyldap,dc=com" , password : "not my password" ) , @ldap . get_operation_result . inspect
32
+ refute @ldap . bind ( BIND_CREDS . merge ( password : "not my password" ) ) ,
33
+ @ldap . get_operation_result . inspect
31
34
end
32
35
33
36
def test_bind_tls_with_cafile
34
- tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge ( :ca_file => CA_FILE )
35
- @ldap . encryption ( method : :start_tls , tls_options : tls_options )
36
- assert @ldap . bind ( method : :simple , username : "uid=user1,ou=People,dc=rubyldap,dc=com" , password : "passworD1" ) , @ldap . get_operation_result . inspect
37
+ @ldap . encryption (
38
+ method : :start_tls ,
39
+ tls_options : TLS_OPTS . merge ( ca_file : CA_FILE ) ,
40
+ )
41
+ assert @ldap . bind ( BIND_CREDS ) ,
42
+ @ldap . get_operation_result . inspect
37
43
end
38
44
39
45
def test_bind_tls_with_verify_none
40
46
@ldap . host = '127.0.0.1'
41
47
@ldap . port = 9389
42
- tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
43
- :verify_mode => OpenSSL ::SSL ::VERIFY_NONE ,
48
+ @ldap . encryption (
49
+ method : :start_tls ,
50
+ tls_options : TLS_OPTS . merge ( verify_mode : OpenSSL ::SSL ::VERIFY_NONE ) ,
44
51
)
45
- @ldap . encryption ( method : :start_tls , tls_options : tls_options )
46
- assert @ldap . bind ( method : :simple , username : "uid=user1,ou=People,dc=rubyldap,dc=com" , password : "passworD1" ) , @ldap . get_operation_result . inspect
52
+ assert @ldap . bind ( BIND_CREDS ) ,
53
+ @ldap . get_operation_result . inspect
47
54
end
48
55
49
56
def test_bind_tls_with_bad_hostname
50
57
@ldap . host = '127.0.0.1'
51
58
@ldap . port = 9389
52
- tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
53
- :verify_mode => OpenSSL ::SSL ::VERIFY_PEER ,
54
- :ca_file => CA_FILE ,
59
+ @ldap . encryption (
60
+ method : :start_tls ,
61
+ tls_options : TLS_OPTS . merge ( verify_mode : OpenSSL ::SSL ::VERIFY_PEER ,
62
+ ca_file : CA_FILE ) ,
55
63
)
56
- @ldap . encryption ( method : :start_tls , tls_options : tls_options )
57
64
error = assert_raise Net ::LDAP ::Error do
58
- @ldap . bind ( method : :simple ,
59
- username : "uid=user1,ou=People,dc=rubyldap,dc=com" ,
60
- password : "passworD1" )
65
+ @ldap . bind BIND_CREDS
61
66
end
62
67
assert_equal (
63
68
"hostname \" #{ @ldap . host } \" does not match the server certificate" ,
@@ -68,72 +73,71 @@ def test_bind_tls_with_bad_hostname
68
73
def test_bind_tls_with_valid_hostname
69
74
@ldap . host = 'localhost'
70
75
@ldap . port = 9389
71
- tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
72
- :verify_mode => OpenSSL ::SSL ::VERIFY_PEER ,
73
- :ca_file => CA_FILE ,
76
+ @ldap . encryption (
77
+ method : :start_tls ,
78
+ tls_options : TLS_OPTS . merge ( verify_mode : OpenSSL ::SSL ::VERIFY_PEER ,
79
+ ca_file : CA_FILE ) ,
74
80
)
75
- @ldap . encryption ( method : :start_tls , tls_options : tls_options )
76
- assert @ldap . bind ( method : :simple ,
77
- username : "uid=user1,ou=People,dc=rubyldap,dc=com" ,
78
- password : "passworD1" )
79
- @ldap . get_operation_result . inspect
81
+ assert @ldap . bind ( BIND_CREDS ) ,
82
+ @ldap . get_operation_result . inspect
80
83
end
81
84
82
85
# The following depend on /etc/hosts hacking.
83
86
# We can do that on CI, but it's less than cool on people's dev boxes
84
87
def test_bind_tls_with_multiple_hosts
85
88
omit_unless ENV [ 'TRAVIS' ] == 'true'
86
- tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
87
- :verify_mode => OpenSSL ::SSL ::VERIFY_PEER ,
88
- :ca_file => CA_FILE ,
89
+
90
+ @ldap . host = nil
91
+ @ldap . hosts = [ [ 'ldap01.example.com' , 389 ] , [ 'ldap02.example.com' , 389 ] ]
92
+ @ldap . encryption (
93
+ method : :start_tls ,
94
+ tls_options : TLS_OPTS . merge ( verify_mode : OpenSSL ::SSL ::VERIFY_PEER ,
95
+ ca_file : CA_FILE ) ,
89
96
)
90
- @ldap_multi . encryption ( method : :start_tls , tls_options : tls_options )
91
- assert @ldap_multi . bind ( method : :simple ,
92
- username : "uid=user1,ou=People,dc=rubyldap,dc=com" ,
93
- password : "passworD1" )
94
- @ldap_multi . get_operation_result . inspect
97
+ assert @ldap . bind ( BIND_CREDS ) ,
98
+ @ldap . get_operation_result . inspect
95
99
end
96
100
97
101
def test_bind_tls_with_multiple_bogus_hosts
98
102
omit_unless ENV [ 'TRAVIS' ] == 'true'
99
- tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
100
- :verify_mode => OpenSSL ::SSL ::VERIFY_PEER ,
101
- :ca_file => CA_FILE ,
103
+
104
+ @ldap . host = nil
105
+ @ldap . hosts = [ [ '127.0.0.1' , 389 ] , [ 'bogus.example.com' , 389 ] ]
106
+ @ldap . encryption (
107
+ method : :start_tls ,
108
+ tls_options : TLS_OPTS . merge ( verify_mode : OpenSSL ::SSL ::VERIFY_PEER ,
109
+ ca_file : CA_FILE ) ,
102
110
)
103
- @ldap_multi . hosts = [ [ '127.0.0.1' , 389 ] , [ 'bogus.example.com' , 389 ] ]
104
- @ldap_multi . encryption ( method : :start_tls , tls_options : tls_options )
105
111
error = assert_raise Net ::LDAP ::Error do
106
- @ldap_multi . bind ( method : :simple ,
107
- username : "uid=user1,ou=People,dc=rubyldap,dc=com" ,
108
- password : "passworD1" )
112
+ @ldap . bind BIND_CREDS
109
113
end
110
114
assert_equal ( "TODO - fix this" ,
111
115
error . message )
112
116
end
113
117
114
118
def test_bind_tls_with_multiple_bogus_hosts_no_verification
115
119
omit_unless ENV [ 'TRAVIS' ] == 'true'
116
- tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
117
- :verify_mode => OpenSSL ::SSL ::VERIFY_NONE ,
120
+
121
+ @ldap . host = nil
122
+ @ldap . hosts = [ [ '127.0.0.1' , 389 ] , [ 'bogus.example.com' , 389 ] ]
123
+ @ldap . encryption (
124
+ method : :start_tls ,
125
+ tls_options : TLS_OPTS . merge ( verify_mode : OpenSSL ::SSL ::VERIFY_NONE ) ,
118
126
)
119
- @ldap_multi . hosts = [ [ '127.0.0.1' , 389 ] , [ 'bogus.example.com' , 389 ] ]
120
- @ldap_multi . encryption ( method : :start_tls , tls_options : tls_options )
121
- assert @ldap_multi . bind ( method : :simple ,
122
- username : "uid=user1,ou=People,dc=rubyldap,dc=com" ,
123
- password : "passworD1" )
124
- @ldap_multi . get_operation_result . inspect
127
+ assert @ldap . bind ( BIND_CREDS ) ,
128
+ @ldap . get_operation_result . inspect
125
129
end
126
130
127
131
def test_bind_tls_with_multiple_bogus_hosts_ca_check_only
128
132
omit_unless ENV [ 'TRAVIS' ] == 'true'
129
- tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
130
- :ca_file => CA_FILE ,
133
+
134
+ @ldap . host = nil
135
+ @ldap . hosts = [ [ '127.0.0.1' , 389 ] , [ 'bogus.example.com' , 389 ] ]
136
+ @ldap . encryption (
137
+ method : :start_tls ,
138
+ tls_options : TLS_OPTS . merge ( ca_file : CA_FILE ) ,
131
139
)
132
- @ldap_multi . hosts = [ [ '127.0.0.1' , 389 ] , [ 'bogus.example.com' , 389 ] ]
133
- @ldap_multi . encryption ( method : :start_tls , tls_options : tls_options )
134
- assert @ldap_multi . bind ( method : :simple ,
135
- username : "uid=user1,ou=People,dc=rubyldap,dc=com" ,
136
- password : "passworD1" )
137
- @ldap_multi . get_operation_result . inspect
140
+ assert @ldap . bind ( BIND_CREDS ) ,
141
+ @ldap . get_operation_result . inspect
138
142
end
139
143
end
0 commit comments