From e4dec5501ec64b119fc84513a84cfc2ca903b7f5 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 4 May 2021 17:20:03 -0400 Subject: [PATCH] island: Add constants for user and hash to UserCreds tests --- .../cc/environment/test_user_creds.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/monkey/tests/monkey_island/cc/environment/test_user_creds.py b/monkey/tests/monkey_island/cc/environment/test_user_creds.py index 0ea6a6464..3d1f2ea34 100644 --- a/monkey/tests/monkey_island/cc/environment/test_user_creds.py +++ b/monkey/tests/monkey_island/cc/environment/test_user_creds.py @@ -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