-
Notifications
You must be signed in to change notification settings - Fork 126
Add high level LDAPObject.set_tls_options() #350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,6 +418,62 @@ def test_multiple_starttls(self): | |
l.simple_bind_s(self.server.root_dn, self.server.root_pw) | ||
self.assertEqual(l.whoami_s(), 'dn:' + self.server.root_dn) | ||
|
||
def assert_option_equal(self, conn, option, value): | ||
self.assertEqual(conn.get_option(option), value) | ||
|
||
@requires_tls() | ||
def test_set_tls_options_ldap(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the coverage report has failed. If you haven't started on the test suite expansion yet, I can take a look later and add a few tests so it will cover the rest of the code. :) |
||
# just any directory will do | ||
certdir = os.path.dirname(__file__) | ||
conn = self.ldap_object_class(self.server.ldap_uri) | ||
conn.set_tls_options( | ||
cacertfile=self.server.cafile, | ||
# just any directory | ||
cacertdir=certdir, | ||
require_cert=ldap.OPT_X_TLS_DEMAND, | ||
protocol_min=0x303, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a very minor nitpick. |
||
# libldap on Travis CI doesn't like cipher_suite | ||
# cipher_suite="ALL", | ||
certfile=self.server.clientcert, | ||
keyfile=self.server.clientkey, | ||
# libldap on TravisCI doesn't like CRL options | ||
# crlfile=None, | ||
# crlcheck=ldap.OPT_X_TLS_CRL_PEER, | ||
start_tls=False | ||
) | ||
self.assert_option_equal( | ||
conn, ldap.OPT_X_TLS_CACERTFILE, self.server.cafile | ||
) | ||
self.assert_option_equal( | ||
conn, ldap.OPT_X_TLS_CACERTDIR, certdir | ||
) | ||
self.assert_option_equal( | ||
conn, ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND | ||
) | ||
# cipher_suite depends on OpenSSL version and system settings | ||
self.assert_option_equal( | ||
conn, ldap.OPT_X_TLS_PROTOCOL_MIN, 0x303 | ||
) | ||
self.assert_option_equal( | ||
conn, ldap.OPT_X_TLS_CERTFILE, self.server.clientcert | ||
) | ||
self.assert_option_equal( | ||
conn, ldap.OPT_X_TLS_KEYFILE, self.server.clientkey, | ||
) | ||
# self.assert_option_equal( | ||
# conn, ldap.OPT_X_TLS_CRLFILE, crlfile | ||
# ) | ||
# self.assert_option_equal( | ||
# conn, ldap.OPT_X_TLS_CRLCHECK, ldap.OPT_X_TLS_CRL_PEER | ||
# ) | ||
|
||
# run again, this time with default start_tls. | ||
conn.set_tls_options() | ||
# second call should fail | ||
with self.assertRaises(ValueError) as e: | ||
conn.set_tls_options() | ||
self.assertIn("TLS connection already established", str(e.exception)) | ||
|
||
def test_dse(self): | ||
dse = self._ldap_conn.read_rootdse_s() | ||
self.assertIsInstance(dse, dict) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly the exception types... I think this one will fit a bit better -
EnvironmentError
(instead ofValueError
).