forked from p15670423/monkey
Island: Rename get_users() -> get_user()
This function only ever returns one user. The plural name "get_users()" is misleading. Returning a list is also misleading.
This commit is contained in:
parent
a5d3c218b4
commit
bb806522a1
|
@ -12,6 +12,6 @@ class AwsEnvironment(Environment):
|
|||
|
||||
def get_auth_users(self):
|
||||
if self._is_registered():
|
||||
return self._config.get_users()
|
||||
return [self._config.get_user()]
|
||||
else:
|
||||
return []
|
||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import json
|
||||
import os
|
||||
from typing import Dict, List
|
||||
from typing import Dict
|
||||
|
||||
from monkey_island.cc.environment.user_creds import UserCreds
|
||||
from monkey_island.cc.resources.auth.auth_user import User
|
||||
|
@ -58,11 +58,11 @@ class EnvironmentConfig:
|
|||
def add_user(self, credentials: UserCreds):
|
||||
self.user_creds = credentials
|
||||
self.save_to_file()
|
||||
UserStore.set_users(self.get_users())
|
||||
UserStore.set_users([self.get_user()])
|
||||
|
||||
def get_users(self) -> List[User]:
|
||||
def get_user(self) -> User:
|
||||
auth_user = self.user_creds.to_auth_user()
|
||||
return [auth_user] if auth_user else []
|
||||
return auth_user if auth_user else None
|
||||
|
||||
|
||||
def _get_user_credentials_from_config(dict_data: Dict):
|
||||
|
|
|
@ -6,6 +6,6 @@ class PasswordEnvironment(Environment):
|
|||
|
||||
def get_auth_users(self):
|
||||
if self._is_registered():
|
||||
return self._config.get_users()
|
||||
return [self._config.get_user()]
|
||||
else:
|
||||
return []
|
||||
|
|
|
@ -82,11 +82,10 @@ def test_add_user(config_file, with_credentials):
|
|||
assert from_file["environment"]["password_hash"] == new_password_hash
|
||||
|
||||
|
||||
def test_get_users(with_credentials):
|
||||
def test_get_user(with_credentials):
|
||||
environment_config = EnvironmentConfig(with_credentials)
|
||||
users = environment_config.get_users()
|
||||
user = environment_config.get_user()
|
||||
|
||||
assert len(users) == 1
|
||||
assert users[0].id == 1
|
||||
assert users[0].username == "test"
|
||||
assert users[0].secret == "abcdef"
|
||||
assert user.id == 1
|
||||
assert user.username == "test"
|
||||
assert user.secret == "abcdef"
|
||||
|
|
Loading…
Reference in New Issue