Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
2 changes: 0 additions & 2 deletions internal/formats/github/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/anchore/packageurl-go"
"github.com/anchore/syft/internal"
"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/sbom"
"github.com/anchore/syft/syft/source"
Expand Down Expand Up @@ -148,7 +147,6 @@ func toGithubManifests(s *sbom.SBOM) Manifests {
func dependencyName(p pkg.Package) string {
purl, err := packageurl.FromString(p.PURL)
if err != nil {
log.Warnf("Invalid PURL for package: '%s' PURL: '%s' (%w)", p.Name, p.PURL, err)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log line seems unnecessary with the new warning that works for all formats

return ""
}
// don't use qualifiers for this
Expand Down
1 change: 0 additions & 1 deletion syft/pkg/cataloger/python/package_cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"

"github.com/anchore/syft/internal"

"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/pkg"

Expand Down
8 changes: 8 additions & 0 deletions syft/pkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ func (p *Package) OverrideID(id artifact.ID) {
}

func (p *Package) SetID() {
if p.Name == "" {
log.Warnf("%s: missing package name, that is necessary for further metadata extraction, such as CPEs and pURLs", p.FoundBy)
}

if p.Version == "" {
log.Warnf("%s: missing package version, that is necessary for further metadata extraction, such as CPEs and pURLs", p.FoundBy)
}

id, err := artifact.IDByHash(p)
if err != nil {
// TODO: what to do in this case?
Expand Down
12 changes: 10 additions & 2 deletions syft/pkg/python_package_metadata_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package pkg

import (
"github.com/anchore/syft/syft/linux"
"github.com/sergi/go-diff/diffmatchpatch"
"strings"
"testing"

"github.com/anchore/syft/syft/linux"
"github.com/sergi/go-diff/diffmatchpatch"

"github.com/go-test/deep"
)

Expand All @@ -16,6 +17,13 @@ func TestPythonPackageMetadata_pURL(t *testing.T) {
metadata PythonPackageMetadata
expected string
}{
// NOTE: making this case explicit since it happens for users
// with empty egg/wheel files
{
name: "without-name-and-version",
metadata: PythonPackageMetadata{},
expected: "pkg:pypi/",
},
{
name: "with vcs info",
metadata: PythonPackageMetadata{
Expand Down
37 changes: 37 additions & 0 deletions test/cli/package_missing_data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cli

import (
"fmt"
"strings"
"testing"

"github.com/anchore/syft/syft"
"github.com/stretchr/testify/assert"
)

func TestPackageMissingNameAndVersion(t *testing.T) {
formats := syft.FormatIDs()
commonAssertions := []traitAssertion{
func(tb testing.TB, _, stderr string, _ int) {
tb.Helper()
assert.Contains(tb, stderr, "python-package-cataloger: missing package name, that is necessary for further metadata extraction, such as CPEs and pURLs")
assert.Contains(tb, stderr, "python-package-cataloger: missing package version, that is necessary for further metadata extraction, such as CPEs and pURLs")
},
assertSuccessfulReturnCode,
}

for _, o := range formats {
t.Run(fmt.Sprintf("format:%s", o), func(t *testing.T) {
// TODO: does it make sense to add empty metadata for all catalogers?
cmd, stdout, stderr := runSyft(t, nil, "dir:./test-fixtures/image-pkg-coverage/pkgs/", "-o", string(o))
for _, traitFn := range commonAssertions {
traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode())
}
if t.Failed() {
t.Log("STDOUT:\n", stdout)
t.Log("STDERR:\n", stderr)
t.Log("COMMAND:", strings.Join(cmd.Args, " "))
}
})
}
}
2 changes: 1 addition & 1 deletion test/cli/packages_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestPackagesCmdFlags(t *testing.T) {
name: "squashed-scope-flag",
args: []string{"packages", "-o", "json", "-s", "squashed", coverageImage},
assertions: []traitAssertion{
assertPackageCount(32),
assertPackageCount(34),
assertSuccessfulReturnCode,
},
},
Expand Down
4 changes: 4 additions & 0 deletions test/integration/catalog_packages_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var imageOnlyTestCases = []testCase{
"requests": "2.22.0",
"somerequests": "3.22.0",
"someotherpkg": "3.19.0",
"brokenpkg": "",
"": "",
},
},
{
Expand Down Expand Up @@ -148,6 +150,8 @@ var dirOnlyTestCases = []testCase{
"requests": "2.22.0",
"somerequests": "3.22.0",
"someotherpkg": "3.19.0",
"brokenpkg": "",
"": "",
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Name: brokenpkg