mirror of
https://github.com/anchore/syft.git
synced 2026-11-04 00:16:38 +01:00
fix(java): filter Tomcat server CPE for embedded EL (#5322)
Signed-off-by: King Star <54024410+jstar0@users.noreply.github.com> Co-authored-by: Will Murphy <willmurphyscode@users.noreply.github.com>
This commit is contained in:
@@ -14,6 +14,7 @@ type filterFn func(cpe cpe.Attributes, p pkg.Package) bool
|
|||||||
|
|
||||||
var cpeFilters = []filterFn{
|
var cpeFilters = []filterFn{
|
||||||
disallowJiraClientServerMismatch,
|
disallowJiraClientServerMismatch,
|
||||||
|
disallowTomcatServerCPEForEmbeddedEL,
|
||||||
disallowJenkinsServerCPEForPluginPackage,
|
disallowJenkinsServerCPEForPluginPackage,
|
||||||
disallowJenkinsCPEsNotAssociatedWithJenkins,
|
disallowJenkinsCPEsNotAssociatedWithJenkins,
|
||||||
disallowNonParseableCPEs,
|
disallowNonParseableCPEs,
|
||||||
@@ -71,3 +72,18 @@ func disallowJiraClientServerMismatch(c cpe.Attributes, p pkg.Package) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// disallowTomcatServerCPEForEmbeddedEL prevents the server-level Tomcat CPE from being
|
||||||
|
// assigned to the EL-only embedded artifact. Keep its artifact-specific CPE candidates.
|
||||||
|
func disallowTomcatServerCPEForEmbeddedEL(c cpe.Attributes, p pkg.Package) bool {
|
||||||
|
if c.Vendor != "apache" || c.Product != "tomcat" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata, ok := p.Metadata.(pkg.JavaArchive)
|
||||||
|
if !ok || metadata.PomProperties == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return metadata.PomProperties.GroupID == "org.apache.tomcat.embed" && metadata.PomProperties.ArtifactID == "tomcat-embed-el"
|
||||||
|
}
|
||||||
|
|||||||
@@ -963,6 +963,39 @@ func TestGeneratePackageCPEs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTomcatEmbeddedCPEs(t *testing.T) {
|
||||||
|
packageFor := func(artifactID string) pkg.Package {
|
||||||
|
return pkg.Package{
|
||||||
|
Name: artifactID,
|
||||||
|
Version: "11.0.20",
|
||||||
|
Language: pkg.Java,
|
||||||
|
Type: pkg.JavaPkg,
|
||||||
|
Metadata: pkg.JavaArchive{
|
||||||
|
PomProperties: &pkg.JavaPomProperties{
|
||||||
|
GroupID: "org.apache.tomcat.embed",
|
||||||
|
ArtifactID: artifactID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hasCPE := func(cpes []cpe.CPE, vendor, product string) bool {
|
||||||
|
for _, generated := range cpes {
|
||||||
|
if generated.Attributes.Vendor == vendor && generated.Attributes.Product == product {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
elCPEs := FromPackageAttributes(packageFor("tomcat-embed-el"))
|
||||||
|
assert.False(t, hasCPE(elCPEs, "apache", "tomcat"), "EL-only module should not inherit the server CPE")
|
||||||
|
assert.True(t, hasCPE(elCPEs, "apache", "tomcat-embed-el"), "keep the artifact-specific CPE candidate")
|
||||||
|
|
||||||
|
coreCPEs := FromPackageAttributes(packageFor("tomcat-embed-core"))
|
||||||
|
assert.True(t, hasCPE(coreCPEs, "apache", "tomcat"), "core module should retain the Tomcat server CPE")
|
||||||
|
}
|
||||||
|
|
||||||
func TestCandidateProducts(t *testing.T) {
|
func TestCandidateProducts(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
Reference in New Issue
Block a user