def setUp(self): SetupMixin.setUp(self) d=self.config.db.lookup('cn=fred,dc=example,dc=com') ldapconfig.loadConfig(configFiles=[], reload=True) def _setPassword(e, password): return e.setPassword(password) d.addCallback(_setPassword, 'flintstone') ldaptestutil.pumpingDeferredResult(d) os.mkdir(os.path.join(self.spool, 'example.com', 'h1'))
def getSearchFieldByName(name, vars): for pri, n, raw in _getSearchFields(): if n == name: cfg = config.loadConfig() val = cfg.get('webui', raw, raw=None, vars=vars) return val return None
def getSearchFieldByName(name, vars): for pri, n, raw in _getSearchFields(): if n == name: cfg = config.loadConfig() val = cfg.get("webui", raw, raw=None, vars=vars) return val return None
def testSomething(self): self.dir = self.mktemp() os.mkdir(self.dir) self.f1 = os.path.join(self.dir, 'one.cfg') writeFile( self.f1, """\ [fooSection] fooVar = val [barSection] barVar = anotherVal """) self.f2 = os.path.join(self.dir, 'two.cfg') writeFile(self.f2, """\ [fooSection] fooVar = val2 """) self.cfg = config.loadConfig(configFiles=[self.f1, self.f2], reload=True) val = self.cfg.get('fooSection', 'fooVar') self.assertEquals(val, 'val2') val = self.cfg.get('barSection', 'barVar') self.assertEquals(val, 'anotherVal')
def testMultileConfigurationFile(self): """ It can read configuration from multiple files, merging the loaded values. """ self.dir = self.mktemp() os.mkdir(self.dir) self.f1 = os.path.join(self.dir, 'one.cfg') writeFile( self.f1, """\ [fooSection] fooVar = val [barSection] barVar = anotherVal """) self.f2 = os.path.join(self.dir, 'two.cfg') writeFile(self.f2, """\ [fooSection] fooVar = val2 """) self.cfg = config.loadConfig(configFiles=[self.f1, self.f2], reload=True) val = self.cfg.get('fooSection', 'fooVar') self.assertEqual(val, 'val2') val = self.cfg.get('barSection', 'barVar') self.assertEqual(val, 'anotherVal')
def testMultileConfigurationFile(self): """ It can read configuration from multiple files, merging the loaded values. """ self.dir = self.mktemp() os.mkdir(self.dir) self.f1 = os.path.join(self.dir, "one.cfg") writeFile( self.f1, b"""\ [fooSection] fooVar = val [barSection] barVar = anotherVal """, ) self.f2 = os.path.join(self.dir, "two.cfg") writeFile( self.f2, b"""\ [fooSection] fooVar = val2 """, ) self.cfg = config.loadConfig(configFiles=[self.f1, self.f2], reload=True) val = self.cfg.get("fooSection", "fooVar") self.assertEqual(val, "val2") val = self.cfg.get("barSection", "barVar") self.assertEqual(val, "anotherVal")
def testSomething(self): self.dir = self.mktemp() os.mkdir(self.dir) self.f1 = os.path.join(self.dir, 'one.cfg') writeFile(self.f1, """\ [fooSection] fooVar = val [barSection] barVar = anotherVal """) self.f2 = os.path.join(self.dir, 'two.cfg') writeFile(self.f2, """\ [fooSection] fooVar = val2 """) self.cfg = config.loadConfig( configFiles=[self.f1, self.f2], reload=True) val = self.cfg.get('fooSection', 'fooVar') self.assertEquals(val, 'val2') val = self.cfg.get('barSection', 'barVar') self.assertEquals(val, 'anotherVal')
def testKnownValues(self): """ When lanman password are enabled in the configuration, they will return """ cfg = config.loadConfig() cfg.set('samba', 'use-lmhash', 'yes') self.assertEqual(self.knownValues, [(p, smbpassword.lmhash(p)) for p, _ in self.knownValues])
def testLMHashConfiguationDisabled(self): """ When the lanman passwords are disabled from the configuration, it will return the disabled password. """ cfg = config.loadConfig() cfg.set('samba', 'use-lmhash', 'no') result = smbpassword.lmhash(b'any-pass') self.assertEqual(32 * b'X', result)
def setUp(self): self.dir = self.mktemp() os.mkdir(self.dir) self.f1 = os.path.join(self.dir, 'one.cfg') writeFile( self.f1, """\ [authentication] identity-search = (something=%(name)s) """) self.cfg = config.loadConfig(configFiles=[self.f1], reload=True) self.config = config.LDAPConfig()
def testLMHashConfiguationDisabled(self): """ When the lanman passwords are disabled from the configuration, it will return the disabled password. """ cfg = config.loadConfig() cfg.set("samba", "use-lmhash", "no") result = smbpassword.lmhash(b"any-pass") self.assertEqual(32 * b"X", result)
def testKnownValues(self): """ When lanman password are enabled in the configuration, they will return """ cfg = config.loadConfig() cfg.set('samba', 'use-lmhash', 'yes') self.assertEqual( self.knownValues, [(p, smbpassword.lmhash(p)) for p, _ in self.knownValues] )
def setUp(self): self.dir = self.mktemp() os.mkdir(self.dir) self.f1 = os.path.join(self.dir, 'one.cfg') writeFile(self.f1, """\ [authentication] identity-search = (something=%(name)s) """) self.cfg = config.loadConfig( configFiles=[self.f1], reload=True) self.config = config.LDAPConfig()
def testKnownValues(self): """ When lanman password are enabled in the configuration, they will return """ cfg = config.loadConfig() cfg.set('samba', 'use-lmhash', 'yes') for password, expected in self.knownValues: result = smbpassword.lmhash(password) self.assertEqual(expected, result)
def _getSearchFields(): cfg = config.loadConfig() if not cfg.has_section("webui"): return for raw in cfg.options("webui"): if not raw: continue l = raw.split(None, 2) if l[0].lower() == "search-field": pri, name = l[1:] pri = int(pri) yield (pri, name, raw)
def _getSearchFields(): cfg = config.loadConfig() if not cfg.has_section('webui'): return for raw in cfg.options('webui'): if not raw: continue l=raw.split(None, 2) if l[0].lower() == 'search-field': pri, name = l[1:] pri = int(pri) yield (pri, name, raw)
def testKnownValues(self): """lmhash(...) gives known results""" cfg = config.loadConfig() for password, expected_result in self.knownValues: cfg.set('samba', 'use-lmhash', 'no') disabled = smbpassword.lmhash(password) self.assertEquals(disabled, 32 * 'X', "Disabled lmhash must be X's: %r" % disabled) cfg.set('samba', 'use-lmhash', 'yes') result = smbpassword.lmhash(password) if result != expected_result: raise AssertionError, 'lmhash(%s)=%s, expected %s' \ % (repr(password), repr(result), repr(expected_result))
def testKnownValues(self): """lmhash(...) gives known results""" cfg = config.loadConfig() for password, expected in self.knownValues: cfg.set('samba', 'use-lmhash', 'no') disabled = smbpassword.lmhash(password) self.assertEqual(disabled, 32 * 'X', "Disabled lmhash must be X's: %r" % disabled) cfg.set('samba', 'use-lmhash', 'yes') result = smbpassword.lmhash(password) self.assertEqual(expected, result)
def reloadFromContent(testCase, content): """ Reload the global configuration file with raw `content`. """ base_path = testCase.mktemp() os.mkdir(base_path) config_path = os.path.join(base_path, "test.cfg") writeFile(config_path, content) # Reload with empty content to reduce the side effects. testCase.addCleanup(reloadFromContent, testCase, b"") return config.loadConfig( configFiles=[config_path], reload=True, )
def createServer(proto, *responses, **kw): def createClient(factory): factory.doStart() #TODO factory.startedConnecting(c) proto = factory.buildProtocol(addr=None) proto.connectionMade() cfg = config.loadConfig(configFiles=[], reload=True) overrides = kw.setdefault('serviceLocationOverrides', {}) overrides.setdefault('', createClient) conf = config.LDAPConfig(**kw) server = proto(conf) server.protocol = lambda: LDAPClientTestDriver(*responses) server.transport = proto_helpers.StringTransport() server.connectionMade() return server
def testKnownValues(self): """lmhash(...) gives known results""" cfg = config.loadConfig() for password, expected_result in self.knownValues: cfg.set("samba", "use-lmhash", "no") disabled = smbpassword.lmhash(password) self.assertEquals(disabled, 32 * "X", "Disabled lmhash must be X's: %r" % disabled) cfg.set("samba", "use-lmhash", "yes") result = smbpassword.lmhash(password) if result != expected_result: raise AssertionError, "lmhash(%s)=%s, expected %s" % ( repr(password), repr(result), repr(expected_result), )
def createServer(proto, *responses, **kw): def createClient(factory): factory.doStart() #TODO factory.startedConnecting(c) proto = factory.buildProtocol(addr=None) proto.connectionMade() cfg = config.loadConfig( configFiles=[], reload=True) overrides = kw.setdefault('serviceLocationOverrides', {}) overrides.setdefault('', createClient) conf = config.LDAPConfig(**kw) server = proto(conf) server.protocol = lambda : LDAPClientTestDriver(*responses) server.transport = proto_helpers.StringTransport() server.connectionMade() return server