-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fingerprint_data.py
More file actions
78 lines (55 loc) · 2.57 KB
/
test_fingerprint_data.py
File metadata and controls
78 lines (55 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from typing import Any, Dict
import pytest
from monkeytypes import DiscoveredService, NetworkProtocol, NetworkService, OperatingSystem
from agentpluginapi import FingerprintData
LINUX_VERSION = "xenial"
DISCOVERED_SERVICE_DICT_1 = {"protocol": "tcp", "port": 80, "service": "http"}
DISCOVERED_SERVICE_OBJECT_1 = DiscoveredService(
protocol=NetworkProtocol.TCP, port=80, service=NetworkService.HTTP
)
DISCOVERED_SERVICE_DICT_2 = {"protocol": "tcp", "port": 443, "service": "https"}
DISCOVERED_SERVICE_OBJECT_2 = DiscoveredService(
protocol=NetworkProtocol.TCP, port=443, service=NetworkService.HTTPS
)
DISCOVERED_SERVICE_DICT_3 = {"protocol": "tcp", "port": 22, "service": "ssh"}
DISCOVERED_SERVICE_OBJECT_3 = DiscoveredService(
protocol=NetworkProtocol.TCP, port=22, service=NetworkService.SSH
)
FINGERPRINT_DATA_DICT_IN: Dict[str, Any] = {
"os_type": "linux",
"os_version": LINUX_VERSION,
"services": [DISCOVERED_SERVICE_DICT_3, DISCOVERED_SERVICE_DICT_2],
}
FINGERPRINT_DATA_OBJECT = FingerprintData(
os_type=OperatingSystem.LINUX,
os_version=LINUX_VERSION,
services=[DISCOVERED_SERVICE_OBJECT_3, DISCOVERED_SERVICE_OBJECT_2],
)
def test_fingerprint_data__serialization():
assert FINGERPRINT_DATA_OBJECT.to_json_dict() == FINGERPRINT_DATA_DICT_IN
def test_fingerprint_data__deserialization():
assert FingerprintData(**FINGERPRINT_DATA_DICT_IN) == FINGERPRINT_DATA_OBJECT
@pytest.mark.parametrize(
"discovered_service_object, discovered_service_dict",
[
(DISCOVERED_SERVICE_OBJECT_1, DISCOVERED_SERVICE_DICT_1),
(DISCOVERED_SERVICE_OBJECT_2, DISCOVERED_SERVICE_DICT_2),
(DISCOVERED_SERVICE_OBJECT_3, DISCOVERED_SERVICE_DICT_3),
],
)
def test_discovered_service__serialization(discovered_service_object, discovered_service_dict):
assert discovered_service_object.to_json_dict() == discovered_service_dict
@pytest.mark.parametrize(
"discovered_service_object, discovered_service_dict",
[
(DISCOVERED_SERVICE_OBJECT_1, DISCOVERED_SERVICE_DICT_1),
(DISCOVERED_SERVICE_OBJECT_2, DISCOVERED_SERVICE_DICT_2),
(DISCOVERED_SERVICE_OBJECT_3, DISCOVERED_SERVICE_DICT_3),
],
)
def test_discovered_service__deserialization(discovered_service_object, discovered_service_dict):
assert DiscoveredService(**discovered_service_dict) == discovered_service_object
@pytest.mark.parametrize("port", ["", 70000, None, -12342])
def test_discovered_service__invalid_port(port):
with pytest.raises(ValueError):
DiscoveredService(portocol=NetworkProtocol.TCP, port=port, service=NetworkService.SSH)