Skip to content

Commit

Permalink
Retrieve target from directory sbom types in addition to image types (#…
Browse files Browse the repository at this point in the history
…440)

* Retrieve target from directory sbom types in addition to image types

Signed-off-by: Samuel Dacanay <[email protected]>

* add dir sbom ingest test

Signed-off-by: Alex Goodman <[email protected]>

Co-authored-by: Alex Goodman <[email protected]>
  • Loading branch information
dakaneye and wagoodman authored Oct 6, 2021
1 parent 6fe9fc2 commit 2dd4131
Show file tree
Hide file tree
Showing 3 changed files with 1,132 additions and 7 deletions.
2 changes: 2 additions & 0 deletions grype/pkg/syft_json_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func (s *syftSource) UnmarshalJSON(b []byte) error {
s.Type = unpacker.Type

switch s.Type {
case "directory":
s.Target = string(unpacker.Target[:])
case "image":
var payload source.ImageMetadata
if err := json.Unmarshal(unpacker.Target, &payload); err != nil {
Expand Down
16 changes: 9 additions & 7 deletions test/cli/sbom_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"testing"
)

const sbomLocation = "./test-fixtures/sbom-ubuntu-20.04--pruned.json"

func TestSBOMInput_AsArgument(t *testing.T) {
workingDirectory, err := os.Getwd()
if err != nil {
Expand All @@ -19,12 +17,16 @@ func TestSBOMInput_AsArgument(t *testing.T) {
path string
}{
{
"absolute path",
path.Join(workingDirectory, sbomLocation),
"absolute path - image scan",
path.Join(workingDirectory, "./test-fixtures/sbom-ubuntu-20.04--pruned.json"),
},
{
"relative path - image scan",
"./test-fixtures/sbom-ubuntu-20.04--pruned.json",
},
{
"relative path",
sbomLocation,
"directory scan",
"./test-fixtures/sbom-grype-source.json",
},
}

Expand Down Expand Up @@ -54,7 +56,7 @@ func TestSBOMInput_AsArgument(t *testing.T) {
func TestSBOMInput_FromStdin(t *testing.T) {
cmd := getGrypeCommand(t)

sbom, err := os.Open(sbomLocation)
sbom, err := os.Open("./test-fixtures/sbom-ubuntu-20.04--pruned.json")
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit 2dd4131

Please sign in to comment.