-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: in some cases, try to use pom info to guess name and version to top level jar #2080
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f347fb0
initial failing test
willmurphyscode 44df88f
passes initial test
willmurphyscode 714d208
only trust lonely pom.xml if filename is prefix of artifact id
willmurphyscode 09bdd84
extract name and version guessing
willmurphyscode 37337b5
linter
willmurphyscode 1f37909
Account for having mismatched count of pom.xml and pom.properties
willmurphyscode 878b5a4
remove todo
willmurphyscode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe rename
selectName
to something more specific likeselectNameFromManifest
(same for the version function) -- the upside is that you can write aselectNameAndVersion
wrapper that is called here and pushes some of this lower level logic to another function, and the existing tests for selectName don't really need to get modified from a logic sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! I think I'll do this as a follow up.