Example #1
0
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()
Example #2
0
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()
Example #3
0
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)
Example #4
0
 def setUpClass(cls):
     cls.mockldap = mockldap.MockLdap(cls.directory)
Example #5
0
    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')
Example #6
0
 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)
Example #7
0
 def setUpClass(cls):
     cls.configure_logger()
     cls.mockldap = mockldap.MockLdap(cls.directory)