fix: unicode output in cyclonedx-json format (#1420)

This commit is contained in:
Keith Zantow 2022-12-23 08:37:47 -05:00 committed by GitHub
parent b125ea83ba
commit e1e489a284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 65 additions and 40 deletions

6
go.mod
View File

@ -3,7 +3,7 @@ module github.com/anchore/syft
go 1.18 go 1.18
require ( require (
github.com/CycloneDX/cyclonedx-go v0.7.0 github.com/CycloneDX/cyclonedx-go v0.7.1-0.20221222100750-41a1ac565cce
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/acobaugh/osrelease v0.1.0 github.com/acobaugh/osrelease v0.1.0
github.com/adrg/xdg v0.3.3 github.com/adrg/xdg v0.3.3
@ -37,7 +37,7 @@ require (
github.com/spf13/cobra v1.6.0 github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.13.0 github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.0 github.com/stretchr/testify v1.8.1
github.com/vifraa/gopom v0.1.0 github.com/vifraa/gopom v0.1.0
github.com/wagoodman/go-partybus v0.0.0-20210627031916-db1f5573bbc5 github.com/wagoodman/go-partybus v0.0.0-20210627031916-db1f5573bbc5
github.com/wagoodman/go-progress v0.0.0-20200731105512-1020f39e6240 github.com/wagoodman/go-progress v0.0.0-20200731105512-1020f39e6240
@ -241,7 +241,7 @@ require (
github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spiffe/go-spiffe/v2 v2.1.1 // indirect github.com/spiffe/go-spiffe/v2 v2.1.1 // indirect
github.com/stretchr/objx v0.4.0 // indirect github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect github.com/subosito/gotenv v1.4.1 // indirect
github.com/sylabs/sif/v2 v2.8.1 // indirect github.com/sylabs/sif/v2 v2.8.1 // indirect
github.com/sylabs/squashfs v0.6.1 // indirect github.com/sylabs/squashfs v0.6.1 // indirect

10
go.sum
View File

@ -153,8 +153,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CycloneDX/cyclonedx-go v0.7.0 h1:jNxp8hL7UpcvPDFXjY+Y1ibFtsW+e5zyF9QoSmhK/zg= github.com/CycloneDX/cyclonedx-go v0.7.1-0.20221222100750-41a1ac565cce h1:o5r3msApzvtE5LhcMkxWaKernD/PK0HpMccu7ywBj5Q=
github.com/CycloneDX/cyclonedx-go v0.7.0/go.mod h1:W5Z9w8pTTL+t+yG3PCiFRGlr8PUlE0pGWzKSJbsyXkg= github.com/CycloneDX/cyclonedx-go v0.7.1-0.20221222100750-41a1ac565cce/go.mod h1:XURd0m8zvnLE5aIRqg6JOVRl7qZ/pWBtuFa9EHjQwFc=
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
@ -1875,8 +1875,9 @@ github.com/stretchr/objx v0.0.0-20180129172003-8a3f7159479f/go.mod h1:HFkY916IF+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@ -1889,8 +1890,9 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=

View File

@ -9,6 +9,7 @@ import (
"github.com/sergi/go-diff/diffmatchpatch" "github.com/sergi/go-diff/diffmatchpatch"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/anchore/go-testutils" "github.com/anchore/go-testutils"
"github.com/anchore/stereoscope/pkg/filetree" "github.com/anchore/stereoscope/pkg/filetree"
@ -35,7 +36,7 @@ func FromSnapshot() ImageOption {
} }
} }
func AssertEncoderAgainstGoldenImageSnapshot(t *testing.T, format sbom.Format, sbom sbom.SBOM, testImage string, updateSnapshot bool, redactors ...redactor) { func AssertEncoderAgainstGoldenImageSnapshot(t *testing.T, format sbom.Format, sbom sbom.SBOM, testImage string, updateSnapshot bool, json bool, redactors ...redactor) {
var buffer bytes.Buffer var buffer bytes.Buffer
// grab the latest image contents and persist // grab the latest image contents and persist
@ -61,15 +62,17 @@ func AssertEncoderAgainstGoldenImageSnapshot(t *testing.T, format sbom.Format, s
expected = r(expected) expected = r(expected)
} }
// assert that the golden file snapshot matches the actual contents if json {
if !bytes.Equal(expected, actual) { require.JSONEq(t, string(expected), string(actual))
} else if !bytes.Equal(expected, actual) {
// assert that the golden file snapshot matches the actual contents
dmp := diffmatchpatch.New() dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(string(expected), string(actual), true) diffs := dmp.DiffMain(string(expected), string(actual), true)
t.Errorf("mismatched output:\n%s", dmp.DiffPrettyText(diffs)) t.Errorf("mismatched output:\n%s", dmp.DiffPrettyText(diffs))
} }
} }
func AssertEncoderAgainstGoldenSnapshot(t *testing.T, format sbom.Format, sbom sbom.SBOM, updateSnapshot bool, redactors ...redactor) { func AssertEncoderAgainstGoldenSnapshot(t *testing.T, format sbom.Format, sbom sbom.SBOM, updateSnapshot bool, json bool, redactors ...redactor) {
var buffer bytes.Buffer var buffer bytes.Buffer
err := format.Encode(&buffer, sbom) err := format.Encode(&buffer, sbom)
@ -90,7 +93,9 @@ func AssertEncoderAgainstGoldenSnapshot(t *testing.T, format sbom.Format, sbom s
expected = r(expected) expected = r(expected)
} }
if !bytes.Equal(expected, actual) { if json {
require.JSONEq(t, string(expected), string(actual))
} else if !bytes.Equal(expected, actual) {
dmp := diffmatchpatch.New() dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(string(expected), string(actual), true) diffs := dmp.DiffMain(string(expected), string(actual), true)
t.Logf("len: %d\nexpected: %s", len(expected), expected) t.Logf("len: %d\nexpected: %s", len(expected), expected)

View File

@ -13,7 +13,7 @@ func encoder(output io.Writer, s sbom.SBOM) error {
bom := cyclonedxhelpers.ToFormatModel(s) bom := cyclonedxhelpers.ToFormatModel(s)
enc := cyclonedx.NewBOMEncoder(output, cyclonedx.BOMFileFormatJSON) enc := cyclonedx.NewBOMEncoder(output, cyclonedx.BOMFileFormatJSON)
enc.SetPretty(true) enc.SetPretty(true)
enc.SetEscapeHTML(false)
err := enc.Encode(bom) err := enc.Encode(bom)
return err return err
} }

View File

@ -15,6 +15,7 @@ func TestCycloneDxDirectoryEncoder(t *testing.T) {
Format(), Format(),
testutils.DirectoryInput(t), testutils.DirectoryInput(t),
*updateCycloneDx, *updateCycloneDx,
true,
cycloneDxRedactor, cycloneDxRedactor,
) )
} }
@ -26,19 +27,20 @@ func TestCycloneDxImageEncoder(t *testing.T) {
testutils.ImageInput(t, testImage), testutils.ImageInput(t, testImage),
testImage, testImage,
*updateCycloneDx, *updateCycloneDx,
true,
cycloneDxRedactor, cycloneDxRedactor,
) )
} }
func cycloneDxRedactor(s []byte) []byte { func cycloneDxRedactor(s []byte) []byte {
serialPattern := regexp.MustCompile(`urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`) serialPattern := regexp.MustCompile(`urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`)
rfc3339Pattern := regexp.MustCompile(`([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))`) rfc3339Pattern := regexp.MustCompile(`([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))`)
sha256Pattern := regexp.MustCompile(`sha256:[A-Fa-f0-9]{64}`) sha256Pattern := regexp.MustCompile(`sha256:[A-Fa-f0-9]{64}`)
for _, pattern := range []*regexp.Regexp{serialPattern, rfc3339Pattern, sha256Pattern} { for _, pattern := range []*regexp.Regexp{serialPattern, rfc3339Pattern, sha256Pattern} {
s = pattern.ReplaceAll(s, []byte("redacted")) s = pattern.ReplaceAll(s, []byte(""))
} }
// the bom-ref will be autogenerated every time, the value here should not be directly tested in snapshot tests // the bom-ref will be autogenerated every time, the value here should not be directly tested in snapshot tests
s = regexp.MustCompile(` "bom-ref": .*\n`).ReplaceAll(s, []byte("")) s = regexp.MustCompile(`\s+"bom-ref":\s*"[^"]+",?\n`).ReplaceAll(s, []byte(""))
return s return s
} }

