feat(updates): the CVEs a host's installed advisories close (4.37.0)
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m2s
driver / test (3.13) (pull_request) Successful in 1m11s
driver / test (3.12) (pull_request) Successful in 1m24s
driver / lowest (pull_request) Successful in 40s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Successful in 2m29s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m2s
driver / test (3.13) (pull_request) Successful in 1m11s
driver / test (3.12) (pull_request) Successful in 1m24s
driver / lowest (pull_request) Successful in 40s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Successful in 2m29s
driver / publish (pull_request) Skipped
UpdateMixin declares get_installed_advisory_cves(): per package, the CVEs the installed security advisories close -- the distribution's word that a backport is in although the upstream version did not move. The command (DNF_INSTALLED_CVES_COMMAND, dnf 4, from the cache) and its parser (parse_dnf_installed_cves) live here for every dnf driver, as the security read's do. netOrk reads it where its knowledge base holds no records of the host's release (NetOrk/netork#2394).
This commit is contained in:
1 parent
a8fedf299a
commit
f3cb3601a8
6 files changed
+141
-1
No files matched your search
@@ -18,9 +18,11 @@ import pytest
|
||||
|
||||
from napalm_device_types.package_updates import (
|
||||
APT_UPGRADABLE_COMMAND,
|
||||
DNF_INSTALLED_CVES_COMMAND,
|
||||
DNF_SECURITY_COMMAND,
|
||||
nevra_name,
|
||||
parse_apt_upgradable,
|
||||
parse_dnf_installed_cves,
|
||||
parse_dnf_security,
|
||||
)
|
||||
|
||||
@@ -198,3 +200,75 @@ __DNF_RC=0
|
||||
)
|
||||
def test_the_name_of_a_nevra(self, nevra, name):
|
||||
assert nevra_name(nevra) == name
|
||||
|
||||
|
||||
class TestDnfInstalledCves:
|
||||
"""The CVEs the host's installed advisories close, per package (netOrk #2394).
|
||||
|
||||
Where netOrk's knowledge base holds no records of a release, the host's own
|
||||
advisories are the distribution's word that a backport is in. Lines from real
|
||||
hosts: Oracle Linux 9.8 (dnf 4.14, aarch64) and Amazon Linux 2023 (dnf 4.14).
|
||||
"""
|
||||
|
||||
ORACLE = """\
|
||||
CVE-2024-6501 Low/Sec. NetworkManager-1:1.48.10-2.0.1.el9_5.aarch64
|
||||
CVE-2024-3661 Moderate/Sec. NetworkManager-1:1.48.10-5.0.1.el9_5.aarch64
|
||||
CVE-2023-38545 Important/Sec. curl-7.76.1-23.el9_2.4.aarch64
|
||||
CVE-2023-38545 Important/Sec. curl-7.76.1-26.el9_3.2.aarch64
|
||||
CVE-2023-4911 Important/Sec. glibc-common-2.34-60.0.3.el9.aarch64
|
||||
CVE-2023-4911 Important/Sec. glibc-common-2.34-60.0.3.el9_2.7.aarch64
|
||||
__DNF_RC=0
|
||||
"""
|
||||
|
||||
AMAZON = """\
|
||||
CVE-2022-3715 Medium/Sec. bash-5.2.15-1.amzn2023.0.2.x86_64
|
||||
CVE-2022-23491 Important/Sec. ca-certificates-2021.2.50-1.0.amzn2023.0.6.noarch
|
||||
CVE-2023-32803 Important/Sec. ca-certificates-2023.2.60-1.0.amzn2023.0.2.noarch
|
||||
__DNF_RC=0
|
||||
"""
|
||||
|
||||
def test_cves_per_package_once_each_and_sorted(self):
|
||||
assert parse_dnf_installed_cves(self.ORACLE) == {
|
||||
"NetworkManager": ["CVE-2024-3661", "CVE-2024-6501"],
|
||||
"curl": ["CVE-2023-38545"],
|
||||
"glibc-common": ["CVE-2023-4911"],
|
||||
}
|
||||
|
||||
def test_amazon_linux(self):
|
||||
assert parse_dnf_installed_cves(self.AMAZON) == {
|
||||
"bash": ["CVE-2022-3715"],
|
||||
"ca-certificates": ["CVE-2022-23491", "CVE-2023-32803"],
|
||||
}
|
||||
|
||||
def test_lines_that_name_no_cve_are_left_out(self):
|
||||
"""A GPG prompt a repository without its key prints, an advisory id."""
|
||||
out = (
|
||||
"Importing GPG key 0x6E93CD0C:\n"
|
||||
' Userid : "https://packagecloud.io/crowdsec/crowdsec"\n'
|
||||
"ELSA-2023-5453 Important/Sec. glibc-2.34-60.0.3.el9_2.7.aarch64\n"
|
||||
"__DNF_RC=0\n"
|
||||
)
|
||||
assert parse_dnf_installed_cves(out) == {}
|
||||
|
||||
def test_a_failed_dnf_raises_instead_of_reading_as_no_advisories(self):
|
||||
with pytest.raises(ValueError, match="exit status 1"):
|
||||
parse_dnf_installed_cves("__DNF_RC=1\n")
|
||||
|
||||
def test_output_cut_short_raises(self):
|
||||
with pytest.raises(ValueError, match="no exit status"):
|
||||
parse_dnf_installed_cves(self.ORACLE.replace("__DNF_RC=0\n", ""))
|
||||
|
||||
def test_the_command_lists_installed_advisories_with_their_cves_from_the_cache(self, tmp_path):
|
||||
args = tmp_path / "args"
|
||||
dnf = tmp_path / "dnf"
|
||||
dnf.write_text(f"#!/bin/sh\nprintf '%s\\n' \"$@\" > {args}\n")
|
||||
dnf.chmod(0o755)
|
||||
env = {"PATH": f"{tmp_path}:{os.environ.get('PATH', '/usr/bin:/bin')}"}
|
||||
out = subprocess.run(
|
||||
["sh", "-c", DNF_INSTALLED_CVES_COMMAND], capture_output=True, text=True, env=env
|
||||
).stdout
|
||||
|
||||
assert {"--cacheonly", "updateinfo", "list", "--installed", "--with-cve"} <= set(
|
||||
args.read_text().split()
|
||||
)
|
||||
assert out == "__DNF_RC=0\n"
|
||||
Reference in new issue
Block a user