def ldap_directory(): top = ("o=test", {"o": "test"}) people = ("ou=people,o=test", {"ou": "people"}) groups = ("ou=groups,o=test", {"ou": "groups"}) ldapuser = ( "uid=ldapuser,ou=people,o=test", { "uid": ["ldapuser"], "objectClass": [ "person", "organizationalPerson", "inetOrgPerson", "posixAccount", ], "userPassword": ["Test1234!"], "uidNumber": ["1000"], "gidNumber": ["1000"], "givenName": ["givenName"], "mail": ["*****@*****.**"], "sn": ["LdapUser"], }, ) directory = dict([top, people, groups, ldapuser]) mock = mockldap.MockLdap(directory) mock.start() yield mock.stop()
def ldap_directory(): top = ('o=test', {'o': 'test'}) people = ('ou=people,o=test', {'ou': 'people'}) groups = ('ou=groups,o=test', {'ou': 'groups'}) ldapuser = ( 'uid=ldapuser,ou=people,o=test', { 'uid': ['ldapuser'], 'objectClass': [ 'person', 'organizationalPerson', 'inetOrgPerson', 'posixAccount' ], 'userPassword': ['Test1234!'], 'uidNumber': ['1000'], 'gidNumber': ['1000'], 'givenName': ['givenName'], 'mail': ['*****@*****.**'], 'sn': ['LdapUser'] } ) directory = dict([top, people, groups, ldapuser]) mock = mockldap.MockLdap(directory) mock.start() yield mock.stop()
def mock_ldap_setup( ldap_dc="dc=example,dc=com", bind_user="******", **kwargs): """Mock ldap setup. Args: ldap_dc: The base dc to use, eg 'dc=example,dc=com' bind_user: The mock user to use for ldap BIND Returns an instance of MockLdap. To apply the settings you must call `.start()` on the returned value. """ from django.conf import settings import mockldap directory = mock_ldap_directory(ldap_dc, bind_user, **kwargs) bind_user_dn = person_dn(bind_user, ldap_dc) settings.AUTH_LDAP_BIND_DN = bind_user_dn settings.AUTH_LDAP_BIND_PASSWORD = \ directory[bind_user_dn]['userPassword'][0] return mockldap.MockLdap(directory)
def setUpClass(cls): cls.mockldap = mockldap.MockLdap(cls.directory)
def setUpClass(cls): cls.configure_logger() cls.mockldap = mockldap.MockLdap(cls.directory) warnings.filterwarnings('ignore', message='.*?AUTH_PROFILE_MODULE', category=DeprecationWarning, module='django_auth_ldap')
def setUpClass(cls): # We only need to create the MockLdap instance once. The content we # pass in will be used for all LDAP connections. cls.mockldap = mockldap.MockLdap(cls.directory)
def setUpClass(cls): cls.configure_logger() cls.mockldap = mockldap.MockLdap(cls.directory)