From 2a581d84efd5a287aeb77d23dcea3cfd2404102a Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Mon, 23 Dec 2024 21:40:10 -0500 Subject: [PATCH] pull in grype distro normalization changes Signed-off-by: Alex Goodman --- manager/tests/cli/test_workflows.py | 8 ++++++-- pkg/process/v6/transformers/os/transform.go | 12 ++---------- pkg/process/v6/transformers/os/transform_test.go | 8 ++++---- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/manager/tests/cli/test_workflows.py b/manager/tests/cli/test_workflows.py index a0c13590..42a2495f 100644 --- a/manager/tests/cli/test_workflows.py +++ b/manager/tests/cli/test_workflows.py @@ -1,6 +1,7 @@ import pytest from grype_db_manager.db import schema +from grype_db_manager.cli import config @pytest.mark.usefixtures("cli_env") @@ -29,6 +30,9 @@ def test_workflow_1(cli_env, command, logger, tmp_path, grype): } ) + cfg = config.load() + image = cfg.validate.gates[0].images[0] + grype = grype.install(schema.grype_version(schema_version), bin_dir) logger.step("setup: clear previous data") @@ -57,8 +61,8 @@ def test_workflow_1(cli_env, command, logger, tmp_path, grype): stdout, _ = grype.run("db update -v", env=cli_env) assert "Vulnerability database updated" in stdout - stdout, _ = grype.run("--platform linux/amd64 --by-cve alpine:3.2", env=cli_env) - assert "CVE-2016-2148" in stdout + stdout, _ = grype.run(f"--platform linux/amd64 {image}", env=cli_env) + assert "ELSA-2021-9314" in stdout logger.step("case 4: delete the DB") command.run("grype-db-manager db clear", env=cli_env) diff --git a/pkg/process/v6/transformers/os/transform.go b/pkg/process/v6/transformers/os/transform.go index aba7a131..aad10645 100644 --- a/pkg/process/v6/transformers/os/transform.go +++ b/pkg/process/v6/transformers/os/transform.go @@ -199,7 +199,7 @@ func groupFixedIns(vuln unmarshal.OSVulnerability) map[groupIndex][]unmarshal.OS func getPackageType(osName string) string { switch osName { - case "redhat", "amazon", "oracle", "sles", "mariner", "azurelinux": + case "redhat", "amazonlinux", "oraclelinux", "sles", "mariner", "azurelinux": return string(pkg.RpmPkg) case "ubuntu", "debian": return string(pkg.DebPkg) @@ -247,15 +247,7 @@ func normalizeOsName(id string) string { return id } - distroName := d.String() - - switch d { - case distro.OracleLinux: - distroName = "oracle" - case distro.AmazonLinux: - distroName = "amazon" - } - return distroName + return d.String() } func getOperatingSystem(osName, osID, osVersion string) *grypeDB.OperatingSystem { diff --git a/pkg/process/v6/transformers/os/transform_test.go b/pkg/process/v6/transformers/os/transform_test.go index a6625dab..1b1b6575 100644 --- a/pkg/process/v6/transformers/os/transform_test.go +++ b/pkg/process/v6/transformers/os/transform_test.go @@ -52,7 +52,7 @@ func TestTransform(t *testing.T) { } amazonOS := &grypeDB.OperatingSystem{ - Name: "amazon", + Name: "amazonlinux", ReleaseID: "amzn", MajorVersion: "2", } @@ -76,7 +76,7 @@ func TestTransform(t *testing.T) { MinorVersion: "0", // TODO: is this right? } ol8OS := &grypeDB.OperatingSystem{ - Name: "oracle", + Name: "oraclelinux", ReleaseID: "ol", MajorVersion: "8", } @@ -1221,8 +1221,8 @@ func TestGetOSInfo(t *testing.T) { { name: "oracle linux", group: "ol:8", - expectedOS: "oracle", // normalize name - expectedID: "ol", // keep original ID + expectedOS: "oraclelinux", // normalize name + expectedID: "ol", // keep original ID expectedV: "8", }, }