Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Limmen committed Jun 28, 2024
1 parent ced9c14 commit 7c134bc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,17 @@ def test_start_ossec_idses(self, mock_start_ossec_ids) -> None:
"csle_common.controllers.ossec_ids_controller.OSSECIDSController.start_ossec_ids_manager"
)
@patch(
"csle_common.controllers.ossec_ids_controller.OSSECIDSController.get_ossec_ids_monitor_thread_status_by_ip_and_port"
"csle_common.controllers.ossec_ids_controller.OSSECIDSController"
".get_ossec_ids_monitor_thread_status_by_ip_and_port"
)
@patch("grpc.insecure_channel")
@patch("csle_common.controllers.ossec_ids_controller.Logger")
def test_start_ossec_ids(
self,
mock_logger,
mock_insecure_channel,
mock_get_monitor_status,
mock_start_manager,
self,
mock_logger,
mock_insecure_channel,
mock_get_monitor_status,
mock_start_manager,
) -> None:
"""
Test the method for starting a OSSEC IDS with a specific IP
Expand Down Expand Up @@ -141,11 +142,12 @@ def test_start_ossec_ids(
"csle_common.controllers.ossec_ids_controller.OSSECIDSController.start_ossec_ids_manager"
)
@patch(
"csle_common.controllers.ossec_ids_controller.OSSECIDSController.get_ossec_ids_monitor_thread_status_by_ip_and_port"
"csle_common.controllers.ossec_ids_controller.OSSECIDSController"
".get_ossec_ids_monitor_thread_status_by_ip_and_port"
)
@patch("grpc.insecure_channel")
def test_stop_ossec_ids(
self, mock_insecure_channel, mock_get_monitor_status, mock_start_manager
self, mock_insecure_channel, mock_get_monitor_status, mock_start_manager
) -> None:
"""
Test the method for stopping a OSSEC IDS with a specific IP
Expand Down Expand Up @@ -191,7 +193,7 @@ def test_start_ossec_idses_managers(self, mock_start_manager) -> None:
@patch("csle_common.util.emulation_util.EmulationUtil.connect_admin")
@patch("csle_common.util.emulation_util.EmulationUtil.execute_ssh_cmd")
def test_start_ossec_ids_manager(
self, mock_execute_ssh_cmd, mock_connect_admin
self, mock_execute_ssh_cmd, mock_connect_admin
) -> None:
"""
Test method for starting the OSSEC IDS manager on a specific container
Expand Down Expand Up @@ -232,7 +234,7 @@ def test_stop_ossec_idses_managers(self, mock_stop_manager) -> None:
@patch("csle_common.util.emulation_util.EmulationUtil.connect_admin")
@patch("csle_common.util.emulation_util.EmulationUtil.execute_ssh_cmd")
def test_stop_ossec_ids_manager(
self, mock_execute_ssh_cmd, mock_connect_admin
self, mock_execute_ssh_cmd, mock_connect_admin
) -> None:
"""
Test method for stopping the OSSEC IDS manager on a specific container
Expand All @@ -255,18 +257,20 @@ def test_start_ossec_idses_monitor_threads(self, mock_start_monitor) -> None:
constants.CONTAINER_IMAGES = MagicMock()
constants.CONTAINER_IMAGES.OSSEC_IDS_IMAGES = ["container-1", "container-2"]
physical_server_ip = "192.168.1.10"
OSSECIDSController.start_ossec_idses_monitor_threads(emulation_env_config=self.emulation_env_config,physical_server_ip=physical_server_ip,logger=self.logger)
OSSECIDSController.start_ossec_idses_monitor_threads(emulation_env_config=self.emulation_env_config,
physical_server_ip=physical_server_ip,logger=self.logger)
assert mock_start_monitor.call_count == 2"""

@patch(
"csle_common.controllers.ossec_ids_controller.OSSECIDSController.start_ossec_ids_manager"
)
@patch(
"csle_common.controllers.ossec_ids_controller.OSSECIDSController.get_ossec_ids_monitor_thread_status_by_ip_and_port"
"csle_common.controllers.ossec_ids_controller.OSSECIDSController"
".get_ossec_ids_monitor_thread_status_by_ip_and_port"
)
@patch("grpc.insecure_channel")
def test_start_ossec_ids_monitor_thread(
self, mock_insecure_channel, mock_get_monitor_status, mock_start_manager
self, mock_insecure_channel, mock_get_monitor_status, mock_start_manager
) -> None:
"""
A method that sends a request to the OSSECIDSManager on a specific IP to start
Expand Down Expand Up @@ -333,7 +337,7 @@ def test_stop_ossec_ids_monitor_thread(self, mock_start_manager) -> None:
"csle_common.controllers.ossec_ids_controller.OSSECIDSController.start_ossec_idses_managers"
)
def test_get_ossec_idses_monitor_threads_statuses(
self, mock_start_managers
self, mock_start_managers
) -> None:
"""
Test a method that sends a request to the OSSECIDSManager on every container to get the status of the
Expand Down Expand Up @@ -383,7 +387,7 @@ def test_get_ossec_idses_managers_ports(self) -> None:

@patch("grpc.insecure_channel")
def test_get_ossec_ids_monitor_thread_status_by_ip_and_port(
self, mock_insecure_channel
self, mock_insecure_channel
) -> None:
"""
Tests a method that sends a request to the OSSECIDSManager with a specific port and ip
Expand Down Expand Up @@ -411,19 +415,20 @@ def test_get_ossec_ids_monitor_thread_status_by_ip_and_port(
"csle_common.controllers.ossec_ids_controller.OSSECIDSController.get_ossec_idses_managers_ports"
)
@patch(
"csle_common.controllers.ossec_ids_controller.OSSECIDSController.get_ossec_ids_monitor_thread_status_by_ip_and_port"
"csle_common.controllers.ossec_ids_controller.OSSECIDSController"
".get_ossec_ids_monitor_thread_status_by_ip_and_port"
)
@patch("csle_common.util.emulation_util.EmulationUtil.physical_ip_match")
@patch(
"csle_collector.ossec_ids_manager.ossec_ids_manager_util.OSSecManagerUtil.ossec_ids_monitor_dto_empty"
)
def test_get_ossec_managers_info(
self,
mock_ossec_dto_empty,
mock_physical_ip_match,
mock_get_status,
mock_get_ports,
mock_get_ips,
self,
mock_ossec_dto_empty,
mock_physical_ip_match,
mock_get_status,
mock_get_ports,
mock_get_ips,
) -> None:
"""
Tests the method that extracts the information of the OSSEC IDS managers for a given emulation
Expand Down
17 changes: 11 additions & 6 deletions simulation-system/libs/csle-common/tests/test_ovs_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import logging
from unittest.mock import patch, MagicMock
import csle_common.constants.constants as constants
from csle_common.controllers.ovs_controller import (
OVSController,
)
from csle_common.controllers.ovs_controller import OVSController
from csle_common.dao.emulation_config.containers_config import ContainersConfig


Expand All @@ -14,7 +12,7 @@ class TestOVSControllerSuite:
"""