View File

@ -1,10 +1,10 @@
{ {
"bomFormat": "CycloneDX", "bomFormat": "CycloneDX",
"specVersion": "1.4", "specVersion": "1.4",
"serialNumber": "urn:uuid:cfd602eb-022b-4a61-84d4-50d34612bd84", "serialNumber": "urn:uuid:0b628da1-274e-4c24-821c-f9452f37db54",
"version": 1, "version": 1,
"metadata": { "metadata": {
"timestamp": "2022-11-07T09:11:21-05:00", "timestamp": "2022-12-22T18:33:51-05:00",
"tools": [ "tools": [
{ {
"vendor": "anchore", "vendor": "anchore",

View File

@ -1,10 +1,10 @@
{ {
"bomFormat": "CycloneDX", "bomFormat": "CycloneDX",
"specVersion": "1.4", "specVersion": "1.4",
"serialNumber": "urn:uuid:ced49687-6384-48fa-a930-ef83a258bf77", "serialNumber": "urn:uuid:542fc1a1-81ac-4b76-b9e2-8e6b9d8c840a",
"version": 1, "version": 1,
"metadata": { "metadata": {
"timestamp": "2022-11-07T09:11:21-05:00", "timestamp": "2022-12-22T18:33:51-05:00",
"tools": [ "tools": [
{ {
"vendor": "anchore", "vendor": "anchore",
@ -13,7 +13,7 @@
} }
], ],
"component": { "component": {
"bom-ref": "522dc6b135a55bb4", "bom-ref": "ffd645a093c0fe70",
"type": "container", "type": "container",
"name": "user-image-input", "name": "user-image-input",
"version": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368" "version": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368"
@ -53,7 +53,7 @@
}, },
{ {
"name": "syft:location:0:layerID", "name": "syft:location:0:layerID",
"value": "sha256:fb6beecb75b39f4bb813dbf177e501edd5ddb3e69bb45cedeb78c676ee1b7a59" "value": "sha256:62058900d4ce269c900160b8dd255fe310c3a459dda236d041102fa070f84406"
}, },
{ {
"name": "syft:location:0:path", "name": "syft:location:0:path",
@ -83,7 +83,7 @@
}, },
{ {
"name": "syft:location:0:layerID", "name": "syft:location:0:layerID",
"value": "sha256:319b588ce64253a87b533c8ed01cf0025e0eac98e7b516e12532957e1244fdec" "value": "sha256:623ad97366f39ae279f1925673cdacb4851ddf2e3266f04e63010ec080a098c1"
}, },
{ {
"name": "syft:location:0:path", "name": "syft:location:0:path",

View File

@ -15,6 +15,7 @@ func TestCycloneDxDirectoryEncoder(t *testing.T) {
Format(), Format(),
testutils.DirectoryInput(t), testutils.DirectoryInput(t),
*updateCycloneDx, *updateCycloneDx,
false,
cycloneDxRedactor, cycloneDxRedactor,
) )
} }
@ -26,6 +27,7 @@ func TestCycloneDxImageEncoder(t *testing.T) {
testutils.ImageInput(t, testImage), testutils.ImageInput(t, testImage),
testImage, testImage,
*updateCycloneDx, *updateCycloneDx,
false,
cycloneDxRedactor, cycloneDxRedactor,
) )
} }

View File

@ -15,6 +15,7 @@ func TestSPDXJSONDirectoryEncoder(t *testing.T) {
Format(), Format(),
testutils.DirectoryInput(t), testutils.DirectoryInput(t),
*updateSpdxJson, *updateSpdxJson,
true,
spdxJsonRedactor, spdxJsonRedactor,
) )
} }
@ -26,6 +27,7 @@ func TestSPDXJSONImageEncoder(t *testing.T) {
testutils.ImageInput(t, testImage, testutils.FromSnapshot()), testutils.ImageInput(t, testImage, testutils.FromSnapshot()),
testImage, testImage,
*updateSpdxJson, *updateSpdxJson,
true,
spdxJsonRedactor, spdxJsonRedactor,
) )
} }
@ -39,17 +41,18 @@ func TestSPDXRelationshipOrder(t *testing.T) {
s, s,
testImage, testImage,
*updateSpdxJson, *updateSpdxJson,
true,
spdxJsonRedactor, spdxJsonRedactor,
) )
} }
func spdxJsonRedactor(s []byte) []byte { func spdxJsonRedactor(s []byte) []byte {
// each SBOM reports the time it was generated, which is not useful during snapshot testing // each SBOM reports the time it was generated, which is not useful during snapshot testing
s = regexp.MustCompile(`"created": .*`).ReplaceAll(s, []byte("redacted")) s = regexp.MustCompile(`"created":\s+"[^"]*",?`).ReplaceAll(s, []byte(""))
// each SBOM reports a unique documentNamespace when generated, this is not useful for snapshot testing // each SBOM reports a unique documentNamespace when generated, this is not useful for snapshot testing
s = regexp.MustCompile(`"documentNamespace": .*`).ReplaceAll(s, []byte("redacted")) s = regexp.MustCompile(`"documentNamespace":\s+"[^"]*",?`).ReplaceAll(s, []byte(""))
// the license list will be updated periodically, the value here should not be directly tested in snapshot tests // the license list will be updated periodically, the value here should not be directly tested in snapshot tests
return regexp.MustCompile(`"licenseListVersion": .*`).ReplaceAll(s, []byte("redacted")) return regexp.MustCompile(`"licenseListVersion":\s+"[^"]*",?`).ReplaceAll(s, []byte(""))
} }

