forked from p15670423/monkey
island: Simplify UserCreds constructor by removing defaults
The default values were only really used by the test code. We can simplify the Usercreds's interface and test code by removing functionality (read: complication) we don't really need.
This commit is contained in:
parent
1aed5f37d1
commit
d56cb5cd75
|
@ -8,7 +8,7 @@ from monkey_island.cc.resources.auth.auth_user import User
|
||||||
|
|
||||||
|
|
||||||
class UserCreds:
|
class UserCreds:
|
||||||
def __init__(self, username="", password_hash=""):
|
def __init__(self, username, password_hash):
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password_hash = password_hash
|
self.password_hash = password_hash
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ PARTIAL_CREDENTIALS = None
|
||||||
STANDARD_WITH_CREDENTIALS = None
|
STANDARD_WITH_CREDENTIALS = None
|
||||||
STANDARD_ENV = None
|
STANDARD_ENV = None
|
||||||
|
|
||||||
|
EMPTY_CREDS = UserCreds("", "")
|
||||||
|
|
||||||
|
|
||||||
# This fixture is a dirty hack that can be removed once these tests are converted from
|
# 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.
|
# 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 TestEnvironment(TestCase):
|
||||||
class EnvironmentCredentialsNotRequired(Environment):
|
class EnvironmentCredentialsNotRequired(Environment):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
config = StubEnvironmentConfig("test", "test", UserCreds())
|
config = StubEnvironmentConfig("test", "test", EMPTY_CREDS)
|
||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
|
|
||||||
_credentials_required = False
|
_credentials_required = False
|
||||||
|
@ -77,7 +79,7 @@ class TestEnvironment(TestCase):
|
||||||
|
|
||||||
class EnvironmentCredentialsRequired(Environment):
|
class EnvironmentCredentialsRequired(Environment):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
config = StubEnvironmentConfig("test", "test", UserCreds())
|
config = StubEnvironmentConfig("test", "test", EMPTY_CREDS)
|
||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
|
|
||||||
_credentials_required = True
|
_credentials_required = True
|
||||||
|
@ -101,7 +103,7 @@ class TestEnvironment(TestCase):
|
||||||
credentials = UserCreds(username="test", password_hash="1231234")
|
credentials = UserCreds(username="test", password_hash="1231234")
|
||||||
env.try_add_user(credentials)
|
env.try_add_user(credentials)
|
||||||
|
|
||||||
credentials = UserCreds(username="test")
|
credentials = UserCreds(username="test", password_hash="")
|
||||||
with self.assertRaises(InvalidRegistrationCredentialsError):
|
with self.assertRaises(InvalidRegistrationCredentialsError):
|
||||||
env.try_add_user(credentials)
|
env.try_add_user(credentials)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ TEST_SALT = b"$2b$12$JA7GdT1iyfIsquF2cTZv2."
|
||||||
|
|
||||||
|
|
||||||
def test_to_dict_empty_creds():
|
def test_to_dict_empty_creds():
|
||||||
user_creds = UserCreds()
|
user_creds = UserCreds("", "")
|
||||||
assert user_creds.to_dict() == {}
|
assert user_creds.to_dict() == {}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,14 +23,6 @@ def test_to_auth_user_full_credentials():
|
||||||
assert auth_user.secret == "abc1231234"
|
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):
|
def test_get_from_cleartext(monkeypatch):
|
||||||
monkeypatch.setattr(bcrypt, "gensalt", lambda: TEST_SALT)
|
monkeypatch.setattr(bcrypt, "gensalt", lambda: TEST_SALT)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue