Skip to content
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: SPDX tag value version selector #2665

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmd/syft/internal/options/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package options
import (
"github.com/anchore/clio"
"github.com/anchore/syft/syft/format"
"github.com/anchore/syft/syft/format/spdxtagvalue"
"github.com/anchore/syft/syft/sbom"
)

Expand Down Expand Up @@ -41,9 +42,10 @@ func (o Format) Encoders() ([]sbom.FormatEncoder, error) {
return format.EncodersConfig{
Template: o.Template.config(),
SyftJSON: o.SyftJSON.config(),
SPDXJSON: o.SPDXJSON.config(format.AllVersions), // we support multiple versions, not just a single version
CyclonedxJSON: o.CyclonedxJSON.config(format.AllVersions), // we support multiple versions, not just a single version
CyclonedxXML: o.CyclonedxXML.config(format.AllVersions), // we support multiple versions, not just a single version
SPDXJSON: o.SPDXJSON.config(format.AllVersions), // we support multiple versions, not just a single version
SPDXTagValue: spdxtagvalue.EncoderConfig{Version: format.AllVersions}, // we support multiple versions, not just a single version
CyclonedxJSON: o.CyclonedxJSON.config(format.AllVersions), // we support multiple versions, not just a single version
CyclonedxXML: o.CyclonedxXML.config(format.AllVersions), // we support multiple versions, not just a single version
}.Encoders()
}

Expand Down
37 changes: 37 additions & 0 deletions test/cli/all_formats_expressible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,40 @@ func TestAllFormatsExpressible(t *testing.T) {
})
}
}

func Test_formatVersionsExpressible(t *testing.T) {
tests := []struct {
format string
assertion traitAssertion
}{
{
format: "spdx@2.1",
assertion: assertInOutput("SPDXVersion: SPDX-2.1"),
},
{
format: "spdx@2.2",
assertion: assertInOutput("SPDXVersion: SPDX-2.2"),
},
{
format: "spdx@2.3",
assertion: assertInOutput("SPDXVersion: SPDX-2.3"),
},
{
format: "spdx-json@2.2",
assertion: assertInOutput(`"spdxVersion":"SPDX-2.2"`),
},
{
format: "spdx-json@2.3",
assertion: assertInOutput(`"spdxVersion":"SPDX-2.3"`),
},
}

for _, test := range tests {
t.Run(test.format, func(t *testing.T) {
args := []string{"dir:./test-fixtures/image-pkg-coverage", "-o", test.format}
cmd, stdout, stderr := runSyft(t, nil, args...)
test.assertion(t, stdout, stderr, cmd.ProcessState.ExitCode())
logOutputOnFailure(t, cmd, stdout, stderr)
})
}
}