Loading src/opticalattackdetector/.gitlab-ci.yml +6 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,12 @@ unit_test opticalattackdetector: - sleep 5 - docker ps -a - docker logs $IMAGE_NAME - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/home/${IMAGE_NAME}/results/${IMAGE_NAME}_report.xml; coverage xml -o /home/${IMAGE_NAME}/results/${IMAGE_NAME}_coverage.xml; coverage report --include='${IMAGE_NAME}/*' --show-missing" - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/home/${IMAGE_NAME}/results/${IMAGE_NAME}_report.xml" - docker logs redis - docker logs dbscanserving - docker logs $IMAGE_NAME - docker exec -i $IMAGE_NAME bash -c "coverage xml -o /home/${IMAGE_NAME}/results/${IMAGE_NAME}_coverage.xml" - docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing" coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' after_script: - docker rm -f $IMAGE_NAME Loading src/opticalattackdetector/service/OpticalAttackDetectorServiceServicerImpl.py +1 −1 Original line number Diff line number Diff line Loading @@ -221,7 +221,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi monitoring_client.IncludeKpi(kpi) # if -1 in response.cluster_indices: # attack detected if kpi.kpi_value.int32Val == -1: if kpi.kpi_value.int32Val == 1: attack = AttackDescription() attack.cs_id.uuid = request.service_id.service_uuid.uuid with HISTOGRAM_DURATION.labels(step="mitigation", **METRIC_LABELS).time(): Loading src/opticalattackdetector/tests/test_unitary.py +12 −17 Original line number Diff line number Diff line Loading @@ -15,13 +15,13 @@ import logging import uuid import queue import time from unittest.mock import patch import pytest from common.proto import dbscanserving_pb2 as dbscan from common.proto.optical_attack_detector_pb2 import DetectionRequest from common.tests.MockServicerImpl_Monitoring import MockServicerImpl_Monitoring from opticalattackdetector.client.OpticalAttackDetectorClient import \ OpticalAttackDetectorClient Loading @@ -37,6 +37,7 @@ LOGGER = logging.getLogger(__name__) def optical_attack_detector_service(): _service = OpticalAttackDetectorService() _service.start() time.sleep(2) yield _service _service.stop() Loading @@ -44,7 +45,7 @@ def optical_attack_detector_service(): @pytest.fixture(scope="session") def optical_attack_detector_client(optical_attack_detector_service: OpticalAttackDetectorService): _client = OpticalAttackDetectorClient( host=optical_attack_detector_service.bind_address, host="127.0.0.1", port=optical_attack_detector_service.bind_port, ) yield _client Loading @@ -56,26 +57,20 @@ def test_detect_attack( optical_attack_detector_client: OpticalAttackDetectorClient, ): message = dbscan.DetectionResponse() message.cluster_indices.extend([0, 1, -1, -1, -1]) message.cluster_indices.extend([0, 1] * 5 + [-1] * 10) monitoring_mock = MockServicerImpl_Monitoring(queue_samples = queue.Queue()) with patch( "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.attack_mitigator_client" ) as mitigator, patch( "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.monitoring_client", monitoring_mock, "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.monitoring_client.IncludeKpi", ) as monitoring, patch( "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.dbscanserving_client.Detect", # TODO: return dumb object with "cluster_indices" attribute # idea: create new response object return_value=message, ) as dbscanserving: for _ in range(10): request: DetectionRequest = DetectionRequest() request.service_id.context_id.context_uuid.uuid = str(uuid.uuid4()) request.service_id.service_uuid.uuid = str(uuid.uuid4()) request.kpi_id.kpi_id.uuid = "1" optical_attack_detector_client.DetectAttack(request) dbscanserving.assert_called_once() monitoring.IncludeKpi.assert_called_once() mitigator.NotifyAttack.assert_called() dbscanserving.assert_called() monitoring.assert_called() src/webui/requirements.in +4 −4 Original line number Diff line number Diff line Loading @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. Flask==2.1.3 Flask-WTF==1.0.0 flask-healthz==0.0.3 flask-unittest==0.1.2 Flask<3 Flask-WTF<2 flask-healthz<2 flask-unittest==0.1.3 lorem-text==2.1 werkzeug==2.3.7 Loading
src/opticalattackdetector/.gitlab-ci.yml +6 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,12 @@ unit_test opticalattackdetector: - sleep 5 - docker ps -a - docker logs $IMAGE_NAME - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/home/${IMAGE_NAME}/results/${IMAGE_NAME}_report.xml; coverage xml -o /home/${IMAGE_NAME}/results/${IMAGE_NAME}_coverage.xml; coverage report --include='${IMAGE_NAME}/*' --show-missing" - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/home/${IMAGE_NAME}/results/${IMAGE_NAME}_report.xml" - docker logs redis - docker logs dbscanserving - docker logs $IMAGE_NAME - docker exec -i $IMAGE_NAME bash -c "coverage xml -o /home/${IMAGE_NAME}/results/${IMAGE_NAME}_coverage.xml" - docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing" coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' after_script: - docker rm -f $IMAGE_NAME Loading
src/opticalattackdetector/service/OpticalAttackDetectorServiceServicerImpl.py +1 −1 Original line number Diff line number Diff line Loading @@ -221,7 +221,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi monitoring_client.IncludeKpi(kpi) # if -1 in response.cluster_indices: # attack detected if kpi.kpi_value.int32Val == -1: if kpi.kpi_value.int32Val == 1: attack = AttackDescription() attack.cs_id.uuid = request.service_id.service_uuid.uuid with HISTOGRAM_DURATION.labels(step="mitigation", **METRIC_LABELS).time(): Loading
src/opticalattackdetector/tests/test_unitary.py +12 −17 Original line number Diff line number Diff line Loading @@ -15,13 +15,13 @@ import logging import uuid import queue import time from unittest.mock import patch import pytest from common.proto import dbscanserving_pb2 as dbscan from common.proto.optical_attack_detector_pb2 import DetectionRequest from common.tests.MockServicerImpl_Monitoring import MockServicerImpl_Monitoring from opticalattackdetector.client.OpticalAttackDetectorClient import \ OpticalAttackDetectorClient Loading @@ -37,6 +37,7 @@ LOGGER = logging.getLogger(__name__) def optical_attack_detector_service(): _service = OpticalAttackDetectorService() _service.start() time.sleep(2) yield _service _service.stop() Loading @@ -44,7 +45,7 @@ def optical_attack_detector_service(): @pytest.fixture(scope="session") def optical_attack_detector_client(optical_attack_detector_service: OpticalAttackDetectorService): _client = OpticalAttackDetectorClient( host=optical_attack_detector_service.bind_address, host="127.0.0.1", port=optical_attack_detector_service.bind_port, ) yield _client Loading @@ -56,26 +57,20 @@ def test_detect_attack( optical_attack_detector_client: OpticalAttackDetectorClient, ): message = dbscan.DetectionResponse() message.cluster_indices.extend([0, 1, -1, -1, -1]) message.cluster_indices.extend([0, 1] * 5 + [-1] * 10) monitoring_mock = MockServicerImpl_Monitoring(queue_samples = queue.Queue()) with patch( "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.attack_mitigator_client" ) as mitigator, patch( "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.monitoring_client", monitoring_mock, "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.monitoring_client.IncludeKpi", ) as monitoring, patch( "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.dbscanserving_client.Detect", # TODO: return dumb object with "cluster_indices" attribute # idea: create new response object return_value=message, ) as dbscanserving: for _ in range(10): request: DetectionRequest = DetectionRequest() request.service_id.context_id.context_uuid.uuid = str(uuid.uuid4()) request.service_id.service_uuid.uuid = str(uuid.uuid4()) request.kpi_id.kpi_id.uuid = "1" optical_attack_detector_client.DetectAttack(request) dbscanserving.assert_called_once() monitoring.IncludeKpi.assert_called_once() mitigator.NotifyAttack.assert_called() dbscanserving.assert_called() monitoring.assert_called()
src/webui/requirements.in +4 −4 Original line number Diff line number Diff line Loading @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. Flask==2.1.3 Flask-WTF==1.0.0 flask-healthz==0.0.3 flask-unittest==0.1.2 Flask<3 Flask-WTF<2 flask-healthz<2 flask-unittest==0.1.3 lorem-text==2.1 werkzeug==2.3.7