66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
import json
|
|
from zipfile import ZIP_DEFLATED, ZipFile
|
|
|
|
import pytest
|
|
|
|
from vuln_mcp.matching import Asset, product_status
|
|
from vuln_mcp.sources.feeds_archive import archive_docs
|
|
from vuln_mcp.sources.parsers import InvalidData
|
|
|
|
|
|
_CVE = "CVE-2023-3946"
|
|
_MEMBER = f"cves/2023/3xxx/{_CVE}.json"
|
|
_UPPER_BOUND = " 5.10.0 SP1 UP1"
|
|
|
|
|
|
def _write_record(path, version):
|
|
# Reduced from the publisher's 2026-11-28 baseline; the spaces are significant fixture data.
|
|
record = {
|
|
"dataType": "CVE_RECORD",
|
|
"dataVersion": "5.1",
|
|
"cveMetadata": {
|
|
"cveId": _CVE,
|
|
"state": "PUBLISHED",
|
|
"dateUpdated": "2024-10-15T18:38:29.839Z",
|
|
},
|
|
"containers": {"cna": {
|
|
"providerMetadata": {"shortName": "trellix"},
|
|
"affected": [{
|
|
"vendor": "Trellix",
|
|
"product": "Trellix EPO",
|
|
"platforms": ["Windows"],
|
|
"defaultStatus": "unaffected",
|
|
"versions": [{
|
|
"version": version,
|
|
"versionType": "custom",
|
|
"status": "affected",
|
|
"lessThan": _UPPER_BOUND,
|
|
}],
|
|
}],
|
|
}},
|
|
}
|
|
with ZipFile(path, "w", compression=ZIP_DEFLATED) as archive:
|
|
archive.writestr(_MEMBER, json.dumps(record))
|
|
|
|
|
|
def test_cve_archive_preserves_product_with_blank_version_as_uncomparable(tmp_path):
|
|
path = tmp_path / "baseline.zip"
|
|
_write_record(path, " ")
|
|
|
|
[doc] = list(archive_docs(path, "cvelist", "original", prefix="cves.zip!/"))
|
|
assert doc.native_id == _CVE
|
|
assert doc.artifact == f"original#cves.zip!/{_MEMBER}"
|
|
[issue] = doc.issues
|
|
[product] = issue.products
|
|
assert product["name"] == "Trellix EPO"
|
|
assert product["range"] == {"lessThan": _UPPER_BOUND}
|
|
assert product_status(product, Asset(product="Trellix EPO", version="5.10.0")) == "unknown"
|
|
|
|
|
|
def test_cve_archive_rejects_non_text_version(tmp_path):
|
|
path = tmp_path / "baseline.zip"
|
|
_write_record(path, 1)
|
|
|
|
with pytest.raises(InvalidData):
|
|
list(archive_docs(path, "cvelist", "original"))
|