Пример #1
0
 def userActive(self, username):
     ret = None
     msg = "User not found in Cognito DB: /{}\\".format(username)
     # TODO
     # usernames in secadmin cognito idp now appear to be of the form
     # [email protected]
     # .co.uk is lowercase
     # this may change back to 'user.name' eventually
     # hence uncomment this next line and comment the following one.
     un = username
     # un = "bgch_{}@BGCHNET.co.uk".format(username.title())
     poolid = self.params["poolid"]
     cc = CognitoClient()
     userinfo = cc.adminGetUser(poolid, un)
     log.debug("getuser returned: {}".format(userinfo))
     if isinstance(userinfo, dict):
         if "Enabled" in userinfo:
             log.debug("CC: userinfo: {}".format(userinfo))
             ret = userinfo["Enabled"]
         else:
             msg = "User not Enabled in Cognito DB: "
             msg += "{} ({})".format(username, un)
             raise DataNotFound(msg)
     else:
         raise DataNotFound(msg)
     return ret
Пример #2
0
def test_correct_pool_list():
    ret = False
    cc = CognitoClient()
    pools = cc.listPools()
    for pool in pools:
        if pool["Id"] == chaimpoolid:
            ret = True
    assert ret is True
Пример #3
0
def test_find_user():
    cc = CognitoClient()
    users = cc.listUsers(chaimpoolid)
    found = False
    for user in users:
        if user["Username"] == chaimuserfind:
            found = True
            break
    assert found is True
Пример #4
0
 def findCognitoUser(self, username):
     ret = None
     msg = "User not found in Cognito DB: {}".format(username)
     cc = CognitoClient()
     userinfo = cc.findUserByEmail(self.params["poolid"], username)
     if isinstance(userinfo, dict):
         if "Enabled" in userinfo:
             log.debug("CC: userinfo: {}".format(userinfo))
             ret = userinfo["Enabled"]
         else:
             msg = "User not Enabled in Cognito DB: "
             msg += "{}".format(username)
             raise DataNotFound(msg)
     else:
         raise DataNotFound(msg)
     return ret
Пример #5
0
 def createNewUser(self, slackname, slackid, workspaceid, email):
     try:
         ut = Utils()
         if not ut.checkIsEmailAddress(email):
             raise InvalidEmailAddress(
                 "invalid email address: {}".format(email))
         cid = None
         if " " in slackname:
             raise IncorrectCredentials(
                 "Invalid chaim name: {}".format(slackname))
         if self.rwsid is None:
             raise DBNotConnected("no connection to db for createNewUser")
         chaimuserid = self.checkIDs("awsusers", "name", "User", slackname,
                                     True)
         if chaimuserid is not None:
             if self.checkSlackMap(chaimuserid, slackid, workspaceid):
                 raise ChaimUserExists(
                     "Chaim user already exists: {}".format(slackname))
             else:
                 cid = chaimuserid
         else:
             cid = self.createUser(slackname)
         if cid is not None:
             cc = CognitoClient()
             if cc.adminCreateUser(self.params["poolid"], slackname, email):
                 sql = self.slackMapInsert(cid, slackid, workspaceid)
                 naf = self.rwsid.insertQuery(sql)
                 if naf == 1:
                     return True
         return False
     except Exception as e:
         log.warning(
             "Failed to create new user {}, Exception {}: {}".format(
                 slackname,
                 type(e).__name__, e))
         raise
Пример #6
0
def test_find_by_email_name():
    cc = CognitoClient()
    user = cc.findUserByEmail(chaimpoolid, chaimuserfind)
    assert user["Username"] == chaimuserfind
Пример #7
0
def test_admin_get_user():
    cc = CognitoClient()
    user = cc.adminGetUser(chaimpoolid, chaimuserfind)
    assert user["Username"] == chaimuserfind
Пример #8
0
def test_has_min_num_users():
    cc = CognitoClient()
    users = cc.listUsers(chaimpoolid)
    cn = len(users)
    assert cn >= chaimminnumusers
Пример #9
0
def test_pool_list():
    cc = CognitoClient()
    pools = cc.listPools()
    pool = pools[0]
    assert "Id" in pool
Пример #10
0
def test_has_pools_with_profile():
    cc = CognitoClient(profile="sadmin")
    pools = cc.listPools()
    cn = len(pools)
    assert cn > 0
Пример #11
0
def test_has_pools():
    cc = CognitoClient()
    pools = cc.listPools()
    cn = len(pools)
    assert cn > 0
Пример #12
0
def test_nocreds():
    with pytest.raises(NoCreds):
        CognitoClient(defaultsession=False)