@@ -65,8 +65,75 @@ def test_bind_tls_with_bad_hostname
6565 )
6666 end
6767
68- def test_bind_tls_with_good_hostname
69- omit_if true
70- assert_true false
68+ def test_bind_tls_with_valid_hostname
69+ @ldap . host = 'localhost'
70+ @ldap . port = 9389
71+ tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
72+ :verify_mode => OpenSSL ::SSL ::VERIFY_PEER ,
73+ :ca_file => CA_FILE ,
74+ )
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
80+ end
81+
82+ # The following depend on /etc/hosts hacking.
83+ # We can do that on CI, but it's less than cool on people's dev boxes
84+ def test_bind_tls_with_multiple_hosts
85+ 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_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
95+ end
96+
97+ def test_bind_tls_with_multiple_bogus_hosts
98+ 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 ,
102+ )
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+ 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" )
109+ end
110+ assert_equal ( "TODO - fix this" ,
111+ error . message )
112+ end
113+
114+ def test_bind_tls_with_multiple_bogus_hosts_no_verification
115+ omit_unless ENV [ 'TRAVIS' ] == 'true'
116+ tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
117+ :verify_mode => OpenSSL ::SSL ::VERIFY_NONE ,
118+ )
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
125+ end
126+
127+ def test_bind_tls_with_multiple_bogus_hosts_ca_check_only
128+ omit_unless ENV [ 'TRAVIS' ] == 'true'
129+ tls_options = OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS . merge (
130+ :ca_file => CA_FILE ,
131+ )
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
71138 end
72139end
0 commit comments