@@ -42,7 +42,18 @@ def test_bind_tls_with_cafile
42
42
@ldap . get_operation_result . inspect
43
43
end
44
44
45
- def test_bind_tls_with_verify_none
45
+ def test_bind_tls_with_bad_hostname_verify_none_no_ca_passes
46
+ @ldap . host = '127.0.0.1'
47
+ @ldap . port = 9389 unless ENV [ 'TRAVIS' ] == 'true'
48
+ @ldap . encryption (
49
+ method : :start_tls ,
50
+ tls_options : { verify_mode : OpenSSL ::SSL ::VERIFY_NONE } ,
51
+ )
52
+ assert @ldap . bind ( BIND_CREDS ) ,
53
+ @ldap . get_operation_result . inspect
54
+ end
55
+
56
+ def test_bind_tls_with_bad_hostname_verify_none_no_ca_opt_merge_passes
46
57
@ldap . host = '127.0.0.1'
47
58
@ldap . port = 9389 unless ENV [ 'TRAVIS' ] == 'true'
48
59
@ldap . encryption (
@@ -53,13 +64,13 @@ def test_bind_tls_with_verify_none
53
64
@ldap . get_operation_result . inspect
54
65
end
55
66
56
- def test_bind_tls_with_bad_hostname
67
+ def test_bind_tls_with_bad_hostname_verify_peer_ca_fails
57
68
@ldap . host = '127.0.0.1'
58
69
@ldap . port = 9389 unless ENV [ 'TRAVIS' ] == 'true'
59
70
@ldap . encryption (
60
71
method : :start_tls ,
61
- tls_options : TLS_OPTS . merge ( verify_mode : OpenSSL ::SSL ::VERIFY_PEER ,
62
- ca_file : CA_FILE ) ,
72
+ tls_options : { verify_mode : OpenSSL ::SSL ::VERIFY_PEER ,
73
+ ca_file : CA_FILE } ,
63
74
)
64
75
error = assert_raise Net ::LDAP ::Error ,
65
76
Net ::LDAP ::ConnectionRefusedError do
@@ -71,7 +82,24 @@ def test_bind_tls_with_bad_hostname
71
82
)
72
83
end
73
84
74
- def test_bind_tls_with_valid_hostname
85
+ def test_bind_tls_with_bad_hostname_ca_default_opt_merge_fails
86
+ @ldap . host = '127.0.0.1'
87
+ @ldap . port = 9389 unless ENV [ 'TRAVIS' ] == 'true'
88
+ @ldap . encryption (
89
+ method : :start_tls ,
90
+ tls_options : TLS_OPTS . merge ( ca_file : CA_FILE ) ,
91
+ )
92
+ error = assert_raise Net ::LDAP ::Error ,
93
+ Net ::LDAP ::ConnectionRefusedError do
94
+ @ldap . bind BIND_CREDS
95
+ end
96
+ assert_equal (
97
+ "hostname \" #{ @ldap . host } \" does not match the server certificate" ,
98
+ error . message ,
99
+ )
100
+ end
101
+
102
+ def test_bind_tls_with_valid_hostname_default_opts_passes
75
103
@ldap . host = 'localhost'
76
104
@ldap . port = 9389 unless ENV [ 'TRAVIS' ] == 'true'
77
105
@ldap . encryption (
@@ -83,6 +111,18 @@ def test_bind_tls_with_valid_hostname
83
111
@ldap . get_operation_result . inspect
84
112
end
85
113
114
+ def test_bind_tls_with_valid_hostname_just_verify_peer_ca_passes
115
+ @ldap . host = 'localhost'
116
+ @ldap . port = 9389 unless ENV [ 'TRAVIS' ] == 'true'
117
+ @ldap . encryption (
118
+ method : :start_tls ,
119
+ tls_options : { verify_mode : OpenSSL ::SSL ::VERIFY_PEER ,
120
+ ca_file : CA_FILE } ,
121
+ )
122
+ assert @ldap . bind ( BIND_CREDS ) ,
123
+ @ldap . get_operation_result . inspect
124
+ end
125
+
86
126
# The following depend on /etc/hosts hacking.
87
127
# We can do that on CI, but it's less than cool on people's dev boxes
88
128
def test_bind_tls_with_multiple_hosts
@@ -137,7 +177,7 @@ def test_bind_tls_with_multiple_bogus_hosts_ca_check_only
137
177
@ldap . hosts = [ [ '127.0.0.1' , 389 ] , [ 'bogus.example.com' , 389 ] ]
138
178
@ldap . encryption (
139
179
method : :start_tls ,
140
- tls_options : TLS_OPTS . merge ( ca_file : CA_FILE ) ,
180
+ tls_options : { ca_file : CA_FILE } ,
141
181
)
142
182
assert @ldap . bind ( BIND_CREDS ) ,
143
183
@ldap . get_operation_result . inspect
0 commit comments