-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: in some cases, try to use pom info to guess name and version to …
…top level jar (#2080) Otherwise, small renames like 'hudson-war-2.2.1.war' to 'hudson.war', would cause syft to incorrectly catolog the archive. Signed-off-by: Will Murphy <will.murphy@anchore.com>
- Loading branch information
1 parent
cfebae2
commit 51d38f8
Showing
3 changed files
with
91 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package integration | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/source" | ||
) | ||
|
||
func TestWarCatalogedCorrectlyIfRenamed(t *testing.T) { | ||
// install hudson-war@2.2.1 and renames the file to `/hudson.war` | ||
sbom, _ := catalogFixtureImage(t, "image-java-virtualpath-regression", source.SquashedScope, nil) | ||
|
||
badPURL := "pkg:maven/hudson/hudson@2.2.1" | ||
goodPURL := "pkg:maven/org.jvnet.hudson.main/hudson-war@2.2.1" | ||
foundCorrectPackage := false | ||
badVirtualPath := "/hudson.war:org.jvnet.hudson.main:hudson-war" | ||
goodVirtualPath := "/hudson.war" | ||
for _, p := range sbom.Artifacts.Packages.Sorted() { | ||
if p.Type == pkg.JavaPkg && strings.Contains(p.Name, "hudson") { | ||
assert.NotEqual(t, badPURL, p.PURL, "must not find bad purl %q", badPURL) | ||
virtPath := "" | ||
if meta, ok := p.Metadata.(pkg.JavaMetadata); ok { | ||
virtPath = meta.VirtualPath | ||
if p.PURL == goodPURL && virtPath == goodVirtualPath { | ||
foundCorrectPackage = true | ||
} | ||
} | ||
assert.NotEqual(t, badVirtualPath, virtPath, "must not find bad virtual path %q", badVirtualPath) | ||
} | ||
} | ||
assert.True(t, foundCorrectPackage, "must find correct package, but did not") | ||
} |
7 changes: 7 additions & 0 deletions
7
test/integration/test-fixtures/image-java-virtualpath-regression/Dockerfile
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM alpine:latest | ||
|
||
RUN wget https://repo1.maven.org/maven2/org/jvnet/hudson/main/hudson-war/2.2.1/hudson-war-2.2.1.war | ||
|
||
RUN mv hudson-war-2.2.1.war hudson.war | ||
|
||
|