@pytest.fixture
def mock_containers_config(self):
def mock_containers_config(self) -> None:
"""
Test method that sets up OVS switches on containers
Expand Down Expand Up @@ -42,10 +40,10 @@ def mock_containers_config(self):
@patch("subprocess.Popen")
@patch("time.sleep")
def test_create_virtual_switches_on_container(
self, mock_sleep, mock_popen, mock_containers_config
self, mock_sleep, mock_popen, mock_containers_config
) -> None:
"""
Test method that aplies the OVS configuration on the OVS switches
Test method that creates the OVS switches
:param mock_sleep: mock_sleep
:param mock_popen: mock_popen
Expand All @@ -63,6 +61,13 @@ def test_create_virtual_switches_on_container(
@patch("csle_common.util.emulation_util.EmulationUtil.connect_admin")
@patch("csle_common.util.emulation_util.EmulationUtil.execute_ssh_cmd")
def test_apply_ovs_config(self, mock_execute_ssh_cmd, mock_connect_admin) -> None:
"""
Test method that applies the OVS configuration
:param mock_execute_ssh_cmd: mock_execute_ssh_cmd
:param mock_connect_admin: mock_connect_admin
:return:
"""
emulation_env_config = MagicMock()
ovs_switch_config = MagicMock()
ovs_switch_config.container_name = "ovs_container_1"
Expand Down

0 comments on commit 7c134bc

Please sign in to comment.