-
Notifications
You must be signed in to change notification settings - Fork 126
Attach response controls to exceptions #251
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
Attach response controls to exceptions #251
Conversation
Codecov Report
@@ Coverage Diff @@
## master #251 +/- ##
===========================================
+ Coverage 57.91% 71.08% +13.16%
===========================================
Files 49 49
Lines 5910 4824 -1086
Branches 815 815
===========================================
+ Hits 3423 3429 +6
+ Misses 2157 1064 -1093
- Partials 330 331 +1
Continue to review full report at Codecov.
|
Lib/slapdtest/_slapdtest.py
Outdated
:py:class:`PPolicyEnabledSlapdObject` as the slapd controller. | ||
""" | ||
|
||
server_class = PPolicyEnabledSlapdObject |
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.
Is this necessary? PPolicyEnabledSlapdTestCase
needs to be subclassed; the subclass can set its server_class
directly.
Lib/slapdtest/_slapdtest.py
Outdated
@@ -596,3 +623,43 @@ def setUpClass(cls): | |||
@classmethod | |||
def tearDownClass(cls): | |||
cls.server.stop() | |||
|
|||
|
|||
class PPolicyEnabledSlapdObject(SlapdObject): |
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.
Do you think this class will be needed for more than just one test? If not, would it be better to define the class just in the file for that test?
@@ -187,6 +191,9 @@ class SlapdObject(object): | |||
'core.schema', | |||
) | |||
|
|||
modules = () | |||
overlays = () |
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.
Since these attributes can be overridden in subclasses, they should be documented.
Lib/slapdtest/_slapdtest.py
Outdated
ldap_conn.simple_bind_s(who or self.server.root_dn, cred or self.server.root_pw) | ||
return ldap_conn | ||
|
||
def _make_ldap_object(self, **kwargs): |
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 subclasses are supposed to call this, it should be documented.
Perhaps it would be better to add an overridable bind=True
class attribute?
Modules/constants.c
Outdated
@@ -104,6 +104,11 @@ LDAPerror(LDAP *l, char *msg) | |||
ldap_memfree(matched); | |||
} | |||
|
|||
if (pyctrls != NULL) { | |||
PyDict_SetItemString(info, "ctrls", pyctrls); | |||
/* Py_XDECREF(pyctrls) must be called on caller side */ |
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.
Needing to call Py_XDECREF(pyctrls)
is implied by Python's calling convention – it's a borrowed reference. No need to point it out here.
Tests/t_ldapobject.py
Outdated
|
||
controls = cm.exception.args[0]['ctrls'] | ||
pp = ldap.controls.DecodeControlTuples(controls)[0] | ||
self.assertEqual(pp.error, 1) # error == 1 means AccountLockout |
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.
Should we have a constant for AccountLockout
somewhere?
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.
Could you also check len(ldap.controls.DecodeControlTuples(controls))
?
# Firstly cause a bind failure to lock out the account | ||
with self.assertRaises(ldap.INVALID_CREDENTIALS): | ||
wrong_password = 'wrong' + password | ||
ldap_conn.simple_bind_s(user_dn, wrong_password) |
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.
Could you also check here that ctrls
is empty?
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.
checked.
Thank you for quick and detailed review.
acafa3a
to
a0ba399
Compare
I haven't finished yet. |
I have started related work on this and #177 in https://github.com/mistotebe/python-ldap/tree/exceptions, @somay could you have a look and see if these two could be reconciled (I'm happy to do that)? |
Petr and I are at PyCon until end of next week. It may take two weeks until we are able to look into your PR. I noticed some unrelated improvements like a memory leak fix and some changes to slapdtest. Could you please file separate bugs and PRs for these? Thanks |
@tiran sure, hope you're having fun, either of you attending this year's LDAPCon? The linked branch is a work in progress and I've been rewriting it along the way, I guess I can split things at some point when they've settled. Also, do you think you'll have some time to moderate the email I sent to the mailing list? |
@mistotebe sorry for long inactivity. |
Thanks to @mistotebe's work in #288, response controls will be available under |
Fixes: #208
exception.args[0]['ctrls']
is a list of the form of(oid: str, criticality: int, berval: bytes)
.I've choose
ctrls
instead ofcontrols
as the key of the dictionary because the other keys are also abbreviated likedesc
,info
.