Skip to content

Commit 8e36f4c

Browse files
committed
Refactored tests with __database__.is_msg_intended_for
1 parent 7e1dfe0 commit 8e36f4c

15 files changed

+153
-113
lines changed

tests/integration_tests/test_config_files.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ...slips import *
88
from pathlib import Path
99
import shutil
10+
import uuid
1011

1112
alerts_file = 'alerts.log'
1213

@@ -17,6 +18,9 @@ def connect_to_redis(redis_port):
1718
__database__.connect_to_redis_server(redis_port)
1819
return __database__
1920

21+
def setPrefix(database, _prefix:str):
22+
database.setPrefix(_prefix)
23+
return database
2024

2125
def is_evidence_present(log_file, expected_evidence):
2226
"""Function to read the log file line by line and returns when it finds the expected evidence"""
@@ -78,18 +82,18 @@ def check_for_text(txt, output_dir):
7882
return False
7983

8084
@pytest.mark.parametrize(
81-
'pcap_path, expected_profiles, output_dir, redis_port',
85+
'pcap_path, expected_profiles, output_dir, prefix',
8286
[
8387
(
8488
'dataset/test7-malicious.pcap',
8589
290,
8690
'test_configuration_file/',
87-
6667,
91+
'2f168df6-c2a9-4a0a-935a-b04fe92e43b7',
8892
)
8993
],
9094
)
9195
def test_conf_file(
92-
pcap_path, expected_profiles, output_dir, redis_port
96+
pcap_path, expected_profiles, output_dir, prefix
9397
):
9498
"""
9599
In this test we're using tests/test.conf
@@ -101,14 +105,16 @@ def test_conf_file(
101105
f'-f {pcap_path} ' \
102106
f'-o {output_dir} ' \
103107
f'-c tests/integration_tests/test.conf ' \
104-
f'-P {redis_port} ' \
108+
f'-uid {prefix} ' \
105109
f'> {output_file} 2>&1'
106110
# this function returns when slips is done
107111
os.system(command)
108112

109113
assert has_errors(output_dir) is False
110114

111-
database = connect_to_redis(redis_port)
115+
database = connect_to_redis(6379)
116+
117+
database = setPrefix(database, prefix)
112118
profiles = int(database.getProfilesLen())
113119
# expected_profiles is more than 50 because we're using direction = all
114120
assert profiles > expected_profiles
@@ -146,18 +152,18 @@ def test_conf_file(
146152

147153

148154
@pytest.mark.parametrize(
149-
'pcap_path, expected_profiles, output_dir, redis_port',
155+
'pcap_path, expected_profiles, output_dir, prefix',
150156
[
151157
(
152158
'dataset/test8-malicious.pcap',
153159
1,
154160
'pcap_test_conf2/',
155-
6668,
161+
'5eade174-9e34-431b-86c7-4569e55a723d',
156162
)
157163
],
158164
)
159165
def test_conf_file2(
160-
pcap_path, expected_profiles, output_dir, redis_port
166+
pcap_path, expected_profiles, output_dir, prefix
161167
):
162168
"""
163169
In this test we're using tests/test2.conf
@@ -170,15 +176,15 @@ def test_conf_file2(
170176
f'-f {pcap_path} ' \
171177
f'-o {output_dir} ' \
172178
f'-c tests/integration_tests/test2.conf ' \
173-
f'-P {redis_port} ' \
179+
f'-uid {prefix} ' \
174180
f'> {output_file} 2>&1'
175181
# this function returns when slips is done
176182
os.system(command)
177183

178184
assert has_errors(output_dir) is False
179185

180-
database = connect_to_redis(redis_port)
181-
186+
database = connect_to_redis(6379)
187+
database = setPrefix(database, prefix)
182188
# test 1 homenet ip
183189
# the only profile we should have is the one in home_network parameter
184190
profiles = int(database.getProfilesLen())

0 commit comments

Comments
 (0)