Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

GET Monitoring Security Policy Device List #45

Merged
merged 20 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions catalystwan/endpoints/endpoints_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
from catalystwan.endpoints.configuration_settings import ConfigurationSettings
from catalystwan.endpoints.misc import MiscellaneousEndpoints
from catalystwan.endpoints.monitoring.device_details import MonitoringDeviceDetails
from catalystwan.endpoints.monitoring.security_policy import MonitoringSecurityPolicy
from catalystwan.endpoints.monitoring.server_info import ServerInfo
from catalystwan.endpoints.monitoring.status import MonitoringStatus
from catalystwan.endpoints.real_time_monitoring.reboot_history import RealTimeMonitoringRebootHistory
Expand Down Expand Up @@ -199,6 +200,7 @@ def __init__(self, session: ManagerSession):
self.configuration_software_actions = ConfigurationSoftwareActions(session)
self.configuration_disaster_recovery = ConfigurationDisasterRecovery(session)
self.monitoring_device_details = MonitoringDeviceDetails(session)
self.monitoring_security_policy = MonitoringSecurityPolicy(session)
self.monitoring_server_info = ServerInfo(session)
self.monitoring_status = MonitoringStatus(session)
self.sdavc_cloud_connector = SDAVCCloudConnector(session)
Expand Down
12 changes: 12 additions & 0 deletions catalystwan/endpoints/monitoring/security_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

# mypy: disable-error-code="empty-body"

from catalystwan.endpoints import APIEndpoints, get
from catalystwan.models.monitoring.security_policy import SecurityPolicyDeviceList


class MonitoringSecurityPolicy(APIEndpoints):
@get("/security/policy/devicelist", "data")
def get_device_list(self) -> SecurityPolicyDeviceList:
...
16 changes: 16 additions & 0 deletions catalystwan/models/monitoring/security_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

from typing import List

from pydantic import BaseModel


class SecurityPolicyDeviceList(BaseModel):
amp_down: List[str]
amp_up: List[str]
ips_down: List[str]
ips_up: List[str]
urlf_down: List[str]
urlf_up: List[str]
zbfw_down: List[str]
zbfw_up: List[str]
65 changes: 65 additions & 0 deletions catalystwan/tests/test_monitoring_security_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2022 Cisco Systems, Inc. and its affiliates

import unittest
from unittest.mock import MagicMock, patch

from catalystwan.endpoints.monitoring.security_policy import MonitoringSecurityPolicy
from catalystwan.models.monitoring.security_policy import SecurityPolicyDeviceList


class TestMonitoringSecurityPolicy(unittest.TestCase):
def setUp(self) -> None:
self.mock_device_list_data = {
"amp_down": ["2.2.2.2"],
"amp_up": ["3.3.3.3"],
"ips_down": ["2.2.2.2"],
"ips_up": ["1.1.1.1"],
"urlf_down": ["3.3.3.3"],
"urlf_up": ["1.1.1.1", "2.2.2.2"],
"zbfw_down": [],
"zbfw_up": ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
}

@patch("catalystwan.session.ManagerSession")
def test_get_security_policy_device_list(self, mock_session):
# Arrange
# Create a MagicMock for the response that has a dataobj method
mock_response = MagicMock()

# Set up the mock response's dataobj method to return a ServerInfoResponse
mock_response.dataobj.return_value = SecurityPolicyDeviceList(**self.mock_device_list_data)

# Mock the request method of the ManagerSession to return the mock response
mock_session_instance = mock_session.return_value
mock_session_instance.request.return_value = mock_response

mon_sec_pol_api = MonitoringSecurityPolicy(mock_session_instance)

# Act
response = mon_sec_pol_api.get_device_list()

# Assert
self.assertIsInstance(response, SecurityPolicyDeviceList)
self.assertEqual(response.amp_down, self.mock_device_list_data["amp_down"])
self.assertEqual(response.amp_down, ["2.2.2.2"])
self.assertEqual(response.amp_up, self.mock_device_list_data["amp_up"])
self.assertEqual(response.amp_up, ["3.3.3.3"])
self.assertEqual(response.ips_down, self.mock_device_list_data["ips_down"])
self.assertEqual(response.ips_down, ["2.2.2.2"])
self.assertEqual(response.ips_up, self.mock_device_list_data["ips_up"])
self.assertEqual(response.ips_up, ["1.1.1.1"])
self.assertEqual(response.urlf_down, self.mock_device_list_data["urlf_down"])
self.assertEqual(response.urlf_down, ["3.3.3.3"])
self.assertEqual(response.urlf_up, self.mock_device_list_data["urlf_up"])
self.assertEqual(response.urlf_up, ["1.1.1.1", "2.2.2.2"])
self.assertEqual(response.zbfw_down, self.mock_device_list_data["zbfw_down"])
self.assertEqual(response.zbfw_down, [])
self.assertEqual(response.zbfw_up, self.mock_device_list_data["zbfw_up"])
self.assertEqual(response.zbfw_up, ["1.1.1.1", "2.2.2.2", "3.3.3.3"])

# Ensure the request method was called
mock_session_instance.request.assert_called_once()


if __name__ == "__main__":
unittest.main()