Newer
Older
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
"""
Test the package with PCAP traces.
"""
import os
import glob
from pathlib import Path
from pcap_anonymize import anonymize_pcap, anonymize_pcaps_in_dir
### TEST CONSTANTS ###
dir_self = os.path.dirname(os.path.abspath(__file__))
dir_traces = os.path.join(dir_self, "traces")
### TEST FUNCTIONS ###
def test_anonymize_pcap_http(tmp_path: Path) -> None:
"""
Test the package with a PCAP trace containing HTTP packets.
Args:
tmp_path (pathlib.Path): temporary directory to store the output traces
"""
input = os.path.join(dir_traces, "http.pcap")
output = os.path.join(tmp_path, "http.anon.pcap")
anonymize_pcap(input, output)
assert os.path.exists(input)
assert os.path.exists(output)
def test_anonymize_pcap_dhcp(tmp_path: Path) -> None:
"""
Test the package with a PCAP trace containing DHCP packets.
Args:
tmp_path (pathlib.Path): temporary directory to store the output traces
"""
input = os.path.join(dir_traces, "dhcp.pcap")
output = os.path.join(tmp_path, "dhcp.anon.pcap")
anonymize_pcap(input, output)
assert os.path.exists(input)
assert os.path.exists(output)
def test_anonymize_pcap_tplink(tmp_path: Path) -> None:
"""
Test the package with a PCAP trace containing
TP-Link Smart Home protocol packets.
Args:
tmp_path (pathlib.Path): temporary directory to store the output traces
"""
input = os.path.join(dir_traces, "tplink.pcap")
output = os.path.join(tmp_path, "tplink.anon.pcap")
anonymize_pcap(input, output)
assert os.path.exists(input)
assert os.path.exists(output)
def test_anonymize_pcaps_in_dir() -> None:
"""
Test the package with a directory containing PCAP traces.
"""
input_traces = glob.glob(os.path.join(dir_traces, "*.pcap"))
anonymize_pcaps_in_dir(dir_traces)
output_traces = glob.glob(os.path.join(dir_traces, "*.anon.pcap"))
assert len(output_traces) == len(input_traces)
# Clean up
for output_trace in output_traces:
os.remove(output_trace)