tests.test_sbom_vulnerabilities module¶
Tests for the opt-in online SBOM layer: HTTP cache and OSV adapter.
All network traffic is mocked with respx; nothing here touches the
real OSV API. The NetworkClient is constructed with trust_env=False
so an ambient proxy in the test environment cannot interfere.
- tests.test_sbom_vulnerabilities.client(tmp_path)[source]¶
A cache-backed NetworkClient isolated to a temp dir, proxy-free.
- tests.test_sbom_vulnerabilities.test_network_client_caches_responses(client)[source]¶
A second identical request is served from disk, not the network.
- tests.test_sbom_vulnerabilities.test_network_client_retries_then_raises(client)[source]¶
Repeated 503s exhaust retries and surface as NetworkError.
- tests.test_sbom_vulnerabilities.test_network_client_raises_on_invalid_json(client)[source]¶
A 200 with a non-JSON body is reported as NetworkError.
- tests.test_sbom_vulnerabilities.test_network_client_needs_the_online_extra(monkeypatch, tmp_path)[source]¶
Without
httpx, the client refuses to start.
- tests.test_sbom_vulnerabilities.test_network_client_defaults_to_the_user_cache(monkeypatch, tmp_path)[source]¶
With no folder given, the cache goes to the user cache folder of mpm.
- tests.test_sbom_vulnerabilities.test_network_client_works_without_a_cache(tmp_path)[source]¶
A cache folder that cannot be created turns the cache off, not the client.
- tests.test_sbom_vulnerabilities.test_network_client_reports_a_client_that_cannot_start(client, monkeypatch)[source]¶
An HTTP client that fails to build fails as
NetworkError.A client behind a SOCKS proxy with no
socksiois one. It does not fail as the rawImportError.
- tests.test_sbom_vulnerabilities.test_network_client_refetches_an_unusable_cache_entry(client, entry)[source]¶
A cache entry that does not parse, or that expired, counts as a miss.
- tests.test_sbom_vulnerabilities.test_network_client_skips_a_body_it_cannot_cache(client, caplog)[source]¶
A body that JSON cannot encode is not cached, and the write never raises.
- tests.test_sbom_vulnerabilities.test_network_client_retries_a_dropped_connection(client, monkeypatch)[source]¶
A connection error is retried after the first backoff delay.
- tests.test_sbom_vulnerabilities.test_sleep_backoff_honors_a_retry_after_in_seconds(monkeypatch, attempt, retry_after, expected)[source]¶
- tests.test_sbom_vulnerabilities.test_parse_purls_maps_ecosystems(purls, expected_coordinates)[source]¶
- tests.test_sbom_vulnerabilities.test_osv_ecosystems_cover_every_canonical_alias_type()[source]¶
Homebrew resolves a formula’s source to one of ten registries.
Nine are OSV ecosystems and must be mapped under their canonical purl type, or every alias is skipped and the upstream-coordinate route is a no-op. CPAN is the tenth and stays out: OSV indexes no such ecosystem.
- tests.test_sbom_vulnerabilities.test_osv_ecosystems_cover_every_manager_of_an_indexed_type(manager_id, purl_type)[source]¶
A package’s own purl takes its manager ID as the type.
Each manager
PURL_MAPties to a type OSV indexes must then map to the ecosystem of that type, or the scan skips every package of that manager.
- tests.test_sbom_vulnerabilities.test_fetch_detail_drops_a_record_that_is_not_an_object(client)[source]¶
A detail answer that is not a JSON object yields no advisory.
- tests.test_sbom_vulnerabilities.test_scan_vulnerabilities_end_to_end(client)[source]¶
A full batch + detail round-trip, mapping advisories back to purls.
One advisory hitting two purls is fetched once, attached twice.
- tests.test_sbom_vulnerabilities.test_scan_vulnerabilities_no_supported_purls(client)[source]¶
Purls with no OSV ecosystem produce an empty result and no calls.
- tests.test_sbom_vulnerabilities.test_scan_vulnerabilities_skips_bad_detail(client)[source]¶
A detail fetch that 404s drops only that advisory, not the scan.
- tests.test_sbom_vulnerabilities.test_vulnerability_dataclass_is_frozen()[source]¶
Vulnerability instances are immutable, safe to share across purls.