-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing of PPolicyControl ASN.1 structure
Password policy control decoder failed to handle graceAuthNsRemaining
correctly. The warning.getComponentByName('timeBeforeExpiration') call
materialized the time before expiration CHOICE element. The fixed
implementation uses pyasn1's dict interface to check which CHOICE
element is set.
https://github.com/python-ldap/python-ldap/pull/194
Closes: https://github.com/python-ldap/python-ldap/issues/192
See: https://github.com/python-ldap/python-ldap/issues/193
Signed-off-by: Christian Heimes <cheimes@redhat.com>- Loading branch information
Christian Heimes
authored and
Petr Viktorin
committed
Mar 27, 2018
1 parent
f477486
commit 4a6a719
Showing
2 changed files
with
49 additions
and
19 deletions.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import os | ||
| import unittest | ||
|
|
||
| # Switch off processing .ldaprc or ldap.conf before importing _ldap | ||
| os.environ['LDAPNOINIT'] = '1' | ||
|
|
||
| from ldap.controls import ppolicy | ||
|
|
||
|
|
||
| PP_GRACEAUTH = b'0\x84\x00\x00\x00\t\xa0\x84\x00\x00\x00\x03\x81\x01\x02' | ||
| PP_TIMEBEFORE = b'0\x84\x00\x00\x00\t\xa0\x84\x00\x00\x00\x03\x80\x012' | ||
|
|
||
|
|
||
| class TestControlsPPolicy(unittest.TestCase): | ||
| def assertPPolicy(self, pp, timeBeforeExpiration=None, | ||
| graceAuthNsRemaining=None, error=None): | ||
| self.assertEqual(pp.timeBeforeExpiration, timeBeforeExpiration) | ||
| self.assertEqual(pp.graceAuthNsRemaining, graceAuthNsRemaining) | ||
| self.assertEqual(pp.error, error) | ||
|
|
||
| def test_ppolicy_graceauth(self): | ||
| pp = ppolicy.PasswordPolicyControl() | ||
| pp.decodeControlValue(PP_GRACEAUTH) | ||
| self.assertPPolicy(pp, graceAuthNsRemaining=2) | ||
|
|
||
| def test_ppolicy_timebefore(self): | ||
| pp = ppolicy.PasswordPolicyControl() | ||
| pp.decodeControlValue(PP_TIMEBEFORE) | ||
| self.assertPPolicy(pp, timeBeforeExpiration=50) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |