#2769: added changes which should align with 2735 once merged
This commit is contained in:
@@ -1077,9 +1077,9 @@ class NodeAccountsChangePasswordAction(AbstractAction):
|
||||
def __init__(self, manager: "ActionManager", **kwargs) -> None:
|
||||
super().__init__(manager=manager)
|
||||
|
||||
def form_request(self, node_id: str) -> RequestFormat:
|
||||
def form_request(self, node_id: str, username: str, current_password: str, new_password: str) -> RequestFormat:
|
||||
"""Return the action formatted as a request which can be ingested by the PrimAITE simulation."""
|
||||
return ["network", "node", node_id, "change_password"]
|
||||
return ["network", "node", node_id, "accounts", "change_password", username, current_password, new_password]
|
||||
|
||||
|
||||
class NodeSessionsRemoteLoginAction(AbstractAction):
|
||||
@@ -1088,9 +1088,9 @@ class NodeSessionsRemoteLoginAction(AbstractAction):
|
||||
def __init__(self, manager: "ActionManager", **kwargs) -> None:
|
||||
super().__init__(manager=manager)
|
||||
|
||||
def form_request(self, node_id: str) -> RequestFormat:
|
||||
def form_request(self, node_id: str, username: str, password: str) -> RequestFormat:
|
||||
"""Return the action formatted as a request which can be ingested by the PrimAITE simulation."""
|
||||
return ["network", "node", node_id, "remote_logon"]
|
||||
return ["network", "node", node_id, "sessions", "remote_login", username, password]
|
||||
|
||||
|
||||
class NodeSessionsRemoteLogoutAction(AbstractAction):
|
||||
@@ -1099,9 +1099,9 @@ class NodeSessionsRemoteLogoutAction(AbstractAction):
|
||||
def __init__(self, manager: "ActionManager", **kwargs) -> None:
|
||||
super().__init__(manager=manager)
|
||||
|
||||
def form_request(self, node_id: str) -> RequestFormat:
|
||||
def form_request(self, node_id: str, remote_session_id: str) -> RequestFormat:
|
||||
"""Return the action formatted as a request which can be ingested by the PrimAITE simulation."""
|
||||
return ["network", "node", node_id, "remote_logoff"]
|
||||
return ["network", "node", node_id, "sessions", "remote_logout", remote_session_id]
|
||||
|
||||
|
||||
class ActionManager:
|
||||
|
||||
@@ -1071,18 +1071,6 @@ class Node(SimComponent):
|
||||
rm.add_request(
|
||||
"logoff", RequestType(func=lambda request, context: RequestResponse.from_bool(False), validator=_node_is_on)
|
||||
) # TODO implement logoff request
|
||||
rm.add_request(
|
||||
"change_password",
|
||||
RequestType(func=lambda request, context: RequestResponse.from_bool(False), validator=_node_is_on),
|
||||
) # TODO implement change_password request
|
||||
rm.add_request(
|
||||
"remote_logon",
|
||||
RequestType(func=lambda request, context: RequestResponse.from_bool(False), validator=_node_is_on),
|
||||
) # TODO implement remote_logon request
|
||||
rm.add_request(
|
||||
"remote_logoff",
|
||||
RequestType(func=lambda request, context: RequestResponse.from_bool(False), validator=_node_is_on),
|
||||
) # TODO implement remote_logoff request
|
||||
|
||||
self._os_request_manager = RequestManager()
|
||||
self._os_request_manager.add_request(
|
||||
|
||||
@@ -1,38 +1,49 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
|
||||
|
||||
def test_remote_logon(game_and_agent):
|
||||
"""Test that the remote session login action works."""
|
||||
game, agent = game_and_agent
|
||||
|
||||
client_1: Computer = game.simulation.network.get_node_by_hostname("client_1")
|
||||
|
||||
client_1.user_manager.add_user(username="test_user", password="password", bypass_can_perform_action=True)
|
||||
|
||||
action = (
|
||||
"NODE_SESSIONS_REMOTE_LOGIN",
|
||||
{"node_id": 0},
|
||||
{"node_id": 0, "username": "test_user", "password": "password"},
|
||||
)
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
# TODO Assert that there is a logged in user
|
||||
assert len(client_1.user_session_manager.remote_sessions) == 1
|
||||
|
||||
|
||||
def test_remote_logoff(game_and_agent):
|
||||
"""Test that the remote session logout action works."""
|
||||
game, agent = game_and_agent
|
||||
|
||||
client_1: Computer = game.simulation.network.get_node_by_hostname("client_1")
|
||||
|
||||
client_1.user_manager.add_user(username="test_user", password="password", bypass_can_perform_action=True)
|
||||
|
||||
action = (
|
||||
"NODE_SESSIONS_REMOTE_LOGIN",
|
||||
{"node_id": 0},
|
||||
{"node_id": 0, "username": "test_user", "password": "password"},
|
||||
)
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
# TODO Assert that there is a logged in user
|
||||
assert len(client_1.user_session_manager.remote_sessions) == 1
|
||||
|
||||
remote_session_id = client_1.user_session_manager.remote_sessions[0].uuid
|
||||
|
||||
action = (
|
||||
"NODE_SESSIONS_REMOTE_LOGOUT",
|
||||
{"node_id": 0},
|
||||
{"node_id": 0, "remote_session_id": remote_session_id},
|
||||
)
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
# TODO Assert the user has logged out
|
||||
assert len(client_1.user_session_manager.remote_sessions) == 0
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
|
||||
|
||||
def test_remote_logon(game_and_agent):
|
||||
"""Test that the remote session login action works."""
|
||||
game, agent = game_and_agent
|
||||
|
||||
client_1: Computer = game.simulation.network.get_node_by_hostname("client_1")
|
||||
|
||||
client_1.user_manager.add_user(username="test_user", password="password", bypass_can_perform_action=True)
|
||||
user = next((user for user in client_1.user_manager.users.values() if user.username == "test_user"), None)
|
||||
|
||||
assert user.password == "password"
|
||||
|
||||
action = (
|
||||
"NODE_ACCOUNTS_CHANGEPASSWORD",
|
||||
{"node_id": 0},
|
||||
{"node_id": 0, "username": user.username, "current_password": user.password, "new_password": "test_pass"},
|
||||
)
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
# TODO Assert that the user account password is changed
|
||||
assert user.password == "test_pass"
|
||||
|
||||
Reference in New Issue
Block a user