def test_update_with_user_new_user_existing_team(mock_load_db, mock_json): update_with_user("ONETEAM", "newuser", "NEWUSERNAME", "NEWPASSWORD") new_logins = copy.deepcopy(MOCK_LOGINS) new_logins["ONETEAM"]["newuser"] = {"username": "******", "password": base64.encodestring(encrypt("NEWPASSWORD")).decode('utf-8')} mock_json.assert_called_once_with(new_logins, ANY)
def add_user(team, slack_user, username, pw): logins = load_db() if team not in logins: logins[team] = {} logins[team][slack_user]['username'] = username logins[team][slack_user]['password'] = base64.encodestring(encrypt(pw)) with open(LOGIN_DB, 'w') as fp: json.dump(logins, fp)
def update_with_user(self, team, slack_user, username, pw): logins = self.load_db() if team not in logins: logins[team] = {} if slack_user not in logins[team]: logins[team][slack_user] = {} logins[team][slack_user]['username'] = username pw = base64.encodestring(encrypt(pw)).decode('utf-8') logins[team][slack_user]['password'] = pw with open(LOGIN_DB, 'w') as fp: json.dump(logins, fp)
def test_update_with_user_new_user_new_team(mock_json): account_manager.update_with_user("NEWTEAM", "newuser", "NEWUSERNAME", "NEWPASSWORD") new_logins = copy.deepcopy(MOCK_LOGINS) new_logins["NEWTEAM"] = { "newuser": { "username": "******", "password": base64.encodestring(encrypt("NEWPASSWORD")).decode('utf-8') } } mock_json.assert_called_once_with(new_logins, ANY)
def test_incorrect_pw(): test_pw = "password" for s in test_strings: assert decrypt(encrypt(s, p=test_pw), p="wrong pw") != s
def test_encrypt(): test_pw = "password" for s in test_strings: assert decrypt(encrypt(s, p=test_pw), p=test_pw) == s