Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions syft/cataloger/java/archive_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,51 @@ func generateJavaBuildFixture(t *testing.T, fixturePath string) {
}
}

func TestSelectName(t *testing.T) {
tests := []struct {
desc string
manifest pkg.JavaManifest
archive archiveFilename
expected string
}{
{
desc: "name from Implementation-Title",
archive: archiveFilename{},
manifest: pkg.JavaManifest{
Name: "",
SpecTitle: "",
ImplTitle: "maven-wrapper",
},
expected: "maven-wrapper",
},
{
desc: "Implementation-Title does not override",
manifest: pkg.JavaManifest{
Name: "Foo",
SpecTitle: "",
ImplTitle: "maven-wrapper",
},
archive: archiveFilename{
fields: []map[string]string{
{"name": "omg"},
},
},
expected: "omg",
},
}

for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
result := selectName(&test.manifest, test.archive)

if result != test.expected {
t.Errorf("mismatch in names: '%s' != '%s'", result, test.expected)
}
})
}

}

func TestParseJar(t *testing.T) {
tests := []struct {
fixture string
Expand Down
6 changes: 6 additions & 0 deletions syft/cataloger/java/java_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func selectName(manifest *pkg.JavaManifest, filenameObj archiveFilename) string
// Jenkins...
name = manifest.Extra["Extension-Name"]
}

// in situations where we hit this point and no name was
// determined, look at the Implementation-Title
if name == "" && manifest.ImplTitle != "" {
name = manifest.ImplTitle
}
return name
}

Expand Down