-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix regex for matching RPM packages with unorthodox vendor name (#4726
) * Modify regex pattern for SuSE vendor name. Signed-off-by: Vasil Sirakov <[email protected]> * Trim out the HTML tag altogether and update the unit tests. Signed-off-by: Vasil Sirakov <[email protected]> * Fix unit test name. Signed-off-by: Vasil Sirakov <[email protected]> * Cleanup vendor name also in static query code path. Signed-off-by: Vasil Sirakov <[email protected]> --------- Signed-off-by: Vasil Sirakov <[email protected]>
- Loading branch information
1 parent
4e1406a
commit d6d1f67
Showing
2 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,3 +287,88 @@ func TestPhoton4ImageParser(t *testing.T) { | |
} | ||
assert.Equal(t, p, findPkg(m, p.Name), p.Name) | ||
} | ||
|
||
// ensure that the tag in the SuSE vendor name is parsed correctly | ||
func TestSuSEParser(t *testing.T) { | ||
epoch := int(0) | ||
pkgList := []*rpmdb.PackageInfo{ | ||
{ | ||
Name: "grep", | ||
Epoch: &epoch, | ||
Version: "3.1", | ||
Release: "150000.4.6.1", | ||
Arch: "x86_64", | ||
Vendor: "SUSE LLC <https://www.suse.com/>", | ||
Summary: "Print lines matching a pattern", | ||
}, | ||
} | ||
|
||
var packageList bytes.Buffer | ||
for _, pkg := range pkgList { | ||
packageList.WriteString(fmt.Sprintf("%s %d:%s-%s %s__%s__%s\n", pkg.Name, pkg.EpochNum(), pkg.Version, pkg.Release, pkg.Arch, pkg.Vendor, pkg.Summary)) | ||
} | ||
|
||
pf := &inventory.Platform{ | ||
Name: "suse", | ||
Version: "15.6", | ||
Arch: "x86_64", | ||
Family: []string{"linux", "unix", "os"}, | ||
Labels: map[string]string{ | ||
"distro-id": "suse", | ||
}, | ||
} | ||
|
||
m := ParseRpmPackages(pf, &packageList) | ||
assert.Equal(t, 1, len(m), "detected the right amount of packages") | ||
|
||
p := Package{ | ||
Name: "grep", | ||
Version: "3.1-150000.4.6.1", | ||
// Note that the tag <https://suse.com/> has been removed. | ||
Vendor: "SUSE LLC", | ||
Arch: "x86_64", | ||
Description: "Print lines matching a pattern", | ||
PUrl: "pkg:rpm/suse/[email protected]?arch=x86_64&distro=suse-15.6", | ||
CPEs: []string{ | ||
"cpe:2.3:a:suse_llc:grep:3.1-150000.4.6.1:*:*:*:*:*:x86_64:*", | ||
"cpe:2.3:a:suse_llc:grep:3.1-150000.4:*:*:*:*:*:x86_64:*", | ||
"cpe:2.3:a:suse_llc:grep:3.1:*:*:*:*:*:x86_64:*", | ||
"cpe:2.3:a:suse_llc:grep:3.1-150000.4.6.1:*:*:*:*:*:*:*", | ||
"cpe:2.3:a:suse_llc:grep:3.1-150000.4:*:*:*:*:*:*:*", | ||
"cpe:2.3:a:suse_llc:grep:3.1:*:*:*:*:*:*:*", | ||
}, | ||
Format: RpmPkgFormat, | ||
FilesAvailable: PkgFilesAsync, | ||
} | ||
assert.Equal(t, p, m[0], p.Name) | ||
} | ||
|
||
func TestVendorNameCleanup(t *testing.T) { | ||
vendorFromRpm := "SUSE LLC" | ||
actual := cleanupVendorName(vendorFromRpm) | ||
require.Equal(t, "SUSE LLC", actual) | ||
|
||
vendorFromRpm = "SUSE LLC<https://suse.com/>" | ||
actual = cleanupVendorName(vendorFromRpm) | ||
require.Equal(t, "SUSE LLC", actual) | ||
|
||
vendorFromRpm = "SUSE LLC <https://suse.com/>" | ||
actual = cleanupVendorName(vendorFromRpm) | ||
require.Equal(t, "SUSE LLC", actual) | ||
|
||
vendorFromRpm = "SUSE LLC <https://suse.com/>" | ||
actual = cleanupVendorName(vendorFromRpm) | ||
require.Equal(t, "SUSE LLC", actual) | ||
|
||
vendorFromRpm = "SUSE LLC <abc><def>" | ||
actual = cleanupVendorName(vendorFromRpm) | ||
require.Equal(t, "SUSE LLC", actual) | ||
|
||
vendorFromRpm = "SUSE LLC <>" | ||
actual = cleanupVendorName(vendorFromRpm) | ||
require.Equal(t, "SUSE LLC", actual) | ||
|
||
vendorFromRpm = "SUSE LLC <<>>" | ||
actual = cleanupVendorName(vendorFromRpm) | ||
require.Equal(t, "SUSE LLC", actual) | ||
} |