mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Filter out CPE product candidates that are asterisks (#513)
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
316d4341c8
commit
6d4d083acc
@ -46,6 +46,16 @@ func (s fieldCandidateSet) add(candidates ...fieldCandidate) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s fieldCandidateSet) removeByValue(values ...string) {
|
||||||
|
for _, value := range values {
|
||||||
|
for candidate := range s {
|
||||||
|
if candidate.value == value {
|
||||||
|
delete(s, candidate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s fieldCandidateSet) clear() {
|
func (s fieldCandidateSet) clear() {
|
||||||
for k := range s {
|
for k := range s {
|
||||||
delete(s, k)
|
delete(s, k)
|
||||||
|
|||||||
@ -261,3 +261,33 @@ func Test_cpeFieldCandidateSet_uniqueValues(t *testing.T) {
|
|||||||
assert.ElementsMatch(t, []string{"1", "2", "3"}, set.uniqueValues())
|
assert.ElementsMatch(t, []string{"1", "2", "3"}, set.uniqueValues())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_cpeFieldCandidateSet_removeByValue(t *testing.T) {
|
||||||
|
s := newFieldCandidateSet()
|
||||||
|
// should be removed
|
||||||
|
s.add(fieldCandidate{
|
||||||
|
value: "1",
|
||||||
|
disallowSubSelections: true,
|
||||||
|
disallowDelimiterVariations: true,
|
||||||
|
})
|
||||||
|
s.add(fieldCandidate{
|
||||||
|
value: "1",
|
||||||
|
disallowSubSelections: true,
|
||||||
|
})
|
||||||
|
s.add(fieldCandidate{
|
||||||
|
value: "1",
|
||||||
|
disallowDelimiterVariations: true,
|
||||||
|
})
|
||||||
|
s.add(fieldCandidate{
|
||||||
|
value: "1",
|
||||||
|
})
|
||||||
|
// should not be removed
|
||||||
|
s.add(fieldCandidate{
|
||||||
|
value: "2",
|
||||||
|
})
|
||||||
|
assert.Len(t, s.values(), 5)
|
||||||
|
|
||||||
|
s.removeByValue("1")
|
||||||
|
|
||||||
|
assert.Len(t, s.values(), 1)
|
||||||
|
}
|
||||||
|
|||||||
@ -151,6 +151,9 @@ func candidateProducts(p pkg.Package) []string {
|
|||||||
products.addValue(prod)
|
products.addValue(prod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// it is never OK to have candidates with these values ["" and "*"] (since CPEs will match any other value)
|
||||||
|
products.removeByValue("")
|
||||||
|
products.removeByValue("*")
|
||||||
|
|
||||||
// try swapping hyphens for underscores, vice versa, and removing separators altogether
|
// try swapping hyphens for underscores, vice versa, and removing separators altogether
|
||||||
addDelimiterVariations(products)
|
addDelimiterVariations(products)
|
||||||
|
|||||||
@ -511,10 +511,12 @@ func TestGeneratePackageCPEs(t *testing.T) {
|
|||||||
|
|
||||||
func TestCandidateProducts(t *testing.T) {
|
func TestCandidateProducts(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
p pkg.Package
|
p pkg.Package
|
||||||
expected []string
|
expected []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "springframework",
|
||||||
p: pkg.Package{
|
p: pkg.Package{
|
||||||
Name: "springframework",
|
Name: "springframework",
|
||||||
Type: pkg.JavaPkg,
|
Type: pkg.JavaPkg,
|
||||||
@ -522,6 +524,7 @@ func TestCandidateProducts(t *testing.T) {
|
|||||||
expected: []string{"spring_framework", "springsource_spring_framework" /* <-- known good names | default guess --> */, "springframework"},
|
expected: []string{"spring_framework", "springsource_spring_framework" /* <-- known good names | default guess --> */, "springframework"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "java",
|
||||||
p: pkg.Package{
|
p: pkg.Package{
|
||||||
Name: "some-java-package-with-group-id",
|
Name: "some-java-package-with-group-id",
|
||||||
Type: pkg.JavaPkg,
|
Type: pkg.JavaPkg,
|
||||||
@ -535,6 +538,21 @@ func TestCandidateProducts(t *testing.T) {
|
|||||||
expected: []string{"itunes", "some-java-package-with-group-id", "some_java_package_with_group_id"},
|
expected: []string{"itunes", "some-java-package-with-group-id", "some_java_package_with_group_id"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "java-with-asterisk",
|
||||||
|
p: pkg.Package{
|
||||||
|
Name: "some-java-package-with-group-id",
|
||||||
|
Type: pkg.JavaPkg,
|
||||||
|
Language: pkg.Java,
|
||||||
|
Metadata: pkg.JavaMetadata{
|
||||||
|
PomProperties: &pkg.PomProperties{
|
||||||
|
GroupID: "com.apple.itunes.*",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []string{"itunes", "some-java-package-with-group-id", "some_java_package_with_group_id"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "jenkins-plugin",
|
||||||
p: pkg.Package{
|
p: pkg.Package{
|
||||||
Name: "some-jenkins-plugin",
|
Name: "some-jenkins-plugin",
|
||||||
Type: pkg.JenkinsPluginPkg,
|
Type: pkg.JenkinsPluginPkg,
|
||||||
@ -548,6 +566,7 @@ func TestCandidateProducts(t *testing.T) {
|
|||||||
expected: []string{"some-jenkins-plugin", "some_jenkins_plugin", "jenkins"},
|
expected: []string{"some-jenkins-plugin", "some_jenkins_plugin", "jenkins"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "javascript",
|
||||||
p: pkg.Package{
|
p: pkg.Package{
|
||||||
Name: "handlebars.js",
|
Name: "handlebars.js",
|
||||||
Type: pkg.NpmPkg,
|
Type: pkg.NpmPkg,
|
||||||
@ -555,6 +574,7 @@ func TestCandidateProducts(t *testing.T) {
|
|||||||
expected: []string{"handlebars" /* <-- known good names | default guess --> */, "handlebars.js"},
|
expected: []string{"handlebars" /* <-- known good names | default guess --> */, "handlebars.js"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "gem",
|
||||||
p: pkg.Package{
|
p: pkg.Package{
|
||||||
Name: "RedCloth",
|
Name: "RedCloth",
|
||||||
Type: pkg.GemPkg,
|
Type: pkg.GemPkg,
|
||||||
@ -562,6 +582,7 @@ func TestCandidateProducts(t *testing.T) {
|
|||||||
expected: []string{"redcloth_library" /* <-- known good names | default guess --> */, "RedCloth"},
|
expected: []string{"redcloth_library" /* <-- known good names | default guess --> */, "RedCloth"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "python",
|
||||||
p: pkg.Package{
|
p: pkg.Package{
|
||||||
Name: "python-rrdtool",
|
Name: "python-rrdtool",
|
||||||
Type: pkg.PythonPkg,
|
Type: pkg.PythonPkg,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user