From 5f285ff028c09f67aa62338dc06fe8e5a6932936 Mon Sep 17 00:00:00 2001 From: Michael de Senna Date: Fri, 20 May 2022 08:39:21 -0400 Subject: [PATCH] fix: add missing Properties (#39) * test: expose missing Properties via failing test Signed-off-by: Mike de Senna * fix: add missing Properties Signed-off-by: Mike de Senna * test: rename to clarify what's being tested Signed-off-by: Mike de Senna * test: update testdata json + xml Signed-off-by: Mike de Senna * test: don't panic Signed-off-by: Mike de Senna * test: UPDATE_SNAPSHOTS=true make test Signed-off-by: Mike de Senna * Revert "test: UPDATE_SNAPSHOTS=true make test" This reverts commit 75c4a5fce050df541f3c359bd755f5ab8ef9245a. Signed-off-by: Mike de Senna * test: comment out xml until fixed, gen new snapshot Signed-off-by: Mike de Senna --- cyclonedx.go | 1 + cyclonedx_test.go | 11 +++++++++++ ...oundTripJSON-func1-valid-vulnerability.json | 18 ++++++++++++++++++ testdata/valid-vulnerability.json | 18 ++++++++++++++++++ testdata/valid-vulnerability.xml | 6 ++++++ 5 files changed, 54 insertions(+) diff --git a/cyclonedx.go b/cyclonedx.go index a265ef2..73f4809 100644 --- a/cyclonedx.go +++ b/cyclonedx.go @@ -626,6 +626,7 @@ type Vulnerability struct { Tools *[]Tool `json:"tools,omitempty" xml:"tools>tool,omitempty"` Analysis *VulnerabilityAnalysis `json:"analysis,omitempty" xml:"analysis,omitempty"` Affects *[]Affects `json:"affects,omitempty" xml:"affects>target,omitempty"` + Properties *[]Property `json:"properties,omitempty" xml:"properties>property,omitempty"` } type VulnerabilityAnalysis struct { diff --git a/cyclonedx_test.go b/cyclonedx_test.go index 3ced188..dd24ac1 100644 --- a/cyclonedx_test.go +++ b/cyclonedx_test.go @@ -217,3 +217,14 @@ func TestLicenses_UnmarshalXML(t *testing.T) { err = xml.Unmarshal([]byte("expressionValue"), licenses) assert.Error(t, err) } + +func TestVulnerability_Properties(t *testing.T) { + // GIVEN + properties := []Property{} + vuln := Vulnerability{ + Properties: &properties, + } + + // EXPECT + assert.Equal(t, 0, len(*vuln.Properties)) +} diff --git a/testdata/snapshots/cyclonedx-go-TestRoundTripJSON-func1-valid-vulnerability.json b/testdata/snapshots/cyclonedx-go-TestRoundTripJSON-func1-valid-vulnerability.json index 4062fe4..9258923 100644 --- a/testdata/snapshots/cyclonedx-go-TestRoundTripJSON-func1-valid-vulnerability.json +++ b/testdata/snapshots/cyclonedx-go-TestRoundTripJSON-func1-valid-vulnerability.json @@ -118,6 +118,24 @@ } ] } + ], + "properties": [ + { + "name": "Foo", + "value": "Bar" + }, + { + "name": "Foo", + "value": "You" + }, + { + "name": "Foo", + "value": "Two" + }, + { + "name": "Bar", + "value": "Foo" + } ] } ] diff --git a/testdata/valid-vulnerability.json b/testdata/valid-vulnerability.json index c4065f6..701152f 100644 --- a/testdata/valid-vulnerability.json +++ b/testdata/valid-vulnerability.json @@ -116,6 +116,24 @@ } ] } + ], + "properties": [ + { + "name": "Foo", + "value": "Bar" + }, + { + "name": "Foo", + "value": "You" + }, + { + "name": "Foo", + "value": "Two" + }, + { + "name": "Bar", + "value": "Foo" + } ] } ] diff --git a/testdata/valid-vulnerability.xml b/testdata/valid-vulnerability.xml index 46b4448..cb6ad19 100644 --- a/testdata/valid-vulnerability.xml +++ b/testdata/valid-vulnerability.xml @@ -116,6 +116,12 @@ +