feat(packages): the rpm epoch in the version, and the installed advisories
driver / standard (pull_request) Failing after 15s
driver / lint (pull_request) Successful in 13s
driver / test (3.12) (pull_request) Failing after 39s
driver / types (pull_request) Failing after 47s
driver / test (3.13) (pull_request) Failing after 39s
driver / lowest (pull_request) Failing after 46s
driver / build (pull_request) Successful in 42s
driver / security (pull_request) Successful in 1m25s
CI / driver (pull_request) Failing after 2m35s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Failing after 15s
driver / lint (pull_request) Successful in 13s
driver / test (3.12) (pull_request) Failing after 39s
driver / types (pull_request) Failing after 47s
driver / test (3.13) (pull_request) Failing after 39s
driver / lowest (pull_request) Failing after 46s
driver / build (pull_request) Successful in 42s
driver / security (pull_request) Successful in 1m25s
CI / driver (pull_request) Failing after 2m35s
driver / publish (pull_request) Skipped
On an rpm host a package's version now carries its epoch where it has one (1:6.2.0-13.el9), as on a dpkg host: Oracle's and Red Hat's fixes name it, and without it an epoch-1 fix read as newer than every installed build. get_installed_advisory_cves() reads, as root and from the cache, the CVEs the installed security advisories close, through napalm-device-types 4.37.0; dnf only (NetOrk/netork#2394).
This commit is contained in:
1 parent
235c1e9a91
commit
257efdef8e
4 files changed
+108
-2
No files matched your search
@@ -4,6 +4,7 @@ import re
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from napalm_device_types import DNF_INSTALLED_CVES_COMMAND
|
||||
|
||||
from napalm_linux._routes import IpRoute, parse_ip_route
|
||||
from napalm_linux.linux import (
|
||||
@@ -2591,3 +2592,65 @@ class TestIpv6NextHops:
|
||||
out = "10.50.0.0/16 via inet 192.0.2.1 dev eth0\n"
|
||||
|
||||
assert [r.nexthop for r in parse_ip_route(out, "ipv4")] == ["192.0.2.1"]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_packages (rpm) and the installed advisories (NetOrk/netork#2394)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# rpm -qa on Oracle Linux 9.8 (aarch64): gmp and openssl carry epoch 1.
|
||||
RPM_QA = (
|
||||
"glibc-common\t2.34-284.0.1.el9_8.4\t1210460\tCommon binaries and locale data for glibc\n"
|
||||
"gmp\t1:6.2.0-13.el9\t805146\tA GNU arbitrary precision library\n"
|
||||
"openssl\t1:3.5.8-2.0.1.el9_8\t2106925\tUtilities from the general purpose cryptography library\n"
|
||||
)
|
||||
|
||||
|
||||
class TestRpmPackages:
|
||||
def test_the_version_carries_the_epoch_where_the_package_has_one(self, driver):
|
||||
"""Oracle's and Red Hat's fixes name it (`1:6.2.0-13.el9`); without it an
|
||||
epoch-1 fix reads as newer than every installed build."""
|
||||
driver._pkg_manager = "dnf"
|
||||
with patch.object(driver, "_send", return_value=RPM_QA) as send:
|
||||
pkgs = {p["name"]: p for p in driver.get_packages()}
|
||||
|
||||
assert "%|EPOCH?{%{EPOCH}:}:{}|%{VERSION}-%{RELEASE}" in send.call_args.args[0]
|
||||
assert pkgs["gmp"]["version"] == "1:6.2.0-13.el9"
|
||||
assert pkgs["openssl"]["version"] == "1:3.5.8-2.0.1.el9_8"
|
||||
assert pkgs["glibc-common"]["version"] == "2.34-284.0.1.el9_8.4"
|
||||
assert pkgs["glibc-common"]["source"] == "dnf"
|
||||
assert pkgs["glibc-common"]["size"] == 1210460
|
||||
|
||||
|
||||
class TestInstalledAdvisoryCves:
|
||||
def test_dnf_reads_the_installed_advisories_as_root(self, driver):
|
||||
driver._pkg_manager = "dnf"
|
||||
driver._device.send_command.side_effect = [
|
||||
"0", # id -u
|
||||
(
|
||||
"CVE-2023-4911 Important/Sec. glibc-common-2.34-60.0.3.el9_2.7.aarch64\n"
|
||||
"CVE-2023-38545 Important/Sec. curl-7.76.1-26.el9_3.2.aarch64\n"
|
||||
"__DNF_RC=0\n__NETORK_RC=0"
|
||||
),
|
||||
]
|
||||
|
||||
assert driver.get_installed_advisory_cves() == {
|
||||
"glibc-common": ["CVE-2023-4911"],
|
||||
"curl": ["CVE-2023-38545"],
|
||||
}
|
||||
sent = driver._device.send_command.call_args.args[0]
|
||||
assert DNF_INSTALLED_CVES_COMMAND in sent
|
||||
|
||||
def test_a_failed_dnf_raises_instead_of_reading_as_nothing_installed(self, driver):
|
||||
driver._pkg_manager = "dnf"
|
||||
driver._device.send_command.side_effect = ["0", "__DNF_RC=1\n__NETORK_RC=0"]
|
||||
|
||||
with pytest.raises(ValueError, match="exit status 1"):
|
||||
driver.get_installed_advisory_cves()
|
||||
|
||||
@pytest.mark.parametrize("manager", ["yum", "apt", "apk", "pacman"])
|
||||
def test_other_package_managers_keep_no_such_advisories(self, driver, manager):
|
||||
driver._pkg_manager = manager
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
driver.get_installed_advisory_cves()
|
||||
Reference in new issue
Block a user