Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/patchorder/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def _cpe(alias: Alias) -> str:
Alias(("windows 10 1809",), ("microsoft",), "o", "microsoft", "windows_10_1809", "Windows 10 1809 (build family 17763)."),
Alias(("windows 10 1607",), ("microsoft",), "o", "microsoft", "windows_10_1607", "Windows 10 1607 (build family 14393)."),
Alias(("windows 10 1507",), ("microsoft",), "o", "microsoft", "windows_10_1507", "Windows 10 1507 (build family 10240)."),
Alias(("redis",), ("redis",), "a", "redis", "redis", "Redis upstream CPE."),
Alias(("haproxy",), ("haproxy",), "a", "haproxy", "haproxy", "HAProxy from HAProxy Technologies."),
Alias(("varnish",), ("varnish",), "a", "varnish", "varnish", "Varnish Cache upstream CPE."),
Alias(("bind 9", "bind9"), ("isc",), "a", "isc", "bind9", "BIND 9 from ISC, not Microsoft DNS or Unbound."),
Alias(("node.js", "nodejs"), ("nodejs", "node"), "a", "nodejs", "node.js", "Node.js runtime; the CPE vendor is nodejs."),
)

# When the primary alias hits, also show this other dictionary name, lower.
Expand Down
47 changes: 47 additions & 0 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,50 @@ def test_dictionary_hit_merges_with_alias():
top = resolution.candidates[0]
assert top.cpe == "cpe:2.3:a:f5:nginx"
assert top.confidence >= 0.93


def test_redis_alias_resolves_to_redis_cpe():
resolution = resolve_asset(_asset(product="Redis", vendor="Redis", version="7.2.4"))
assert resolution.chosen is not None
assert resolution.chosen.cpe == "cpe:2.3:a:redis:redis"
assert resolution.chosen.confidence >= AUTO_USE_CONFIDENCE


def test_haproxy_alias_resolves_to_haproxy_cpe():
resolution = resolve_asset(_asset(product="HAProxy", vendor="HAProxy Technologies", version="2.8.5"))
assert resolution.chosen is not None
assert resolution.chosen.cpe == "cpe:2.3:a:haproxy:haproxy"
assert resolution.chosen.confidence >= AUTO_USE_CONFIDENCE


def test_varnish_alias_resolves_to_varnish_cpe():
resolution = resolve_asset(_asset(product="Varnish Cache", vendor="Varnish", version="7.6.0"))
assert resolution.chosen is not None
assert resolution.chosen.cpe == "cpe:2.3:a:varnish:varnish"
assert resolution.chosen.confidence >= AUTO_USE_CONFIDENCE


def test_bind9_alias_resolves_to_isc_bind9_cpe():
resolution = resolve_asset(_asset(product="BIND 9", vendor="ISC", version="9.18.24"))
assert resolution.chosen is not None
assert resolution.chosen.cpe == "cpe:2.3:a:isc:bind9"
assert resolution.chosen.confidence >= AUTO_USE_CONFIDENCE


def test_nodejs_alias_resolves_to_nodejs_cpe():
resolution = resolve_asset(_asset(product="Node.js", vendor="Node.js", version="20.11.1"))
assert resolution.chosen is not None
assert resolution.chosen.cpe == "cpe:2.3:a:nodejs:node.js"
assert resolution.chosen.confidence >= AUTO_USE_CONFIDENCE


def test_new_aliases_do_not_add_alternate_entries():
from patchorder.aliases import ALTERNATES
for cpe in (
"cpe:2.3:a:redis:redis",
"cpe:2.3:a:haproxy:haproxy",
"cpe:2.3:a:varnish:varnish",
"cpe:2.3:a:isc:bind9",
"cpe:2.3:a:nodejs:node.js",
):
assert cpe not in ALTERNATES
Loading