Skip to content

Commit 748f1b9

Browse files
author
Tom Maher
committed
add tests for cert/hostname mismatch
1 parent d7b36d1 commit 748f1b9

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/integration/test_bind.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,31 @@ def test_bind_tls_with_cafile
3737
end
3838

3939
def test_bind_tls_with_verify_none
40-
tls_options = OpenSSL::SSL::SSLContext::DEFAULT_PARAMS.merge(:verify_mode => OpenSSL::SSL::VERIFY_NONE)
40+
@ldap.host = '127.0.0.1'
41+
@ldap.port = 9389
42+
tls_options = OpenSSL::SSL::SSLContext::DEFAULT_PARAMS.merge(
43+
:verify_mode => OpenSSL::SSL::VERIFY_NONE,
44+
)
4145
@ldap.encryption(method: :start_tls, tls_options: tls_options)
4246
assert @ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: "passworD1"), @ldap.get_operation_result.inspect
4347
end
48+
49+
def test_bind_tls_with_bad_hostname
50+
@ldap.host = '127.0.0.1'
51+
@ldap.port = 9389
52+
tls_options = OpenSSL::SSL::SSLContext::DEFAULT_PARAMS.merge(
53+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
54+
:ca_file => CA_FILE,
55+
)
56+
@ldap.encryption(method: :start_tls, tls_options: tls_options)
57+
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")
61+
end
62+
assert_equal(
63+
"hostname \"#{@ldap.host}\" does not match the server certificate",
64+
error.message,
65+
)
66+
end
4467
end

0 commit comments

Comments
 (0)