def test_sync_repo(test_data_env, test_data_path): feeds_repo_path = os.path.join(test_data_path, "feeds_repo") repo = LocalFeedDataRepo.from_disk(feeds_repo_path) assert repo.has_metadata(), "Repo should have metadata" assert repo.has_root(), "Repo should have root dir already" with pytest.raises(Exception): DataFeeds.sync_from_fetched(repo, catalog_client=None) source_feeds = DataFeeds.get_feed_group_information( test_data_env.feed_client) assert (MetadataSyncUtils.sync_metadata( source_feeds=source_feeds) == empty_metadata_sync_result) to_sync = ["vulnerabilities"] source_feeds = DataFeeds.get_feed_group_information( feed_client=test_data_env.feed_client, to_sync=to_sync) assert (MetadataSyncUtils.sync_metadata( source_feeds=source_feeds, to_sync=to_sync)[0].get("vulnerabilities") is not None) assert DataFeeds.sync_from_fetched(repo, catalog_client=None)
def test_group_lookups(test_data_env): source_feeds = DataFeeds.get_feed_group_information( test_data_env.feed_client) r = MetadataSyncUtils.sync_metadata(source_feeds=source_feeds) assert ( r == empty_metadata_sync_result ), "No metadata should be returned from sync with empty to_sync input" to_sync = ["vulnerabilities"] source_feeds = DataFeeds.get_feed_group_information( feed_client=test_data_env.feed_client, to_sync=to_sync) r = MetadataSyncUtils.sync_metadata(source_feeds=source_feeds, to_sync=to_sync) assert ( r and len(r[0]) == 1 ), "Metadata should be returned from sync with non-empty to_sync list" df = feed_instance_by_name("vulnerabilities") assert df is not None, "vulnerabilities feed instance not loaded" assert df.metadata, "No vuln metadata found" logger.info("Vuln feed metadata {}".format(df.metadata.to_json())) assert not df.group_by_name("not_a_real_Group"), "Found non-existent group" assert df.group_by_name("alpine:3.6"), "Should have found group alpine:3.6"
def test_metadata_sync(test_data_env): source_feeds = DataFeeds.get_feed_group_information( test_data_env.feed_client) r = MetadataSyncUtils.sync_metadata(source_feeds=source_feeds) assert ( r == empty_metadata_sync_result ), "Expected empty dict result from metadata sync with no to_sync directive" to_sync = ["vulnerabilities", "packages", "vulndb", "nvdv2"] source_feeds = DataFeeds.get_feed_group_information( test_data_env.feed_client, to_sync=to_sync) r = MetadataSyncUtils.sync_metadata( source_feeds=source_feeds, to_sync=to_sync, ) assert r is not None, "Expected dict result from metadata sync" assert (type(r) == tuple and type(r[0]) == dict and type(r[1]) == list ), "Expected tuple with element 1 = dict result from metadata sync" assert len(r[0]) == 4, "Expected dict result from metadata sync" assert r[0].get("vulnerabilities") assert r[0].get("packages") assert r[0].get("vulndb") assert r[0].get("nvdv2")