def test_wrong_name_wrong_password(): salt = auth.get_salt() password = '******' pwdb = {'real_name': (auth.pwhash(password, salt), salt)} username = '******' pass_text = 'wrong_password' assert not auth.authenticate(username, pass_text, pwdb)
def test_authenticate_valid(): salt = "SALT" hash_ = au.pwhash("password", salt) res = au.authenticate("John Doe", "password", {"John Doe": [hash_, salt]}) assert res
def test_authenticate_wrong_pass(): salt = "SALT" hash_ = au.pwhash("qwerty", salt) res = au.authenticate("John Doe", "1234", {"John Doe": [hash_, salt]}) assert not res
def test_user_not_exists(): username = '******' password = '******' salt = auth.get_salt() pwdb = {'old_name': (auth.pwhash('old_password', salt), salt)} pwdb_path = tempfile.gettempdir() / PWDB_FLNAME with open(pwdb_path, 'wb+') as pwdb_file: pickle.dump(pwdb, pwdb_file) salt = auth.get_salt() try: with open(pwdb_path, 'wb+') as pwdb_file: auth.add_user(username, password, salt, pwdb, pwdb_file) with open(pwdb_path, 'rb+') as pwdb_file: pwdb = pickle.load(pwdb_file) print(pwdb) assert pwdb[username] == (auth.pwhash(password, salt), salt) except: assert False
def pwdb_path(): USERNAME = "******" PASSWORD = "******" SALT = 'HwIqH8YdT}' pwdb = {} pwdb[USERNAME] = (pwhash(PASSWORD,SALT), SALT) FILEPATH = tempfile.gettempdir() / pathlib.Path('test_pwdb.pkl') with open(FILEPATH, 'wb+') as pwdbfile: write_pwdb(pwdb, pwdbfile) return(FILEPATH)
def test_user_already_exists(): username = '******' password = '******' salt = auth.get_salt() pwdb = {'old_name': (auth.pwhash('old_password', salt), salt)} pwdb_path = tempfile.gettempdir() / PWDB_FLNAME pwdb_file = open(pwdb_path, 'wb') pickle.dump(pwdb, pwdb_file) salt = auth.get_salt() try: auth.add_user(username, password, salt, pwdb, pwdb_file) assert False except Exception as _: assert True
def test_empty_username(): username = '' password = '******' salt = auth.get_salt() pwdb = {'old_name': (auth.pwhash('old_password', salt), salt)} pwdb_path = tempfile.gettempdir() / PWDB_FLNAME with open(pwdb_path, 'wb+') as pwdb_file: pickle.dump(pwdb, pwdb_file) salt = auth.get_salt() try: with open(pwdb_path, 'wb+') as pwdb_file: auth.add_user(username, password, salt, pwdb, pwdb_file) assert False except auth.UsernameError as _: assert True
def test_add_user_new_user(): pwdb = {} with au.tempfile.TemporaryFile() as tmp_f: au.add_user("John Doe", "password", "SALT", pwdb, tmp_f) assert pwdb == {"John Doe": (au.pwhash("password", "SALT"), "SALT")}
def test_pwhash(): for user in db_right: assert auth.pwhash(user[1], user[2]) == user[3] for user in db_wrong: assert auth.pwhash(user[1], user[2]) != user[3]
def test_pwhash(): password = '******' salt = 'HwIqH8YdT}' hashed_password = 11215 assert pwhash(password, salt) == hashed_password