63 lines
4.0 KiB
Python
63 lines
4.0 KiB
Python
"""Ensure extra publisher context survives normalization without crossing product boundaries."""
|
|
import pytest
|
|
|
|
from vuln_mcp.sources.parsers import InvalidData, parse
|
|
|
|
|
|
CVE = "CVE-2025-12345"
|
|
URL = "https://example.org/advisories/12345"
|
|
|
|
|
|
def test_later_cve_container_adds_attributed_remediations_without_changing_cna_status():
|
|
source = {"dataType": "CVE_RECORD", "dataVersion": "5.1", "cveMetadata": {"state": "PUBLISHED", "cveId": CVE},
|
|
"containers": {"cna": {"providerMetadata": {"shortName": "upstream"},
|
|
"affected": [{"product": "Client", "platforms": ["arm64", "x86_64"], "defaultStatus": "unaffected", "versions": [
|
|
{"version": "1.0.0", "lessThan": "2.0.0", "versionType": "semver", "status": "affected",
|
|
"changes": [{"at": "1.9.0", "status": "unaffected"}]}]}]},
|
|
"adp": [{"providerMetadata": {"shortName": "Integrator"},
|
|
"solutions": [{"lang": "en", "value": "Install the maintenance release."}],
|
|
"workarounds": [{"lang": "en", "value": "Disable the optional feature."}],
|
|
"impacts": [{"capecId": "CAPEC-1", "descriptions": [{"lang": "en", "value": "Service interruption."}]}]}]}}
|
|
issue, = parse("cvelist", source, URL).issues
|
|
assert {(p["architecture"], p["default_status"], p["range"]["changes"][0]["status"], p["publisher"]) for p in issue.products} == {
|
|
("arm64", "not_affected", "not_affected", "upstream"), ("x86_64", "not_affected", "not_affected", "upstream")}
|
|
assert {(f["category"], f["details"], f["publisher"]) for f in issue.fixes} == {
|
|
("solution", "Install the maintenance release.", "Integrator"), ("workaround", "Disable the optional feature.", "Integrator")}
|
|
assert issue.facts["impacts"] == [{"description": "Service interruption.", "capec": "CAPEC-1", "publisher": "Integrator"}]
|
|
|
|
|
|
def csaf():
|
|
return {"document": {"csaf_version": "2.0", "title": "Maintenance advisory", "tracking": {"id": "local-12345"}, "publisher": {"name": "Maintainer"}},
|
|
"product_tree": {"full_product_names": [{"name": "Workstation", "product_id": "w"}, {"name": "Server", "product_id": "s"}]},
|
|
"vulnerabilities": [{"cve": CVE, "cwe": {"id": "CWE-20"}, "product_status": {"known_affected": ["w"], "fixed": ["s"]},
|
|
"threats": [{"category": "impact", "details": "Service unavailable.", "product_ids": ["w"]}],
|
|
"scores": [{"products": ["w"], "cvss_v3": {"baseScore": 0.0, "vectorString": "CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:U/C:N/I:N/A:N"}}]}]}
|
|
|
|
|
|
def test_csaf_does_not_assign_one_products_score_to_another():
|
|
issue, = parse("msrc", csaf(), URL).issues
|
|
score, = issue.facts["cvss"]
|
|
assert (score["score"], score["product_ids"], score["publisher"]) == (0, ["w"], "Maintainer")
|
|
assert issue.facts["impacts"] == [{"description": "Service unavailable.", "product_ids": ["w"]}]
|
|
assert issue.facts["cwe"] == [{"id": "CWE-20", "publisher": "Maintainer"}]
|
|
|
|
|
|
def test_csaf_unknown_group_is_invalid():
|
|
raw = csaf()
|
|
raw['vulnerabilities'][0]['remediations'] = [{'category': 'vendor_fix', 'details': 'Apply update.',
|
|
'group_ids': ['missing']}]
|
|
with pytest.raises(InvalidData, match='unresolved CSAF remediation group'):
|
|
parse('msrc', raw, URL)
|
|
|
|
|
|
def test_csaf_unknown_fix_target_stays_opaque_and_never_universal():
|
|
# MSRC reuses remediation blocks across documents, so the ID is kept as-is;
|
|
# an opaque ID still matches no product of this document.
|
|
raw = csaf()
|
|
raw['vulnerabilities'][0]['remediations'] = [{'category': 'vendor_fix', 'details': 'Apply update.',
|
|
'product_ids': ['missing']}]
|
|
issue, = parse('msrc', raw, URL).issues
|
|
fix, = issue.fixes
|
|
assert fix['product_ids'] == ['missing'] and 'version' not in fix
|
|
assert [p['product_id'] for p in issue.products] == ['w', 's']
|