def test_write_pwd(): with au.tempfile.TemporaryFile() as tmp_f1: with au.tempfile.TemporaryFile() as tmp_f2: pwdb = {"John Doe": ("HASH", "SALT")} au.pickle.dump(pwdb, tmp_f1) tmp_f1.seek(0) au.pickle.dump(pwdb, tmp_f2) tmp_f2.seek(0) assert au.read_pwdb(tmp_f1) == au.read_pwdb(tmp_f2)
def test_add_user(): user = ('evert', 'de man', '6v"&?5UXx-', 10173) with open(pwdb_path, 'wb+') as right_file: auth.add_user(user[0], user[1], user[2], db_dict_right, right_file) assert db_dict_right[user[0]] == (user[3], user[2]), 'Dict is not right in memory' with open(pwdb_path, 'rb+') as right_file: assert auth.read_pwdb(right_file) == db_dict_right
def test_authenticate_user_not_in_database(pwdb_path): username = '******' password = '******' try: pwdb_file = open(pwdb_path, 'rb+') except FileNotFoundError: pwdb_file = open(pwdb_path, 'wb+') pwdb = read_pwdb(pwdb_file) assert not authenticate(username, password, pwdb)
def test_authenticate_wrong_password(pwdb_path): username = '******' password = '******' try: pwdb_file = open(pwdb_path, 'rb+') except FileNotFoundError: pwdb_file = open(pwdb_path, 'wb+') pwdb = read_pwdb(pwdb_file) assert not authenticate(username, password, pwdb)
def test_read_pwdb(pwdb_path): username = '******' salt = 'HwIqH8YdT}' hashed_password = 11215 try: pwdb_file = open(pwdb_path, 'rb+') except FileNotFoundError: pwdb_file = open(pwdb_path, 'wb+') pwdb = read_pwdb(pwdb_file) assert username in pwdb assert pwdb[username][1] == salt assert pwdb[username][0] == hashed_password
def test_add_user(pwdb_path): username = '******' password = '******' try: pwdb_file = open(pwdb_path, 'rb+') except FileNotFoundError: pwdb_file = open(pwdb_path, 'wb+') pwdb = read_pwdb(pwdb_file) TEST_PWDB_FLNAME_COPY = tempfile.gettempdir() / pathlib.Path('test_pwdb_copy.pkl') pwdb_file_copy = open(TEST_PWDB_FLNAME_COPY, 'wb+') # creating a copy of the original test database # so that changes don't affect the original test database add_user(username, password, get_salt(), pwdb, pwdb_file_copy) assert username in pwdb
def test_read_pwdb_file(): with au.tempfile.TemporaryFile() as tmp_f: pwdb = {"John Doe": ("HASH", "SALT")} au.pickle.dump(pwdb, tmp_f) tmp_f.seek(0) assert au.read_pwdb(tmp_f) == pwdb
def test_read_pwdb_no_file(): with au.tempfile.TemporaryFile() as tmp_f: assert au.read_pwdb(tmp_f) == {}
def test_io(): with open(pwdb_path, 'wb+') as right_file: auth.write_pwdb(db_dict_right, right_file) with open(pwdb_path, 'rb+') as right_file: assert auth.read_pwdb(right_file) == db_dict_right
def backup_pwdb(backup_file, pwdb_file): pwdb = auth.read_pwdb(pwdb_file) # do something return True