Skip to content

Commit

Permalink
🐛 RPM: fix match "(none)" vendor (#4791)
Browse files Browse the repository at this point in the history
* fix: match (none) vendor

* fix+extend the unit test
  • Loading branch information
slntopp authored Oct 29, 2024
1 parent 18a3d95 commit bb82f9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion providers/os/resources/packages/rpm_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
RpmPkgFormat = "rpm"
)

var RPM_REGEX = regexp.MustCompile(`^([\w-+]*)\s(\d*|\(none\)):([\w\d-+.:]+)\s([\w\d]*|\(none\))__([\w\d\s,/<>:\.]+)__(.*)$`)
var RPM_REGEX = regexp.MustCompile(`^([\w-+]*)\s(\d*|\(none\)):([\w\d-+.:]+)\s([\w\d]*|\(none\))__([\w\d\s,/<>:\.|\(none\)]+)__(.*)$`)

// ParseRpmPackages parses output from:
// rpm -qa --queryformat '%{NAME} %{EPOCHNUM}:%{VERSION}-%{RELEASE} %{ARCH}__%{VENDOR}__%{SUMMARY}\n'
Expand Down
20 changes: 19 additions & 1 deletion providers/os/resources/packages/rpm_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestRedhat8Parser(t *testing.T) {
}

m := ParseRpmPackages(pf, c.Stdout)
assert.Equal(t, 190, len(m), "detected the right amount of packages")
assert.Equal(t, 192, len(m), "detected the right amount of packages")

p := Package{
Name: "ncurses-base",
Expand Down Expand Up @@ -147,6 +147,24 @@ func TestRedhat8Parser(t *testing.T) {
}
assert.Equal(t, p, findPkg(m, p.Name), p.Name)

// Package with (none) vendor and arch
p = Package{
Name: "gpg-pubkey",
Version: "d4082792-5b32db75",
Vendor: "(none)",
Description: "gpg(Red Hat, Inc. (auxiliary key) <[email protected]>)",
Format: RpmPkgFormat,
FilesAvailable: PkgFilesAsync,
PUrl: "pkg:rpm/rhel/gpg-pubkey@d4082792-5b32db75?distro=rhel-8.4",
CPEs: []string{
"cpe:2.3:a:\\(none\\):gpg-pubkey:d4082792-5b32db75:*:*:*:*:*:*:*",
"cpe:2.3:a:\\(none\\):gpg-pubkey:d4082792:*:*:*:*:*:*:*",
"cpe:2.3:a:\\(none\\):gpg-pubkey:d4082792-5b32db75:*:*:*:*:*:*:*",
"cpe:2.3:a:\\(none\\):gpg-pubkey:d4082792:*:*:*:*:*:*:*",
},
}
assert.Equal(t, p, findPkg(m, p.Name), p.Name)

// fetch package files
p = Package{
Name: "which",
Expand Down

0 comments on commit bb82f9d

Please sign in to comment.