@@ 384-411 (lines=28) @@ | ||
381 | "Loaded %d/%d advisories from %s", 0, 1, purepath |
|
382 | ) |
|
383 | ||
384 | def test_upload_lsc_from_csv_reader_sucess(self): |
|
385 | general_metadata_dict = { |
|
386 | 'VULDETECT': 'Checks if a vulnerable package version is present on the target host.', |
|
387 | 'SOLUTION': 'Please install the updated package(s).', |
|
388 | 'SOLUTION_TYPE': 'VendorFix', |
|
389 | 'QOD_TYPE': 'package', |
|
390 | } |
|
391 | ||
392 | notus = NotusMetadataHandler( |
|
393 | nvti=self.nvti, metadata_path="./tests/notus" |
|
394 | ) |
|
395 | notus.nvti.add_vt_to_cache.return_value = None |
|
396 | logging.Logger.debug = MagicMock() |
|
397 | path = Path("./tests/notus/example.csv").resolve() |
|
398 | purepath = PurePath(path).name |
|
399 | with path.open("r") as openfile: |
|
400 | for line_string in openfile: |
|
401 | if line_string.startswith("{"): |
|
402 | break |
|
403 | reader = DictReader(openfile) |
|
404 | ||
405 | ret = notus.upload_lsc_from_csv_reader( |
|
406 | purepath, general_metadata_dict, reader |
|
407 | ) |
|
408 | ||
409 | self.assertTrue(ret) |
|
410 | logging.Logger.debug.assert_called_with( |
|
411 | "Loaded %d/%d advisories from %s", 1, 1, purepath |
|
412 | ) |
|
413 | ||
@@ 354-381 (lines=28) @@ | ||
351 | ||
352 | logging.Logger.warning.assert_not_called() |
|
353 | ||
354 | def test_upload_lsc_from_csv_reader_failed(self): |
|
355 | general_metadata_dict = { |
|
356 | 'VULDETECT': 'Checks if a vulnerable package version is present on the target host.', |
|
357 | 'SOLUTION': 'Please install the updated package(s).', |
|
358 | 'SOLUTION_TYPE': 'VendorFix', |
|
359 | 'QOD_TYPE': 'package', |
|
360 | } |
|
361 | ||
362 | notus = NotusMetadataHandler( |
|
363 | nvti=self.nvti, metadata_path="./tests/notus" |
|
364 | ) |
|
365 | notus.nvti.add_vt_to_cache.side_effect = OspdOpenvasError |
|
366 | logging.Logger.debug = MagicMock() |
|
367 | path = Path("./tests/notus/example.csv").resolve() |
|
368 | purepath = PurePath(path).name |
|
369 | with path.open("r") as openfile: |
|
370 | for line_string in openfile: |
|
371 | if line_string.startswith("{"): |
|
372 | break |
|
373 | reader = DictReader(openfile) |
|
374 | ||
375 | ret = notus.upload_lsc_from_csv_reader( |
|
376 | purepath, general_metadata_dict, reader |
|
377 | ) |
|
378 | ||
379 | self.assertFalse(ret) |
|
380 | logging.Logger.debug.assert_called_with( |
|
381 | "Loaded %d/%d advisories from %s", 0, 1, purepath |
|
382 | ) |
|
383 | ||
384 | def test_upload_lsc_from_csv_reader_sucess(self): |