|
| 1 | +# SPDX-FileCopyrightText: 2026 Sebastian Garcia <sebastian.garcia@agents.fel.cvut.cz> |
| 2 | +# SPDX-License-Identifier: GPL-2.0-only |
| 3 | + |
| 4 | +from unittest.mock import Mock, patch |
| 5 | + |
| 6 | +from modules.anomaly_detection_https.anomaly_detection_https import ( |
| 7 | + AnomalyDetectionHTTPS, |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +def make_https_anomaly_conf(): |
| 12 | + conf = Mock() |
| 13 | + conf.https_anomaly_training_hours.return_value = 1 |
| 14 | + conf.https_anomaly_training_fit_method.return_value = "welford" |
| 15 | + conf.https_anomaly_training_alpha.return_value = 0.1 |
| 16 | + conf.https_anomaly_hourly_zscore_thr.return_value = 3.0 |
| 17 | + conf.https_anomaly_flow_zscore_thr.return_value = 3.0 |
| 18 | + conf.https_anomaly_adapt_score_thr.return_value = 2.0 |
| 19 | + conf.https_anomaly_baseline_alpha.return_value = 0.05 |
| 20 | + conf.https_anomaly_drift_alpha.return_value = 0.02 |
| 21 | + conf.https_anomaly_suspicious_alpha.return_value = 0.001 |
| 22 | + conf.https_anomaly_min_baseline_points.return_value = 5 |
| 23 | + conf.https_anomaly_max_small_flow_anomalies.return_value = 1 |
| 24 | + conf.https_anomaly_ja3_min_variants_per_server.return_value = 2 |
| 25 | + conf.https_anomaly_use_adwin_drift.return_value = False |
| 26 | + conf.https_anomaly_adwin_delta.return_value = 0.002 |
| 27 | + conf.https_anomaly_adwin_clock.return_value = 32 |
| 28 | + conf.https_anomaly_adwin_grace_period.return_value = 10 |
| 29 | + conf.https_anomaly_adwin_min_window_length.return_value = 5 |
| 30 | + conf.https_anomaly_empirical_threshold_quantile.return_value = 0.995 |
| 31 | + conf.https_anomaly_log_verbosity.return_value = 0 |
| 32 | + return conf |
| 33 | + |
| 34 | + |
| 35 | +def test_https_anomaly_module_is_instantiable_and_subscribes_to_new_ssl( |
| 36 | + tmp_path, |
| 37 | +): |
| 38 | + db = Mock() |
| 39 | + db.subscribe.return_value = "ssl_channel" |
| 40 | + conf = make_https_anomaly_conf() |
| 41 | + |
| 42 | + with ( |
| 43 | + patch( |
| 44 | + "slips_files.common.abstracts.imodule.DBManager", return_value=db |
| 45 | + ), |
| 46 | + patch( |
| 47 | + "modules.anomaly_detection_https.anomaly_detection_https.ConfigParser", |
| 48 | + return_value=conf, |
| 49 | + ), |
| 50 | + ): |
| 51 | + module = AnomalyDetectionHTTPS( |
| 52 | + logger=Mock(), |
| 53 | + output_dir=str(tmp_path), |
| 54 | + redis_port=6379, |
| 55 | + termination_event=Mock(), |
| 56 | + slips_args=Mock(), |
| 57 | + conf=Mock(), |
| 58 | + ppid=12345, |
| 59 | + bloom_filters_manager=Mock(), |
| 60 | + ) |
| 61 | + |
| 62 | + assert isinstance(module, AnomalyDetectionHTTPS) |
| 63 | + |
| 64 | + module.subscribe_to_channels() |
| 65 | + |
| 66 | + db.subscribe.assert_called_once_with("new_ssl") |
| 67 | + assert module.channels == {"new_ssl": "ssl_channel"} |
0 commit comments