def test_activate_extension(self): """Ensure extension activation/loading works""" ext = 'laurelin.extensions.netgroups' netgroups = LDAP.activate_extension(ext) self.assertIsInstance(netgroups, ModuleType) self.assertTrue(hasattr(LDAP, 'get_netgroup')) self.assertTrue(hasattr(netgroups, 'LAURELIN_ACTIVATED')) # ensure activating again does not cause an error LDAP.activate_extension(ext) with self.assertRaises(ImportError): LDAP.activate_extension('i.am.not.a.module')
def test_pagedresults(self): """Use the paged results controls to exercise the controls subsystem""" LDAP.activate_extension('laurelin.extensions.pagedresults') mock_sock = MockLDAPSocket() mock_sock.add_search_res_entry('', { 'supportedControl': [pagedresults.OID], 'namingContexts': ['o=testing'] }) mock_sock.add_search_res_done('') ldap = LDAP(mock_sock) test_dn = 'o=testing' test_cookie = 'foo' test_size = 2 # prepare response control controls = rfc4511.Controls() control = rfc4511.Control() ctrl_value = pagedresults.RealSearchControlValue() ctrl_value.setComponentByName('size', pagedresults.Size(test_size)) ctrl_value.setComponentByName('cookie', pagedresults.Cookie(test_cookie)) control.setComponentByName('controlType', rfc4511.LDAPOID(pagedresults.OID)) control.setComponentByName('controlValue', ber_encode(ctrl_value)) controls.setComponentByPosition(0, control) # prepare search results mock_sock.add_search_res_entry(test_dn, {}) mock_sock.add_search_res_entry(test_dn, {}) mock_sock.add_search_res_done(test_dn, controls=controls) # do search with critical ctrl_kwds = {pagedresults.PagedResultsControl.keyword: critical(test_size)} search = ldap.search(test_dn, **ctrl_kwds) # get all results results = list(search) self.assertEqual(len(results), test_size) self.assertTrue(hasattr(search, pagedresults.PagedResultsControl.response_attr)) self.assertEqual(getattr(search, pagedresults.PagedResultsControl.response_attr), test_cookie)
} }, { 'name': '389 Directory Server', 'connection': { 'server': 'ldap://localhost:11389', 'start_tls': False, 'simple_bind': { 'username': '******', 'password': '******' }, 'validators': [SchemaValidator()] } }] LDAP.enable_logging() LDAP.activate_extension('laurelin.extensions.descattrs') fails = [] for info in test_servers: print('Testing {0}'.format(info['name'])) try: with config.create_connection(info) as ldap: print(ldap.root_dse.format_ldif()) print('WHO AM I? {0}'.format(ldap.who_am_i())) for obj in ldap.base.search(): print(obj.format_ldif()) # test descattrs extension testobj = ldap.base.add_child(