-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
170 lines (159 loc) · 4.55 KB
/
tests.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import fnmatch
import os
import pytest
from scapy.all import rdpcap
from heifip.extractor import FIPExtractor
from heifip.images.flow import FlowImage
from heifip.images.markovchain import (MarkovTransitionMatrixFlow,
MarkovTransitionMatrixPacket)
from heifip.images.packet import PacketImage
from heifip.layers import PacketProcessorType
TEST_FOLDER = "./tests/pcaps"
OUTPUT_DIR = "./tests/images"
def get_files():
assert os.path.exists(TEST_FOLDER)
packets = []
for root, dirnames, filenames in os.walk(TEST_FOLDER):
for filename in fnmatch.filter(filenames, "*.pcap"):
match = os.path.join(root, filename)
sub_dir = match.replace(TEST_FOLDER, "")
packets.append(rdpcap(match))
return packets[0:25] # Otherwise we break Python...
@pytest.mark.parametrize('packet', get_files())
@pytest.mark.parametrize("append", [True, False])
@pytest.mark.parametrize("fill", [0, 255])
@pytest.mark.parametrize("dim", [4, 16])
@pytest.mark.parametrize(
"min_packets_per_flow", [0, 4]
)
@pytest.mark.parametrize("max_image_dim", [0, 16])
@pytest.mark.parametrize("min_image_dim", [0, 16])
@pytest.mark.parametrize("remove_duplicates", [True, False])
@pytest.mark.parametrize(
"preprocessing_type", [PacketProcessorType.HEADER, PacketProcessorType.NONE]
)
def test_extractor_flow(
packet,
append,
fill,
dim,
min_packets_per_flow,
max_image_dim,
min_image_dim,
remove_duplicates,
preprocessing_type,
):
extractor = FIPExtractor()
extractor.create_image_from_packet(
packet,
preprocessing_type,
FlowImage,
min_image_dim,
max_image_dim,
min_packets_per_flow,
0,
remove_duplicates,
dim,
fill,
append,
)
# TODO: Assert matrix... if functions worked fine
@pytest.mark.parametrize('packet', get_files())
@pytest.mark.parametrize(
"min_packets_per_flow", [0, 4]
)
@pytest.mark.parametrize(
"max_packets_per_flow", [0, 4]
)
@pytest.mark.parametrize("max_image_dim", [0, 16])
@pytest.mark.parametrize("min_image_dim", [0, 16])
@pytest.mark.parametrize("remove_duplicates", [True, False])
@pytest.mark.parametrize(
"preprocessing_type", [PacketProcessorType.HEADER, PacketProcessorType.NONE]
)
def test_extractor_markovflow(
packet,
min_packets_per_flow,
max_packets_per_flow,
max_image_dim,
min_image_dim,
remove_duplicates,
preprocessing_type,
):
extractor = FIPExtractor()
extractor.create_image_from_packet(
packet,
preprocessing_type,
MarkovTransitionMatrixFlow,
min_image_dim,
max_image_dim,
min_packets_per_flow,
max_packets_per_flow,
remove_duplicates,
)
# TODO: Assert matrix... if functions worked fine
@pytest.mark.parametrize('packet', get_files())
@pytest.mark.parametrize(
"min_packets_per_flow", [0, 4]
)
@pytest.mark.parametrize("max_image_dim", [0, 16])
@pytest.mark.parametrize("min_image_dim", [0, 16])
@pytest.mark.parametrize("remove_duplicates", [True, False])
@pytest.mark.parametrize(
"preprocessing_type", [PacketProcessorType.HEADER, PacketProcessorType.NONE]
)
def test_extractor_markovpacket(
packet,
min_packets_per_flow,
max_image_dim,
min_image_dim,
remove_duplicates,
preprocessing_type,
):
extractor = FIPExtractor()
extractor.create_image_from_packet(
packet,
preprocessing_type,
MarkovTransitionMatrixPacket,
min_image_dim,
max_image_dim,
min_packets_per_flow,
0,
remove_duplicates,
)
# TODO: Assert matrix... if functions worked fine
@pytest.mark.parametrize('packet', get_files())
@pytest.mark.parametrize("fill", [0, 255])
@pytest.mark.parametrize("dim", [4, 16])
@pytest.mark.parametrize("max_image_dim", [0, 16])
@pytest.mark.parametrize("min_image_dim", [0, 16])
@pytest.mark.parametrize("remove_duplicates", [True, False])
@pytest.mark.parametrize(
"preprocessing_type", [PacketProcessorType.HEADER, PacketProcessorType.NONE]
)
def test_extractor_packet(
packet,
fill,
dim,
max_image_dim,
min_image_dim,
remove_duplicates,
preprocessing_type,
):
extractor = FIPExtractor()
extractor.create_image_from_packet(
packet,
preprocessing_type,
PacketImage,
min_image_dim,
max_image_dim,
0,
0,
remove_duplicates,
dim,
fill,
False
)
# TODO: Assert matrix... if functions worked fine
if __name__ == "__main__":
pytest.main()