Skip to content
Snippets Groups Projects
Commit 1a982871 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'fix/webui' into 'develop'

Fixing issues with the WebUI and the optical cybersecurity module

Closes #57 and #102

See merge request !210
parents 1b43b52f ad051b2f
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!210Fixing issues with the WebUI and the optical cybersecurity module
......@@ -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
......
......@@ -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():
......
......@@ -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
......@@ -37,6 +37,7 @@ LOGGER = logging.getLogger(__name__)
def optical_attack_detector_service():
_service = OpticalAttackDetectorService()
_service.start()
time.sleep(2)
yield _service
_service.stop()
......@@ -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
......@@ -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()
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()
monitoring.assert_called()
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment