6

I was reading on how to use ldap3 for mocking, and got this:

from ldap3 import Server, Connection, OFFLINE_AD_2012_R2, MOCK_SYNC


mock_server = Server('dummy_ad', get_info=OFFLINE_AD_2012_R2)
mock_conn   = Connection(mock_server, client_strategy=MOCK_SYNC)
mock_conn.bind()

Is it possible to have just the server run in one Python shell with some dummy users/passwords, and then connect and test authentication from another shell via ldap3?

Context - I want to add active directory authentication to a django app using ldap3. This is meant to be a first tier for testing the authentication function.

Jay
  • 2,535
  • 3
  • 32
  • 44

1 Answers1

0

ldap3 is a LDAP client library

The example of using client_strategy=MOCK_SYNC shows how to mock ldap3 in the django app itself. It does not actually run an ldap server in another process.

You can use the client_strategy=MOCK_SYNC to instantiate the mock Connection in the django app and feed it entries like so:

connection.strategy.add_entry('cn=user0,ou=test,o=lab', 
   {'userPassword': 'test0000', 'sn': 'user0_sn', 'revision': 0})
SargeATM
  • 2,483
  • 14
  • 24