Skip to content

Commit

Permalink
island: Add FULL_USER_CREDENTIALS to test_environment.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mssalvatore committed May 5, 2021
1 parent 4bfc388 commit d86e8e8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions monkey/tests/monkey_island/cc/environment/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
STANDARD_WITH_CREDENTIALS = None
STANDARD_ENV = None

EMPTY_CREDS = UserCreds("", "")
EMPTY_USER_CREDENTIALS = UserCreds("", "")
FULL_USER_CREDENTIALS = UserCreds(username="test", password_hash="1231234")


# This fixture is a dirty hack that can be removed once these tests are converted from
Expand Down Expand Up @@ -69,7 +70,7 @@ def get_server_config_file_path_test_version():
class TestEnvironment(TestCase):
class EnvironmentCredentialsNotRequired(Environment):
def __init__(self):
config = StubEnvironmentConfig("test", "test", EMPTY_CREDS)
config = StubEnvironmentConfig("test", "test", EMPTY_USER_CREDENTIALS)
super().__init__(config)

_credentials_required = False
Expand All @@ -79,7 +80,7 @@ def get_auth_users(self):

class EnvironmentCredentialsRequired(Environment):
def __init__(self):
config = StubEnvironmentConfig("test", "test", EMPTY_CREDS)
config = StubEnvironmentConfig("test", "test", EMPTY_USER_CREDENTIALS)
super().__init__(config)

_credentials_required = True
Expand All @@ -100,15 +101,15 @@ def get_auth_users(self):
@patch.object(target=EnvironmentConfig, attribute="save_to_file", new=MagicMock())
def test_try_add_user(self):
env = TestEnvironment.EnvironmentCredentialsRequired()
credentials = UserCreds(username="test", password_hash="1231234")
credentials = FULL_USER_CREDENTIALS
env.try_add_user(credentials)

credentials = UserCreds(username="test", password_hash="")
with self.assertRaises(InvalidRegistrationCredentialsError):
env.try_add_user(credentials)

env = TestEnvironment.EnvironmentCredentialsNotRequired()
credentials = UserCreds(username="test", password_hash="1231234")
credentials = FULL_USER_CREDENTIALS
with self.assertRaises(RegistrationNotNeededError):
env.try_add_user(credentials)

Expand Down

0 comments on commit d86e8e8

Please sign in to comment.