Skip to content

Commit

Permalink
fix: correct group IDs for commons-codec, okhttp, okio, and add integ…
Browse files Browse the repository at this point in the history
…ration tests for Java PURL generation (#2075)

Add overall integration test for java PURL detection.

Signed-off-by: Will Murphy <[email protected]>
  • Loading branch information
willmurphyscode authored Aug 31, 2023
1 parent b454160 commit 007b034
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 0 deletions.
3 changes: 3 additions & 0 deletions syft/pkg/cataloger/common/cpe/java_groupid_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ var DefaultArtifactIDToGroupID = map[string]string{
"ant-trax": "org.apache.ant",
"ant-weblogic": "org.apache.ant",
"ant-xz": "org.apache.ant",
"commons-codec": "commons-codec",
"okhttp": "com.squareup.okhttp3",
"okio": "com.squareup.okio",
"spring": "org.springframework",
"spring-amqp": "org.springframework.amqp",
"spring-batch-core": "org.springframework.batch",
Expand Down
197 changes: 197 additions & 0 deletions test/integration/java_purl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package integration

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/source"
)

func TestJavaPURLs(t *testing.T) {
sbom, _ := catalogFixtureImage(t, "image-test-java-purls", source.SquashedScope, nil)
found := make(map[string]string)
for _, p := range sbom.Artifacts.Packages.Sorted() {
if p.Type != pkg.JavaPkg && p.Type != pkg.JenkinsPluginPkg {
continue
}
key := fmt.Sprintf("%s@%s", p.Name, p.Version)
found[key] = p.PURL
}
for key, expectedPURL := range expectedPURLs {
purl := found[key]
assert.Equal(t, expectedPURL, purl, fmt.Sprintf("found wrong or missing PURL for %s want %s, got %s", key, expectedPURL, purl))
}
for key, foundPURL := range found {
expectedPURL := expectedPURLs[key]
assert.Equal(t, expectedPURL, foundPURL, fmt.Sprintf("found extra purl for %s want %s, got %s", key, expectedPURL, foundPURL))
}
}

// Constructed by:
// syft anchore/test_images:java-56d52bc -o template -t /tmp/test.templ | grep 'pkg:maven' | sort | uniq >> test/integration/java_purl_test.go
// where the template is:
/*
{{ range .Artifacts}}"{{.Name}}@{{.Version}}":"{{.PURL}}",
{{ end }}
*/
// The map was then hand-edited for correctness by comparing to Maven Central.
var expectedPURLs = map[string]string{
"[email protected]": "pkg:maven/com.twilio.jenkins/[email protected]",
"[email protected]": "pkg:maven/org.kohsuke/[email protected]",
"[email protected]": "pkg:maven/org.acegisecurity/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/com.sun.akuma/[email protected]",
"[email protected]": "pkg:maven/org.jvnet/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/org.jetbrains/[email protected]",
"[email protected]": "pkg:maven/org.apache.ant/[email protected]",
"[email protected]": "pkg:maven/org.apache.ant/[email protected]",
"[email protected]": "pkg:maven/antlr/[email protected]",
"[email protected]": "pkg:maven/aopalliance/[email protected]",
"[email protected]": "pkg:maven/args4j/[email protected]",
"[email protected]": "pkg:maven/asm-commons/[email protected]",
"[email protected]": "pkg:maven/asm-tree/[email protected]",
"[email protected]": "pkg:maven/asm/[email protected]",
"[email protected]": "pkg:maven/avalon-framework/[email protected]",
"[email protected]": "pkg:maven/com.infradna.tool/[email protected]",
"[email protected]": "pkg:maven/org.codehaus.classworlds/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.main/[email protected]",
"[email protected]": "pkg:maven/commons-beanutils/[email protected]",
"[email protected]": "pkg:maven/commons-codec/[email protected]",
"[email protected]": "pkg:maven/commons-codec/[email protected]",
"[email protected]": "pkg:maven/commons-collections/[email protected]",
"[email protected]": "pkg:maven/commons-digester/[email protected]",
"[email protected]": "pkg:maven/commons-discovery/[email protected]",
"[email protected]": "pkg:maven/commons-fileupload/[email protected]",
"[email protected]": "pkg:maven/org.apache/[email protected]",
"[email protected]": "pkg:maven/commons-httpclient/[email protected]",
"[email protected]": "pkg:maven/commons-io/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/commons-jelly-tags-fmt/[email protected]",
"[email protected]": "pkg:maven/commons-jelly-tags-xml/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/commons-lang/[email protected]",
"[email protected]": "pkg:maven/commons-lang/[email protected]",
"[email protected]": "pkg:maven/org.apache.commons.logging/[email protected]",
"[email protected]": "pkg:maven/org.apache.commons.logging/[email protected]",
"[email protected]": "pkg:maven/commons-logging/[email protected]",
"[email protected]": "pkg:maven/commons-pool/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.plugins/[email protected]",
"[email protected]": "pkg:maven/dom4j/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven.doxia/[email protected]",
"[email protected]": "pkg:maven/org.easymock/[email protected]",
"[email protected]": "pkg:maven/com.sun.solaris/[email protected]",
"[email protected]": "pkg:maven/example-java-app-gradle/[email protected]",
"[email protected]": "pkg:maven/net.sf.ezmorph/[email protected]",
"[email protected]": "pkg:maven/org.kohsuke/[email protected]",
"[email protected]": "pkg:maven/groovy-all/[email protected]",
"[email protected]": "pkg:maven/com.google.code.gson/[email protected]",
"guava@r06": "pkg:maven/com.google.guava/guava@r06",
"[email protected]": "pkg:maven/org.apache.httpcomponents/[email protected]",
"[email protected]": "pkg:maven/org.apache.httpcomponents/[email protected]",
"hudson-cli@": "pkg:maven/hudson-cli/hudson-cli",
"[email protected]": "pkg:maven/org.jvnet.hudson.main/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.main/[email protected]",
"[email protected]": "pkg:maven/j-interop/[email protected]",
"[email protected]": "pkg:maven/j-interopdeps/[email protected]",
"[email protected]": "pkg:maven/org.jaxen/[email protected]",
"[email protected]": "pkg:maven/jcaptcha-all/[email protected]",
"[email protected]": "pkg:maven/org.samba.jcifs/[email protected]",
"[email protected]": "pkg:maven/jfree/[email protected]",
"[email protected]": "pkg:maven/jfreechart/[email protected]",
"[email protected]": "pkg:maven/org.kohsuke.jinterop/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/jline/[email protected]",
"[email protected]": "pkg:maven/com.strangeberry.jmdns.tools.Main/[email protected]",
"[email protected]": "pkg:maven/org.jruby.ext.posix/[email protected]",
"[email protected]": "pkg:maven/com.sun.jna/[email protected]",
"[email protected]": "pkg:maven/jsch/[email protected]",
"[email protected]": "pkg:maven/json-lib/[email protected]",
"json@20200518": "pkg:maven/org.json/json@20200518",
"[email protected]": "pkg:maven/com.sun/[email protected]",
"jtidy@4aug2000r7-dev-hudson-1": "pkg:maven/jtidy/jtidy@4aug2000r7-dev-hudson-1",
"[email protected]": "pkg:maven/junit/[email protected]",
"[email protected]": "pkg:maven/kotlin-stdlib-common/[email protected]",
"[email protected]": "pkg:maven/kotlin-stdlib/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.libpam4j/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.libzfs/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.localizer/[email protected]",
"[email protected]": "pkg:maven/log4j/[email protected]",
"[email protected]": "pkg:maven/logkit/[email protected]",
"[email protected]": "pkg:maven/com.sun/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.main/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.main/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.main/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven.reporting/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/org.jenkins-ci.plugins/[email protected]",
"[email protected]": "pkg:maven/com.squareup.okhttp3/[email protected]",
"[email protected]": "pkg:maven/com.squareup.okio/[email protected]",
"[email protected]": "pkg:maven/org.apache.oro/[email protected]",
"[email protected]": "pkg:maven/org.codehaus.plexus/[email protected]",
"[email protected]": "pkg:maven/org.codehaus.plexus/[email protected]",
"[email protected]": "pkg:maven/org.codehaus.plexus/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.main/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.robust-http-client/[email protected]",
"[email protected]": "pkg:maven/sdk/[email protected]",
"[email protected]": "pkg:maven/net.java.sezpoz/[email protected]",
"slave@": "pkg:maven/slave/slave",
"[email protected]": "pkg:maven/slide-webdavlib/[email protected]",
"[email protected]": "pkg:maven/org.springframework.bundle.spring.aop/[email protected]",
"[email protected]": "pkg:maven/org.springframework/[email protected]",
"[email protected]": "pkg:maven/org.springframework.bundle.spring.context/[email protected]",
"[email protected]": "pkg:maven/org.springframework/[email protected]",
"[email protected]": "pkg:maven/spring-dao/[email protected]",
"[email protected]": "pkg:maven/spring-jdbc/[email protected]",
"[email protected]": "pkg:maven/org.springframework/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.plugins/[email protected]",
"[email protected]": "pkg:maven/org.kohsuke.stapler/[email protected]",
"[email protected]": "pkg:maven/org.kohsuke.stapler/[email protected]",
"[email protected]": "pkg:maven/org.kohsuke.stapler/[email protected]",
"[email protected]": "pkg:maven/stax-api/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.plugins/[email protected]",
"[email protected]": "pkg:maven/svnkit/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/org.jvnet/[email protected]",
"[email protected]": "pkg:maven/org.kohsuke/[email protected]",
"trilead-ssh2@build212-hudson-5": "pkg:maven/org.jvnet.hudson/trilead-ssh2@build212-hudson-5",
"txw2@20070624": "pkg:maven/txw2/txw2@20070624",
"[email protected]": "pkg:maven/org.apache.maven.wagon/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven.wagon/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven.wagon/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven.wagon/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven.wagon/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven.wagon/[email protected]",
"[email protected]": "pkg:maven/org.apache.maven.wagon/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.winp/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson.winstone/[email protected]",
"[email protected]": "pkg:maven/wstx-asl/[email protected]",
"[email protected]": "pkg:maven/xml-im-exporter/[email protected]",
"[email protected]": "pkg:maven/xpp3/[email protected]",
"[email protected]": "pkg:maven/xpp3_min/[email protected]",
"[email protected]": "pkg:maven/org.jvnet.hudson/[email protected]",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM anchore/test_images@sha256:10008791acbc5866de04108746a02a0c4029ce3a4400a9b3dad45d7f2245f9da

0 comments on commit 007b034

Please sign in to comment.