1
+ from pathlib import Path
1
2
from dojo .models import Engagement , Finding , Product , Test
2
3
from dojo .tools .tenable .parser import TenableParser
3
4
from unittests .dojo_test_case import DojoTestCase , get_unit_tests_scans_path
@@ -11,7 +12,7 @@ def create_test(self):
11
12
return test
12
13
13
14
def test_parse_some_findings_nessus_legacy (self ):
14
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln.xml" , encoding = "utf-8" ) as testfile :
15
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln.xml" ). open ( encoding = "utf-8" ) as testfile :
15
16
parser = TenableParser ()
16
17
findings = parser .get_findings (testfile , self .create_test ())
17
18
for finding in findings :
@@ -28,7 +29,7 @@ def test_parse_some_findings_nessus_legacy(self):
28
29
29
30
def test_parse_some_findings_csv_nessus_legacy (self ):
30
31
"""Test one report provided by a user"""
31
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln.csv" , encoding = "utf-8" ) as testfile :
32
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln.csv" ). open ( encoding = "utf-8" ) as testfile :
32
33
parser = TenableParser ()
33
34
findings = parser .get_findings (testfile , self .create_test ())
34
35
for finding in findings :
@@ -58,7 +59,7 @@ def test_parse_some_findings_csv_nessus_legacy(self):
58
59
59
60
def test_parse_some_findings_csv2_nessus_legacy (self ):
60
61
"""Test that use default columns of Nessus Pro 8.13.1 (#257)"""
61
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-default.csv" , encoding = "utf-8" ) as testfile :
62
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-default.csv" ). open ( encoding = "utf-8" ) as testfile :
62
63
parser = TenableParser ()
63
64
findings = parser .get_findings (testfile , self .create_test ())
64
65
for finding in findings :
@@ -80,7 +81,7 @@ def test_parse_some_findings_csv2_nessus_legacy(self):
80
81
81
82
def test_parse_some_findings_csv2_all_nessus_legacy (self ):
82
83
"""Test that use a report with all columns of Nessus Pro 8.13.1 (#257)"""
83
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-all.csv" , encoding = "utf-8" ) as testfile :
84
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-all.csv" ). open ( encoding = "utf-8" ) as testfile :
84
85
parser = TenableParser ()
85
86
findings = parser .get_findings (testfile , self .create_test ())
86
87
for finding in findings :
@@ -102,7 +103,7 @@ def test_parse_some_findings_csv2_all_nessus_legacy(self):
102
103
103
104
def test_parse_findings_all_nessus (self ):
104
105
"""Test that use a report with all columns selected in generate CSV Report 2025-04-14"""
105
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus-template.csv" , encoding = "utf-8" ) as testfile :
106
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus-template.csv" ). open ( encoding = "utf-8" ) as testfile :
106
107
parser = TenableParser ()
107
108
findings = parser .get_findings (testfile , self .create_test ())
108
109
for finding in findings :
@@ -128,19 +129,19 @@ def test_parse_findings_all_nessus(self):
128
129
129
130
def test_parse_some_findings_csv_bytes_nessus_legacy (self ):
130
131
"""This tests is designed to test the parser with different read modes"""
131
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-all.csv" , encoding = "utf-8" ) as testfile :
132
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-all.csv" ). open ( encoding = "utf-8" ) as testfile :
132
133
parser = TenableParser ()
133
134
findings = parser .get_findings (testfile , self .create_test ())
134
135
for finding in findings :
135
136
for endpoint in finding .unsaved_endpoints :
136
137
endpoint .clean ()
137
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-all.csv" , encoding = "utf-8" ) as testfile :
138
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-all.csv" ). open ( encoding = "utf-8" ) as testfile :
138
139
parser = TenableParser ()
139
140
findings = parser .get_findings (testfile , self .create_test ())
140
141
for finding in findings :
141
142
for endpoint in finding .unsaved_endpoints :
142
143
endpoint .clean ()
143
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-all.csv" , "rb " ) as testfile :
144
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_many_vuln2-all.csv" ). open ( encoding = "utf-8 " ) as testfile :
144
145
parser = TenableParser ()
145
146
findings = parser .get_findings (testfile , self .create_test ())
146
147
for finding in findings :
@@ -149,7 +150,7 @@ def test_parse_some_findings_csv_bytes_nessus_legacy(self):
149
150
150
151
def test_parse_some_findings_samples_nessus_legacy (self ):
151
152
"""Test that come from samples repo"""
152
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_v_unknown.xml" , encoding = "utf-8" ) as testfile :
153
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_v_unknown.xml" ). open ( encoding = "utf-8" ) as testfile :
153
154
parser = TenableParser ()
154
155
findings = parser .get_findings (testfile , self .create_test ())
155
156
for finding in findings :
@@ -180,7 +181,7 @@ def test_parse_some_findings_samples_nessus_legacy(self):
180
181
181
182
def test_parse_some_findings_with_cvssv3_nessus_legacy (self ):
182
183
"""Test with cvssv3"""
183
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_with_cvssv3.nessus" , encoding = "utf-8" ) as testfile :
184
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_with_cvssv3.nessus" ). open ( encoding = "utf-8" ) as testfile :
184
185
parser = TenableParser ()
185
186
findings = parser .get_findings (testfile , self .create_test ())
186
187
for finding in findings :
@@ -195,7 +196,7 @@ def test_parse_some_findings_with_cvssv3_nessus_legacy(self):
195
196
self .assertEqual ("CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N" , finding .cvssv3 )
196
197
197
198
def test_parse_many_findings_xml_nessus_was_legacy (self ):
198
- with open (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_many_vuln.xml" , encoding = "utf-8" ) as testfile :
199
+ with Path (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_many_vuln.xml" ). open ( encoding = "utf-8" ) as testfile :
199
200
parser = TenableParser ()
200
201
findings = parser .get_findings (testfile , self .create_test ())
201
202
for finding in findings :
@@ -213,7 +214,7 @@ def test_parse_many_findings_xml_nessus_was_legacy(self):
213
214
# self.assertEqual(79, finding.cwe)
214
215
215
216
def test_parse_one_findings_xml_nessus_was_legacy (self ):
216
- with open (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_one_vuln.xml" , encoding = "utf-8" ) as testfile :
217
+ with Path (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_one_vuln.xml" ). open ( encoding = "utf-8" ) as testfile :
217
218
parser = TenableParser ()
218
219
findings = parser .get_findings (testfile , self .create_test ())
219
220
for finding in findings :
@@ -228,7 +229,7 @@ def test_parse_one_findings_xml_nessus_was_legacy(self):
228
229
self .assertEqual ("Cross-Site Scripting (XSS)" , finding .title )
229
230
230
231
def test_parse_no_findings_xml_nessus_was_legacy (self ):
231
- with open (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_no_vuln.xml" , encoding = "utf-8" ) as testfile :
232
+ with Path (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_no_vuln.xml" ). open ( encoding = "utf-8" ) as testfile :
232
233
parser = TenableParser ()
233
234
findings = parser .get_findings (testfile , self .create_test ())
234
235
for finding in findings :
@@ -237,7 +238,7 @@ def test_parse_no_findings_xml_nessus_was_legacy(self):
237
238
self .assertEqual (0 , len (findings ))
238
239
239
240
def test_parse_many_findings_csv_nessus_was_legacy (self ):
240
- with open (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_many_vuln.csv" , encoding = "utf-8" ) as testfile :
241
+ with Path (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_many_vuln.csv" ). open ( encoding = "utf-8" ) as testfile :
241
242
parser = TenableParser ()
242
243
findings = parser .get_findings (testfile , self .create_test ())
243
244
for finding in findings :
@@ -256,7 +257,7 @@ def test_parse_many_findings_csv_nessus_was_legacy(self):
256
257
self .assertEqual (0 , finding .cwe )
257
258
258
259
def test_parse_one_findings_csv_nessus_was_legacy (self ):
259
- with open (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_one_vuln.csv" , encoding = "utf-8" ) as testfile :
260
+ with Path (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_one_vuln.csv" ). open ( encoding = "utf-8" ) as testfile :
260
261
parser = TenableParser ()
261
262
findings = parser .get_findings (testfile , self .create_test ())
262
263
for finding in findings :
@@ -272,13 +273,13 @@ def test_parse_one_findings_csv_nessus_was_legacy(self):
272
273
self .assertEqual ("http" , finding .unsaved_endpoints [0 ].protocol )
273
274
274
275
def test_parse_no_findings_csv_nessus_was_legacy (self ):
275
- with open (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_no_vuln.csv" , encoding = "utf-8" ) as testfile :
276
+ with Path (get_unit_tests_scans_path ("tenable/nessus_was" ) / "nessus_was_no_vuln.csv" ). open ( encoding = "utf-8" ) as testfile :
276
277
parser = TenableParser ()
277
278
findings = parser .get_findings (testfile , self .create_test ())
278
279
self .assertEqual (0 , len (findings ))
279
280
280
281
def test_parse_many_tenable_vulns (self ):
281
- with open (get_unit_tests_scans_path ("tenable" ) / "tenable_many_vuln.csv" , encoding = "utf-8" ) as testfile :
282
+ with Path (get_unit_tests_scans_path ("tenable" ) / "tenable_many_vuln.csv" ). open ( encoding = "utf-8" ) as testfile :
282
283
parser = TenableParser ()
283
284
findings = parser .get_findings (testfile , self .create_test ())
284
285
for finding in findings :
@@ -298,7 +299,7 @@ def test_parse_many_tenable_vulns(self):
298
299
self .assertEqual ("CVE-2023-32233" , vulnerability_id )
299
300
300
301
def test_parse_issue_6992 (self ):
301
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "issue_6992.nessus" , encoding = "utf-8" ) as testfile :
302
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "issue_6992.nessus" ). open ( encoding = "utf-8" ) as testfile :
302
303
parser = TenableParser ()
303
304
findings = parser .get_findings (testfile , self .create_test ())
304
305
for finding in findings :
@@ -308,7 +309,7 @@ def test_parse_issue_6992(self):
308
309
self .assertEqual ("High" , findings [0 ].severity )
309
310
310
311
def test_parse_nessus_new (self ):
311
- with open (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_new.csv" , encoding = "utf-8" ) as testfile :
312
+ with Path (get_unit_tests_scans_path ("tenable/nessus" ) / "nessus_new.csv" ). open ( encoding = "utf-8" ) as testfile :
312
313
parser = TenableParser ()
313
314
findings = parser .get_findings (testfile , self .create_test ())
314
315
self .assertEqual (99 , len (findings ))
@@ -319,7 +320,7 @@ def test_parse_nessus_new(self):
319
320
self .assertEqual ("3.1" , finding .cvssv3_score )
320
321
321
322
def test_parse_issue_9612 (self ):
322
- with open (get_unit_tests_scans_path ("tenable" ) / "issue_9612.csv" , encoding = "utf-8" ) as testfile :
323
+ with Path (get_unit_tests_scans_path ("tenable" ) / "issue_9612.csv" ). open ( encoding = "utf-8" ) as testfile :
323
324
parser = TenableParser ()
324
325
findings = parser .get_findings (testfile , self .create_test ())
325
326
for finding in findings :
@@ -329,7 +330,7 @@ def test_parse_issue_9612(self):
329
330
self .assertEqual ("Critical" , findings [0 ].severity )
330
331
331
332
def test_parse_issue_11102 (self ):
332
- with open (get_unit_tests_scans_path ("tenable" ) / "issue_11102.csv" , encoding = "utf-8" ) as testfile :
333
+ with Path (get_unit_tests_scans_path ("tenable" ) / "issue_11102.csv" ). open ( encoding = "utf-8" ) as testfile :
333
334
parser = TenableParser ()
334
335
findings = parser .get_findings (testfile , self .create_test ())
335
336
for finding in findings :
@@ -339,7 +340,7 @@ def test_parse_issue_11102(self):
339
340
self .assertEqual ("Reconfigure the affected application if possible to avoid use of medium strength ciphers." , findings [0 ].mitigation )
340
341
341
342
def test_parse_issue_11127 (self ):
342
- with open (get_unit_tests_scans_path ("tenable" ) / "issue_11102.csv" , encoding = "utf-8" ) as testfile :
343
+ with Path (get_unit_tests_scans_path ("tenable" ) / "issue_11102.csv" ). open ( encoding = "utf-8" ) as testfile :
343
344
parser = TenableParser ()
344
345
findings = parser .get_findings (testfile , self .create_test ())
345
346
for finding in findings :
0 commit comments