Skip to content

Commit

Permalink
pull in grype distro normalization changes
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman committed Dec 24, 2024
1 parent 3976e77 commit 2a581d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
8 changes: 6 additions & 2 deletions manager/tests/cli/test_workflows.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 2 additions & 10 deletions pkg/process/v6/transformers/os/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/process/v6/transformers/os/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestTransform(t *testing.T) {
}

amazonOS := &grypeDB.OperatingSystem{
Name: "amazon",
Name: "amazonlinux",
ReleaseID: "amzn",
MajorVersion: "2",
}
Expand All @@ -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",
}
Expand Down Expand Up @@ -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",
},
}
Expand Down

0 comments on commit 2a581d8

Please sign in to comment.