예제 #1
0
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)
예제 #2
0
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
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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
예제 #8
0
def test_read_pwdb_no_file():
    with au.tempfile.TemporaryFile() as tmp_f:
        assert au.read_pwdb(tmp_f) == {}
예제 #9
0
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
예제 #10
0
def backup_pwdb(backup_file, pwdb_file):
    pwdb = auth.read_pwdb(pwdb_file)
    # do something
    return True