def test_is_checksum_correct_enabled_false(self): notus = NotusMetadataHandler(nvti=self.nvti) notus.nvti.get_file_checksum.return_value = "abc123" notus._openvas_settings_dict = {'nasl_no_signature_check': 0} self.assertFalse( notus.is_checksum_correct(Path("./tests/notus/example.csv")))
def test_is_checksum_correct_enabled_true(self): notus = NotusMetadataHandler(nvti=self.nvti) notus.nvti.get_file_checksum.return_value = ( "2f561b9be5d1a1194f49cd5a6a024dee15a0c0bc7d94287266d0e6358e737f4e") notus._openvas_settings_dict = {'nasl_no_signature_check': 0} self.assertTrue( notus.is_checksum_correct(Path("./tests/notus/example.csv")))
def test_update_metadata_warning(self): notus = NotusMetadataHandler() 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=False) notus.update_metadata() logging.Logger.warning.assert_called_with(f'Checksum for %s failed', path)
def test_update_metadata_field_name_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=False) notus.update_metadata() logging.Logger.warning.assert_called_with( f'Field names check for %s failed', path)
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)
def test_is_checksum_correct_check_disable(self): notus = NotusMetadataHandler() notus._openvas_settings_dict = {'nasl_no_signature_check': 1} self.assertTrue(notus.is_checksum_correct(Path("foo")))