github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/test/integration/regression_java_virtualpath_test.go (about) 1 package integration 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 9 "github.com/anchore/syft/syft/pkg" 10 "github.com/anchore/syft/syft/source" 11 ) 12 13 func TestWarCatalogedCorrectlyIfRenamed(t *testing.T) { 14 // install hudson-war@2.2.1 and renames the file to `/hudson.war` 15 sbom, _ := catalogFixtureImage(t, "image-java-virtualpath-regression", source.SquashedScope, nil) 16 17 badPURL := "pkg:maven/hudson/hudson@2.2.1" 18 goodPURL := "pkg:maven/org.jvnet.hudson.main/hudson-war@2.2.1" 19 foundCorrectPackage := false 20 badVirtualPath := "/hudson.war:org.jvnet.hudson.main:hudson-war" 21 goodVirtualPath := "/hudson.war" 22 for _, p := range sbom.Artifacts.Packages.Sorted() { 23 if p.Type == pkg.JavaPkg && strings.Contains(p.Name, "hudson") { 24 assert.NotEqual(t, badPURL, p.PURL, "must not find bad purl %q", badPURL) 25 virtPath := "" 26 if meta, ok := p.Metadata.(pkg.JavaMetadata); ok { 27 virtPath = meta.VirtualPath 28 if p.PURL == goodPURL && virtPath == goodVirtualPath { 29 foundCorrectPackage = true 30 } 31 } 32 assert.NotEqual(t, badVirtualPath, virtPath, "must not find bad virtual path %q", badVirtualPath) 33 } 34 } 35 assert.True(t, foundCorrectPackage, "must find correct package, but did not") 36 }