island: Add constants for user and hash to UserCreds tests

This commit is contained in:
Mike Salvatore 2021-05-04 17:20:03 -04:00
parent c4c0b7217d
commit e4dec5501e
1 changed files with 14 additions and 12 deletions

View File

@ -2,19 +2,21 @@ import bcrypt
from monkey_island.cc.environment.user_creds import UserCreds
TEST_USER = "Test"
TEST_HASH = "abc1231234"
TEST_SALT = b"$2b$12$JA7GdT1iyfIsquF2cTZv2."
def test_bool_true():
assert UserCreds("Test", "abc1231234")
assert UserCreds(TEST_USER, TEST_HASH)
def test_bool_false_empty_password_hash():
assert not UserCreds("Test", "")
assert not UserCreds(TEST_USER, "")
def test_bool_false_empty_user():
assert not UserCreds("", "abc1231234")
assert not UserCreds("", TEST_HASH)
def test_bool_false_empty_user_and_password_hash():
@ -27,28 +29,28 @@ def test_to_dict_empty_creds():
def test_to_dict_full_creds():
user_creds = UserCreds(username="Test", password_hash="abc1231234")
assert user_creds.to_dict() == {"user": "Test", "password_hash": "abc1231234"}
user_creds = UserCreds(username=TEST_USER, password_hash=TEST_HASH)
assert user_creds.to_dict() == {"user": TEST_USER, "password_hash": TEST_HASH}
def test_to_auth_user_full_credentials():
user_creds = UserCreds(username="Test", password_hash="abc1231234")
user_creds = UserCreds(username=TEST_USER, password_hash=TEST_HASH)
auth_user = user_creds.to_auth_user()
assert auth_user.id == 1
assert auth_user.username == "Test"
assert auth_user.secret == "abc1231234"
assert auth_user.username == TEST_USER
assert auth_user.secret == TEST_HASH
def test_get_from_cleartext(monkeypatch):
monkeypatch.setattr(bcrypt, "gensalt", lambda: TEST_SALT)
creds = UserCreds.from_cleartext("Test", "Test_Password")
creds = UserCreds.from_cleartext(TEST_USER, "Test_Password")
assert creds.password_hash == "$2b$12$JA7GdT1iyfIsquF2cTZv2.NdGFuYbX1WGfQAOyHlpEsgDTNGZ0TXG"
def test_member_values(monkeypatch):
monkeypatch.setattr(bcrypt, "gensalt", lambda: TEST_SALT)
creds = UserCreds("Test", "abc1231234")
assert creds.username == "Test"
assert creds.password_hash == "abc1231234"
creds = UserCreds(TEST_USER, TEST_HASH)
assert creds.username == TEST_USER
assert creds.password_hash == TEST_HASH