| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -26,3 +26,4 @@ Classes | |
|
|
||
| .. autoclass:: slapdtest.SlapdTestCase | ||
| :members: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -28,9 +28,10 @@ | |
| os.environ['LDAPNOINIT'] = '1' | ||
|
|
||
| import ldap | ||
| import ldap.controls | ||
| import ldap.controls.ppolicy | ||
| from ldap.ldapobject import SimpleLDAPObject, ReconnectLDAPObject | ||
|
|
||
| from slapdtest import SlapdTestCase | ||
| from slapdtest import SlapdTestCase, SlapdObject | ||
| from slapdtest import requires_ldapi, requires_sasl, requires_tls | ||
|
|
||
|
|
||
| Expand Down Expand Up | @@ -75,6 +76,110 @@ | |
| """ | ||
|
|
||
|
|
||
| class PPolicyEnabledSlapdObject(SlapdObject): | ||
| """ | ||
| A subclass of :py:class:`SlapdObject` with password policy enabled. | ||
| Note that this class has no actual password policy configuration entries. | ||
| It is the job of the users of this class to define | ||
| the default password policies on their own. | ||
| The dn of the default is :attr:`.default_ppolicy_dn` of this class. | ||
| """ | ||
|
|
||
| openldap_schema_files = ( | ||
| 'core.schema', 'ppolicy.schema' | ||
| ) | ||
| modules = ( | ||
| 'ppolicy', | ||
| ) | ||
|
|
||
| default_ppolicy_dn = "cn=default-ppolicy,%(suffix)s" % { | ||
| 'suffix': SlapdObject.suffix | ||
| } | ||
|
|
||
| overlays = ( | ||
| { | ||
| 'name': 'ppolicy', | ||
| 'configuration': "\n".join([ | ||
| 'ppolicy_default "{}"'.format(default_ppolicy_dn), | ||
| # let slapd tell the clients that they are locked out | ||
| 'ppolicy_use_lockout']) | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| class Test02_ResponseControl(SlapdTestCase): | ||
| """ | ||
| tests abount response controls sent by the server | ||
| """ | ||
|
|
||
| ldap_object_class = SimpleLDAPObject | ||
| server_class = PPolicyEnabledSlapdObject | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| super(Test02_ResponseControl, cls).setUpClass() | ||
| # insert some Foo* objects via ldapadd | ||
| cls.server.ldapadd( | ||
| LDIF_TEMPLATE % { | ||
| 'suffix': cls.server.suffix, | ||
| 'rootdn': cls.server.root_dn, | ||
| 'rootcn': cls.server.root_cn, | ||
| 'rootpw': cls.server.root_pw, | ||
| 'dc': cls.server.suffix.split(',')[0][3:], | ||
| } | ||
| ) | ||
|
|
||
| # Very strict pwdMaxFailure in order to easily test the cases where | ||
| # bind failure with response controls is needed | ||
| cls.server.ldapadd( | ||
| '''dn: {dn} | ||
| objectClass: organizationalRole | ||
| objectClass: pwdPolicy | ||
| cn: default-ppolicy | ||
| pwdAttribute: userPassword | ||
| pwdLockout: TRUE | ||
| pwdMaxFailure: 1 | ||
| pwdLockoutDuration: 60 | ||
| pwdFailureCountInterval: 3600'''.format(dn=cls.server.default_ppolicy_dn) | ||
| ) | ||
|
|
||
| def test_response_controls_are_attached_to_exceptions(self): | ||
| base = self.server.suffix | ||
| cn = "test_response_controls_are_attached_to_exceptions" | ||
| user_dn = "cn={},{}".format(cn, base) | ||
| password = "user5_pw" | ||
|
|
||
| self.server.ldapadd( | ||
| '''dn: {dn} | ||
| objectClass: applicationProcess | ||
| objectClass: simpleSecurityObject | ||
| cn: {cn} | ||
| userPassword: {password}'''.format(cn=cn, dn=user_dn, password=password) | ||
| ) | ||
|
|
||
| ldap_conn = self.ldap_object_class(self.server.ldap_uri) | ||
|
|
||
| # Firstly cause a bind failure to lock out the account | ||
| with self.assertRaises(ldap.INVALID_CREDENTIALS) as cm: | ||
| wrong_password = 'wrong' + password | ||
| ldap_conn.simple_bind_s(user_dn, wrong_password) | ||
|
Comment thread
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityCould you also check here that ctrls is empty?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitychecked.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| empty_controls = cm.exception.args[0]['ctrls'] | ||
| self.assertEqual(len(empty_controls), 0) | ||
|
|
||
| with self.assertRaises(ldap.INVALID_CREDENTIALS) as cm: | ||
| ldap_conn.simple_bind_s( | ||
| user_dn, password, | ||
| serverctrls=[ldap.controls.ppolicy.PasswordPolicyControl()]) | ||
|
|
||
| controls = cm.exception.args[0]['ctrls'] | ||
| decoded_controls = ldap.controls.DecodeControlTuples(controls) | ||
| self.assertEqual(len(decoded_controls), 1) | ||
| pp = decoded_controls[0] | ||
| expected_error = ldap.controls.ppolicy.PasswordPolicyError('accountLocked') | ||
| self.assertEqual(pp.error, int(expected_error)) | ||
|
|
||
|
|
||
| class Test00_SimpleLDAPObject(SlapdTestCase): | ||
| """ | ||
| test LDAP search operations | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySince these attributes can be overridden in subclasses, they should be documented.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.