def test_upload_lsc_from_csv_reader_sucess(self): general_metadata_dict = { 'VULDETECT': 'Checks if a vulnerable package version is present on the target host.', 'SOLUTION': 'Please install the updated package(s).', 'SOLUTION_TYPE': 'VendorFix', 'QOD_TYPE': 'package', } notus = NotusMetadataHandler(nvti=self.nvti, metadata_path="./tests/notus") notus.nvti.add_vt_to_cache.return_value = None logging.Logger.debug = MagicMock() path = Path("./tests/notus/example.csv").resolve() purepath = PurePath(path).name with path.open("r") as openfile: for line_string in openfile: if line_string.startswith("{"): break reader = DictReader(openfile) ret = notus.upload_lsc_from_csv_reader(purepath, general_metadata_dict, reader) self.assertTrue(ret) logging.Logger.debug.assert_called_with( "Loaded %d/%d advisories from %s", 1, 1, purepath)
def test_update_metadata_success(self): notus = NotusMetadataHandler(metadata_path="./tests/notus") logging.Logger.warning = MagicMock() path = Path("./tests/notus/example.csv").resolve() purepath = PurePath(path).name notus._get_csv_filepaths = MagicMock(return_value=[path]) notus.is_checksum_correct = MagicMock(return_value=True) notus._check_field_names_lsc = MagicMock(return_value=True) notus.upload_lsc_from_csv_reader = MagicMock(return_value=True) notus.update_metadata() logging.Logger.warning.assert_not_called()
def test_update_metadata_failed(self): notus = NotusMetadataHandler(metadata_path="./tests/notus") logging.Logger.warning = MagicMock() path = Path("./tests/notus/example.csv").resolve() notus._get_csv_filepaths = MagicMock(return_value=[path]) notus.is_checksum_correct = MagicMock(return_value=True) notus._check_field_names_lsc = MagicMock(return_value=True) notus.upload_lsc_from_csv_reader = MagicMock(return_value=False) notus.update_metadata() logging.Logger.warning.assert_called_with( "Some advaisory was not loaded from %s", path.name)