Beispiel #1
0
def test_sync_repo(test_data_env):
    repo = LocalFeedDataRepo.from_disk('test/data/feeds_repo')
    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)

    assert DataFeeds.sync_metadata(
        feed_client=test_data_env.feed_client) == empty_metadata_sync_result
    assert DataFeeds.sync_metadata(
        feed_client=test_data_env.feed_client,
        to_sync=['vulnerabilities'])[0].get('vulnerabilities') is not None
    assert DataFeeds.sync_from_fetched(repo, catalog_client=None)
Beispiel #2
0
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)

    assert (DataFeeds.sync_metadata(
        feed_client=test_data_env.feed_client) == empty_metadata_sync_result)
    assert (DataFeeds.sync_metadata(feed_client=test_data_env.feed_client,
                                    to_sync=["vulnerabilities"
                                             ])[0].get("vulnerabilities")
            is not None)
    assert DataFeeds.sync_from_fetched(repo, catalog_client=None)
Beispiel #3
0
def test_metadata_sync(test_data_env):
    r = DataFeeds.sync_metadata(feed_client=test_data_env.feed_client)
    assert r == empty_metadata_sync_result, 'Expected empty dict result from metadata sync with no to_sync directive'

    r = DataFeeds.sync_metadata(
        feed_client=test_data_env.feed_client,
        to_sync=['vulnerabilities', 'packages', 'vulndb', 'nvdv2'])
    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')
Beispiel #4
0
def test_group_lookups(test_data_env):
    r = DataFeeds.sync_metadata(feed_client=test_data_env.feed_client)
    assert r == empty_metadata_sync_result, 'No metadata should be returned from sync with empty to_sync input'

    r = DataFeeds.sync_metadata(feed_client=test_data_env.feed_client,
                                to_sync=['vulnerabilities'])
    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'
Beispiel #5
0
def test_metadata_sync(test_data_env):
    r = DataFeeds.sync_metadata(feed_client=test_data_env.feed_client)
    assert (
        r == empty_metadata_sync_result
    ), "Expected empty dict result from metadata sync with no to_sync directive"

    r = DataFeeds.sync_metadata(
        feed_client=test_data_env.feed_client,
        to_sync=["vulnerabilities", "packages", "vulndb", "nvdv2"],
    )
    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")
Beispiel #6
0
def test_group_lookups(test_data_env):
    r = DataFeeds.sync_metadata(feed_client=test_data_env.feed_client)
    assert (
        r == empty_metadata_sync_result
    ), "No metadata should be returned from sync with empty to_sync input"

    r = DataFeeds.sync_metadata(feed_client=test_data_env.feed_client,
                                to_sync=["vulnerabilities"])
    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"