View File

@ -3,14 +3,14 @@
"dataLicense": "CC0-1.0", "dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT", "SPDXID": "SPDXRef-DOCUMENT",
"name": "/some/path", "name": "/some/path",
"documentNamespace": "https://anchore.com/syft/dir/some/path-116e86ba-a976-48ed-909d-9278807ee7fe", "documentNamespace": "https://anchore.com/syft/dir/some/path-e13c8924-4bbc-42f8-bd30-4e1554472d62",
"creationInfo": { "creationInfo": {
"licenseListVersion": "3.19", "licenseListVersion": "3.19",
"creators": [ "creators": [
"Organization: Anchore, Inc", "Organization: Anchore, Inc",
"Tool: syft-v0.42.0-bogus" "Tool: syft-v0.42.0-bogus"
], ],
"created": "2022-12-21T03:39:05Z", "created": "2022-12-22T23:33:52Z",
"comment": "" "comment": ""
}, },
"packages": [ "packages": [

View File

@ -3,14 +3,14 @@
"dataLicense": "CC0-1.0", "dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT", "SPDXID": "SPDXRef-DOCUMENT",
"name": "user-image-input", "name": "user-image-input",
"documentNamespace": "https://anchore.com/syft/image/user-image-input-006b9b96-66f1-4de3-897f-6583b4358c87", "documentNamespace": "https://anchore.com/syft/image/user-image-input-a1cc9d58-830a-4a4b-9dcd-f41ea3001216",
"creationInfo": { "creationInfo": {
"licenseListVersion": "3.19", "licenseListVersion": "3.19",
"creators": [ "creators": [
"Organization: Anchore, Inc", "Organization: Anchore, Inc",
"Tool: syft-v0.42.0-bogus" "Tool: syft-v0.42.0-bogus"
], ],
"created": "2022-12-21T03:39:05Z", "created": "2022-12-22T23:33:53Z",
"comment": "" "comment": ""
}, },
"packages": [ "packages": [

View File

@ -3,14 +3,14 @@
"dataLicense": "CC0-1.0", "dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT", "SPDXID": "SPDXRef-DOCUMENT",
"name": "user-image-input", "name": "user-image-input",
"documentNamespace": "https://anchore.com/syft/image/user-image-input-552a9cfc-49ee-4706-81cb-723fd7146b4f", "documentNamespace": "https://anchore.com/syft/image/user-image-input-fc663ee3-0f9b-402e-827f-3f29aeff164e",
"creationInfo": { "creationInfo": {
"licenseListVersion": "3.19", "licenseListVersion": "3.19",
"creators": [ "creators": [
"Organization: Anchore, Inc", "Organization: Anchore, Inc",
"Tool: syft-v0.42.0-bogus" "Tool: syft-v0.42.0-bogus"
], ],
"created": "2022-12-21T03:39:05Z", "created": "2022-12-22T23:33:53Z",
"comment": "" "comment": ""
}, },
"packages": [ "packages": [

View File

@ -19,6 +19,7 @@ func TestSPDXTagValueDirectoryEncoder(t *testing.T) {
Format(), Format(),
testutils.DirectoryInput(t), testutils.DirectoryInput(t),
*updateSpdxTagValue, *updateSpdxTagValue,
false,
spdxTagValueRedactor, spdxTagValueRedactor,
) )
} }
@ -30,6 +31,7 @@ func TestSPDXTagValueImageEncoder(t *testing.T) {
testutils.ImageInput(t, testImage, testutils.FromSnapshot()), testutils.ImageInput(t, testImage, testutils.FromSnapshot()),
testImage, testImage,
*updateSpdxTagValue, *updateSpdxTagValue,
false,
spdxTagValueRedactor, spdxTagValueRedactor,
) )
} }
@ -63,6 +65,7 @@ func TestSPDXJSONSPDXIDs(t *testing.T) {
}, },
}, },
*updateSpdxTagValue, *updateSpdxTagValue,
false,
spdxTagValueRedactor, spdxTagValueRedactor,
) )
} }
@ -76,6 +79,7 @@ func TestSPDXRelationshipOrder(t *testing.T) {
s, s,
testImage, testImage,
*updateSpdxTagValue, *updateSpdxTagValue,
false,
spdxTagValueRedactor, spdxTagValueRedactor,
) )
} }

View File

@ -19,6 +19,7 @@ func TestDirectoryEncoder(t *testing.T) {
testutils.AssertEncoderAgainstGoldenSnapshot(t, testutils.AssertEncoderAgainstGoldenSnapshot(t,
Format(), Format(),
testutils.DirectoryInput(t), testutils.DirectoryInput(t),
true,
*updateJson, *updateJson,
) )
} }
@ -29,6 +30,7 @@ func TestImageEncoder(t *testing.T) {
Format(), Format(),
testutils.ImageInput(t, testImage, testutils.FromSnapshot()), testutils.ImageInput(t, testImage, testutils.FromSnapshot()),
testImage, testImage,
true,
*updateJson, *updateJson,
) )
} }
@ -199,5 +201,6 @@ func TestEncodeFullJSONDocument(t *testing.T) {
Format(), Format(),
s, s,
*updateJson, *updateJson,
true,
) )
} }

View File

@ -9,7 +9,7 @@
"locations": [ "locations": [
{ {
"path": "/somefile-1.txt", "path": "/somefile-1.txt",
"layerID": "sha256:fb6beecb75b39f4bb813dbf177e501edd5ddb3e69bb45cedeb78c676ee1b7a59" "layerID": "sha256:62058900d4ce269c900160b8dd255fe310c3a459dda236d041102fa070f84406"
} }
], ],
"licenses": [ "licenses": [
@ -40,7 +40,7 @@
"locations": [ "locations": [
{ {
"path": "/somefile-2.txt", "path": "/somefile-2.txt",
"layerID": "sha256:319b588ce64253a87b533c8ed01cf0025e0eac98e7b516e12532957e1244fdec" "layerID": "sha256:623ad97366f39ae279f1925673cdacb4851ddf2e3266f04e63010ec080a098c1"
} }
], ],
"licenses": [], "licenses": [],
@ -64,11 +64,11 @@
], ],
"artifactRelationships": [], "artifactRelationships": [],
"source": { "source": {
"id": "1a678f111c8ddc66fd82687bb024e0dd6af61314404937a80e810c0cf317b796", "id": "6de18113d4a87f3503d13d10d1e69ebe2f5b41880aec96fb506b2113fd8df2f8",
"type": "image", "type": "image",
"target": { "target": {
"userInput": "user-image-input", "userInput": "user-image-input",
"imageID": "sha256:3c51b06feb0cda8ee62d0e3755ef2a8496a6b71f8a55b245f07f31c4bb813d31", "imageID": "sha256:fdd8b25b9402be0c8cf99e1edde6da614310d6bacd2e45a03781a3ef4a59025f",
"manifestDigest": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368", "manifestDigest": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368",
"mediaType": "application/vnd.docker.distribution.manifest.v2+json", "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"tags": [ "tags": [
@ -78,17 +78,17 @@
"layers": [ "layers": [
{ {
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"digest": "sha256:fb6beecb75b39f4bb813dbf177e501edd5ddb3e69bb45cedeb78c676ee1b7a59", "digest": "sha256:62058900d4ce269c900160b8dd255fe310c3a459dda236d041102fa070f84406",
"size": 22 "size": 22
}, },
{ {
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"digest": "sha256:319b588ce64253a87b533c8ed01cf0025e0eac98e7b516e12532957e1244fdec", "digest": "sha256:623ad97366f39ae279f1925673cdacb4851ddf2e3266f04e63010ec080a098c1",
"size": 16 "size":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iJsYXllcnMiLCJkaWZmX2lkcyI6WyJzaGEyNTY6NjIwNTg5MDBkNGNlMjY5YzkwMDE2MGI4ZGQyNTVmZTMxMGMzYTQ1OWRkYTIzNmQwNDExMDJmYTA3MGY4NDQwNiIsInNoYTI1Njo2MjNhZDk3MzY2ZjM5YWUyNzlmMTkyNTY3M2NkYWNiNDg1MWRkZjJlMzI2NmYwNGU2MzAxMGVjMDgwYTA5OGMxIl19fQ==",
"repoDigests": [], "repoDigests": [],
"architecture": "", "architecture": "",
"os": "" "os": ""

View File

@ -15,6 +15,7 @@ func TestTableEncoder(t *testing.T) {
testutils.AssertEncoderAgainstGoldenSnapshot(t, testutils.AssertEncoderAgainstGoldenSnapshot(t,
Format(), Format(),
testutils.DirectoryInput(t), testutils.DirectoryInput(t),
false,
*updateTableGoldenFiles, *updateTableGoldenFiles,
) )
} }

View File

@ -19,6 +19,7 @@ func TestFormatWithOption(t *testing.T) {
f, f,
testutils.DirectoryInput(t), testutils.DirectoryInput(t),
*updateTmpl, *updateTmpl,
false,
) )
} }

View File

@ -14,6 +14,7 @@ func TestTextDirectoryEncoder(t *testing.T) {
Format(), Format(),
testutils.DirectoryInput(t), testutils.DirectoryInput(t),
*updateTextEncoderGoldenFiles, *updateTextEncoderGoldenFiles,
false,
) )
} }
@ -24,5 +25,6 @@ func TestTextImageEncoder(t *testing.T) {
testutils.ImageInput(t, testImage, testutils.FromSnapshot()), testutils.ImageInput(t, testImage, testutils.FromSnapshot()),
testImage, testImage,
*updateTextEncoderGoldenFiles, *updateTextEncoderGoldenFiles,
false,
) )
} }