diff --git a/monkey/monkey_island/cc/environment/user_creds.py b/monkey/monkey_island/cc/environment/user_creds.py index a86472cd9..f1989a6a4 100644 --- a/monkey/monkey_island/cc/environment/user_creds.py +++ b/monkey/monkey_island/cc/environment/user_creds.py @@ -8,7 +8,7 @@ from monkey_island.cc.resources.auth.auth_user import User class UserCreds: - def __init__(self, username="", password_hash=""): + def __init__(self, username, password_hash): self.username = username self.password_hash = password_hash diff --git a/monkey/tests/monkey_island/cc/environment/test_environment.py b/monkey/tests/monkey_island/cc/environment/test_environment.py index 0c98d1ccf..8d4c4147e 100644 --- a/monkey/tests/monkey_island/cc/environment/test_environment.py +++ b/monkey/tests/monkey_island/cc/environment/test_environment.py @@ -20,6 +20,8 @@ PARTIAL_CREDENTIALS = None STANDARD_WITH_CREDENTIALS = None STANDARD_ENV = None +EMPTY_CREDS = UserCreds("", "") + # This fixture is a dirty hack that can be removed once these tests are converted from # unittest to pytest. Instead, the appropriate fixtures from conftest.py can be used. @@ -67,7 +69,7 @@ def get_server_config_file_path_test_version(): class TestEnvironment(TestCase): class EnvironmentCredentialsNotRequired(Environment): def __init__(self): - config = StubEnvironmentConfig("test", "test", UserCreds()) + config = StubEnvironmentConfig("test", "test", EMPTY_CREDS) super().__init__(config) _credentials_required = False @@ -77,7 +79,7 @@ class TestEnvironment(TestCase): class EnvironmentCredentialsRequired(Environment): def __init__(self): - config = StubEnvironmentConfig("test", "test", UserCreds()) + config = StubEnvironmentConfig("test", "test", EMPTY_CREDS) super().__init__(config) _credentials_required = True @@ -101,7 +103,7 @@ class TestEnvironment(TestCase): credentials = UserCreds(username="test", password_hash="1231234") env.try_add_user(credentials) - credentials = UserCreds(username="test") + credentials = UserCreds(username="test", password_hash="") with self.assertRaises(InvalidRegistrationCredentialsError): env.try_add_user(credentials) 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 359bc3741..87286fc60 100644 --- a/monkey/tests/monkey_island/cc/environment/test_user_creds.py +++ b/monkey/tests/monkey_island/cc/environment/test_user_creds.py @@ -6,7 +6,7 @@ TEST_SALT = b"$2b$12$JA7GdT1iyfIsquF2cTZv2." def test_to_dict_empty_creds(): - user_creds = UserCreds() + user_creds = UserCreds("", "") assert user_creds.to_dict() == {} @@ -23,14 +23,6 @@ def test_to_auth_user_full_credentials(): assert auth_user.secret == "abc1231234" -def test_to_auth_user_username_only(): - user_creds = UserCreds(username="Test") - auth_user = user_creds.to_auth_user() - assert auth_user.id == 1 - assert auth_user.username == "Test" - assert auth_user.secret == "" - - def test_get_from_cleartext(monkeypatch): monkeypatch.setattr(bcrypt, "gensalt", lambda: TEST_SALT)