def setUp(self): ''' This is run before each test. Read configuration from the given JSON file. ''' with open(sys.argv[1], 'r') as f: cfgdata = json.load(f) config = cfgdata['config'] config2 = config.copy() # A config with a differing Map (mapping string user IDs, not numerical user IDs) config2['linotp.sqlresolver.Map'] = cfgdata['config2_map'] # Another config with a where clause (otherwise equals `config`) config3 = config.copy() config3['linotp.sqlresolver.Where'] = cfgdata['config3_where'] self.y = getResolverClass("useridresolver.SQLIdResolver", "IdResolver")() self.y.loadConfig(config, "") self.z = getResolverClass("useridresolver.SQLIdResolver", "IdResolver")() self.z.loadConfig(config2, "") self.w = getResolverClass("useridresolver.SQLIdResolver", "IdResolver")() self.w.loadConfig(config3, "") self.ldap_y = getResolverClass("useridresolver.LDAPIdResolver", "IdResolver")() self.ldap_y.loadConfig({ 'linotp.ldapresolver.LDAPFILTER': '(&(cn=%s))', 'linotp.ldapresolver.LDAPSEARCHFILTER': '(cn=*)', 'linotp.ldapresolver.LOGINNAMEATTRIBUTE': 'cn', 'linotp.ldapresolver.USERINFO': '{"username":"******", "description":"", \ "phone" : "telephoneNumber",\ "groups" : "o",\ "mobile" : "mobile", \ "email" : "email",\ "surname" : "sn",\ "givenname" : "givenName",\ "gender" : "" } ', 'linotp.ldapresolver.LDAPURI': 'ldap://localhost:1389', 'linotp.ldapresolver.LDAPBASE': 'o=linotp,c=org', 'linotp.ldapresolver.BINDDN': '', 'linotp.ldapresolver.BINDPW': '', 'linotp.ldapresolver.TIMEOUT': '5', 'linotp.ldapresolver.SIZELIMIT': '10', })
def setUp(self): self.ldap_y = getResolverClass("useridresolver.LDAPIdResolver", "IdResolver")() self.ldap_y.loadConfig({ 'linotp.ldapresolver.LDAPFILTER': '(&(cn=%s))', 'linotp.ldapresolver.LDAPSEARCHFILTER': '(cn=*)', 'linotp.ldapresolver.LOGINNAMEATTRIBUTE': 'cn', 'linotp.ldapresolver.USERINFO': '{"username":"******", "description":"", \ "phone" : "telephoneNumber",\ "groups" : "o",\ "mobile" : "mobile", \ "email" : "email",\ "surname" : "sn",\ "givenname" : "givenName",\ "gender" : "" } ', 'linotp.ldapresolver.LDAPURI': 'ldap://localhost:1389', 'linotp.ldapresolver.LDAPBASE': 'o=linotp,c=org', 'linotp.ldapresolver.BINDDN': '', 'linotp.ldapresolver.BINDPW': '', 'linotp.ldapresolver.TIMEOUT': '5', 'linotp.ldapresolver.SIZELIMIT': '10', })
def test_resolver(self): ''' Testing PasswdIdResolver ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig( { 'linotp.passwdresolver.fileName': os.path.join(self.fixture_path, 'my-passwd') }, "") userlist = y.getUserList({'username': '******', "userid": "= 1000"}) print userlist assert userlist[0].get('username') == "heinz" loginId = y.getUserId("heinz") print loginId assert loginId == '1000' ret = y.getUserInfo(loginId) print ret assert ret.get('username') == "heinz" username_exists = y.getUsername('1000') print "Username exists: %r" % username_exists assert username_exists
def test_searchfields(self): ''' Testing getSearchfields ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({ 'linotp.passwdresolver.fileName' : 'my-pass2' }, "") s = y.getSearchFields() print s assert s
def test_searchfields(self): ''' Testing getSearchfields ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({'fileName': os.path.join(self.fixture_path, 'my-pass2')}, "") s = y.getSearchFields() self.assertTrue(s, s)
def test_searchfields(self): ''' Testing getSearchfields ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({ 'linotp.passwdresolver.fileName' : os.path.join(self.fixture_path, 'my-pass2') }, "") s = y.getSearchFields() print s assert s
def test_searchfields(self): """ Testing getSearchfields """ y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({"linotp.passwdresolver.fileName": os.path.join(self.fixture_path, "my-pass2")}, "") s = y.getSearchFields() print s assert s
def setUp(self): ''' This is run before each test. Read configuration from the given JSON file. ''' with open(sys.argv[1], 'r') as f: cfgdata = json.load(f) config = cfgdata['config'] config2 = config.copy() # A config with a differing Map (mapping string user IDs, not numerical user IDs) config2['linotp.sqlresolver.Map'] = cfgdata['config2_map'] # Another config with a where clause (otherwise equals `config`) config3 = config.copy() config3['linotp.sqlresolver.Where'] = cfgdata['config3_where'] self.y = getResolverClass("useridresolver.SQLIdResolver", "IdResolver")() self.y.loadConfig(config, "") self.z = getResolverClass("useridresolver.SQLIdResolver", "IdResolver")() self.z.loadConfig(config2, "") self.w = getResolverClass("useridresolver.SQLIdResolver", "IdResolver")() self.w.loadConfig(config3, "") self.ldap_y = getResolverClass("useridresolver.LDAPIdResolver", "IdResolver")() self.ldap_y.loadConfig({ 'linotp.ldapresolver.LDAPFILTER' : '(&(cn=%s))', 'linotp.ldapresolver.LDAPSEARCHFILTER' : '(cn=*)', 'linotp.ldapresolver.LOGINNAMEATTRIBUTE' : 'cn', 'linotp.ldapresolver.USERINFO' : '{"username":"******", "description":"", \ "phone" : "telephoneNumber",\ "groups" : "o",\ "mobile" : "mobile", \ "email" : "email",\ "surname" : "sn",\ "givenname" : "givenName",\ "gender" : "" } ', 'linotp.ldapresolver.LDAPURI' : 'ldap://localhost:1389', 'linotp.ldapresolver.LDAPBASE' : 'o=linotp,c=org', 'linotp.ldapresolver.BINDDN' : '', 'linotp.ldapresolver.BINDPW' : '', 'linotp.ldapresolver.TIMEOUT' : '5', 'linotp.ldapresolver.SIZELIMIT' : '10', })
def setUp(self): ''' This is run before each test. Read configuration from the given JSON file. ''' with open(sys.argv[1], 'r') as f: cfgdata = json.load(f) config = cfgdata['config'] config2 = config.copy() # A config with a differing Map (mapping string user IDs, not numerical user IDs) config2['linotp.sqlresolver.Map'] = cfgdata['config2_map'] # Another config with a where clause (otherwise equals `config`) config3 = config.copy() config3['linotp.sqlresolver.Where'] = cfgdata['config3_where'] self.y = getResolverClass("useridresolver.SQLIdResolver", "IdResolver")() self.y.loadConfig(config, "") self.z = getResolverClass("useridresolver.SQLIdResolver", "IdResolver")() self.z.loadConfig(config2, "") self.w = getResolverClass("useridresolver.SQLIdResolver", "IdResolver")() self.w.loadConfig(config3, "")
def test_checkpass(self): ''' Testing checkpass ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({ 'linotp.passwdresolver.fileName' : os.path.join(self.fixture_path, 'my-pass2') }, "") res = y.checkPass('2001', "geheim") print "result %r" % res assert res res = y.checkPass('2001', "wrongPW") print "result %r" % res assert res is False
def test_checkpass_shadow(self): """ Testing checkpass with PasswdIdResolver with a shadow passwd file """ y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({"linotp.passwdresolver.fileName": os.path.join(self.fixture_path, "my-passwd")}, "") success = False try: y.checkPass("1000", "geheim") except NotImplementedError: success = True assert success
def test_checkpass(self): ''' Testing checkpass ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({ 'linotp.passwdresolver.fileName' : 'my-pass2' }, "") res = y.checkPass('2001', "geheim") print "result %r" % res assert res res = y.checkPass('2001', "wrongPW") print "result %r" % res assert res == False
def test_checkpass(self): """ Testing checkpass """ y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({"linotp.passwdresolver.fileName": os.path.join(self.fixture_path, "my-pass2")}, "") res = y.checkPass("2001", "geheim") print "result %r" % res assert res res = y.checkPass("2001", "wrongPW") print "result %r" % res assert res == False
def test_checkpass_shadow(self): ''' Testing checkpass with PasswdIdResolver with a shadow passwd file ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({ 'linotp.passwdresolver.fileName' : 'my-passwd' }, "") success = False try: y.checkPass('1000', "geheim") except NotImplementedError: success = True assert success
def test_checkpass_shadow(self): ''' Testing checkpass with PasswdIdResolver with a shadow passwd file ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig( {'fileName': os.path.join(self.fixture_path, 'my-passwd')}, "") success = False try: y.checkPass('1000', "geheim") except NotImplementedError: success = True self.assertTrue(success)
def test_no_file(self): ''' Testing PasswdIdResolver without file ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadFile() userlist = y.getUserList({'username': '******', "userid": "= 0"}) self.assertTrue(userlist[0].get('username') == "root", userlist) loginId = y.getUserId("root") self.assertTrue(loginId == '0', loginId) ret = y.getUserInfo(loginId) self.assertTrue(ret.get('username') == "root", ret)
def test_checkpass(self): ''' Testing checkpass ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({'fileName': os.path.join(self.fixture_path, 'my-pass2')}, "") res = y.checkPass('2001', "geheim") msg = "result %r" % res self.assertTrue(res, msg) res = y.checkPass('2001', "wrongPW") msg = "result %r" % res self.assertTrue(res is False, msg)
def test_no_file(self): ''' Testing PasswdIdResolver without file ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadFile() userlist = y.getUserList({'username': '******', "userid": "= 0"}) print userlist assert userlist[0].get('username') == "root" loginId = y.getUserId("root") print loginId assert loginId == '0' ret = y.getUserInfo(loginId) print ret assert ret.get('username') == "root"
def test_no_file(self): """ Testing PasswdIdResolver without file """ y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadFile() userlist = y.getUserList({"username": "******", "userid": "= 0"}) print userlist assert userlist[0].get("username") == "root" loginId = y.getUserId("root") print loginId assert loginId == "0" ret = y.getUserInfo(loginId) print ret assert ret.get("username") == "root"
def test_no_file(self): ''' Testing PasswdIdResolver without file ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadFile() userlist = y.getUserList({'username':'******', "userid":"= 0"}) print userlist assert userlist[0].get('username') == "root" loginId = y.getUserId("root") print loginId assert loginId == '0' ret = y.getUserInfo(loginId) print ret assert ret.get('username') == "root"
def test_resolver(self): ''' Testing PasswdIdResolver ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig( {'fileName': os.path.join(self.fixture_path, 'my-passwd')}, "") userlist = y.getUserList({'username': '******', "userid": "= 1000"}) self.assertTrue(userlist[0].get('username') == "heinz", userlist) loginId = y.getUserId("heinz") self.assertTrue(loginId == '1000', loginId) ret = y.getUserInfo(loginId) self.assertTrue(ret.get('username') == "heinz", ret) username_exists = y.getUsername('1000') msg = "Username exists: %r" % username_exists self.assertTrue(username_exists, msg)
def test_resolver(self): """ Testing PasswdIdResolver """ y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({"linotp.passwdresolver.fileName": os.path.join(self.fixture_path, "my-passwd")}, "") userlist = y.getUserList({"username": "******", "userid": "= 1000"}) print userlist assert userlist[0].get("username") == "heinz" loginId = y.getUserId("heinz") print loginId assert loginId == "1000" ret = y.getUserInfo(loginId) print ret assert ret.get("username") == "heinz" username_exists = y.getUsername("1000") print "Username exists: %r" % username_exists assert username_exists
def test_resolver(self): ''' Testing PasswdIdResolver ''' y = getResolverClass("PasswdIdResolver", "IdResolver")() y.loadConfig({ 'linotp.passwdresolver.fileName' : os.path.join(self.fixture_path, 'my-passwd') }, "") userlist = y.getUserList({'username':'******', "userid":"= 1000"}) print userlist assert userlist[0].get('username') == "heinz" loginId = y.getUserId("heinz") print loginId assert loginId == '1000' ret = y.getUserInfo(loginId) print ret assert ret.get('username') == "heinz" username_exists = y.getUsername('1000') print "Username exists: %r" % username_exists assert username_exists
log.error("[getUserList] error during LDAP access: %r" % exce) log.error("[getUserList] %s" % traceback.format_exc()) self.unbind(l_obj) if resultList: return resultList return "" if __name__ == "__main__": print "LDAPIdResolver - IdResolver class test " DEFAULT_UID_TYPE = "entryUUID" y_res = getResolverClass("LDAPIdResolver", "IdResolver")() y_res.loadConfig({ 'linotp.ldapresolver.LDAPFILTER': '(&(uid=%s)(ObjectClass=inetOrgPerson))', # CKO: need this for getUsername aka loginname 'linotp.ldapresolver.LDAPSEARCHFILTER': '(uid=*)(ObjectClass=inetOrgperson)', # this is the base search pattern for userlist 'linotp.ldapresolver.LOGINNAMEATTRIBUTE': 'uid', #CKO: need this for getUserInfo 'linotp.ldapresolver.USERINFO': ( '{"username": "******", "description": "", "phone": "telephoneNumber",' ' "groups": "o", "mobile": "mobile", "email": "email",' ' "surname": "sn", "givenname": "givenName", "gender" : "" }'), 'linotp.ldapresolver.LDAPURI': 'ldap://localhost',
log.error("[getUserList] %s" % traceback.format_exc()) self.unbind(l_obj) if resultList: return resultList return "" if __name__ == "__main__": print "LDAPIdResolver - IdResolver class test " DEFAULT_UID_TYPE = "entryUUID" y_res = getResolverClass("LDAPIdResolver", "IdResolver")() y_res.loadConfig({ 'linotp.ldapresolver.LDAPFILTER': '(&(uid=%s)(ObjectClass=inetOrgPerson))', # CKO: need this for getUsername aka loginname 'linotp.ldapresolver.LDAPSEARCHFILTER': '(uid=*)(ObjectClass=inetOrgperson)', # this is the base search pattern for userlist 'linotp.ldapresolver.LOGINNAMEATTRIBUTE': 'uid', # CKO: need this for getUserInfo 'linotp.ldapresolver.USERINFO': ('{"username": "******", "description": "", "phone": "telephoneNumber",' ' "groups": "o", "mobile": "mobile", "email": "email",' ' "surname": "sn", "givenname": "givenName", "gender" : "" }'),