Skip to content

Commit 75de64d

Browse files
authored
Add select CycloneDX v1.7 testcases to Go test (#142)
* Add select CycloneDX v1.7 testcases to Go test Signed-off-by: Matt Rutkowski <[email protected]> * Add select CycloneDX v1.7 testcases to Go test Signed-off-by: Matt Rutkowski <[email protected]> * Add select CycloneDX v1.7 testcases to Go test Signed-off-by: Matt Rutkowski <[email protected]> --------- Signed-off-by: Matt Rutkowski <[email protected]>
1 parent 664febc commit 75de64d

File tree

52 files changed

+2159
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2159
-72
lines changed

.vscode/launch.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"request": "launch",
6262
"mode": "debug",
6363
"program": "main.go", // "program": "${file}",
64-
"args": ["validate", "-i", "test/cyclonedx/cdx-1-5-mature-example-1.json"],
64+
"args": ["validate", "-i", "test/cyclonedx/1.5/cdx-1-5-mature-example-1.json"],
6565
"dlvFlags": ["--check-go-version=false"]
6666
},
6767
{
@@ -81,7 +81,7 @@
8181
"request": "launch",
8282
"mode": "debug",
8383
"program": "main.go", // "program": "${file}",
84-
"args": ["query", "-i", "test/cyclonedx/cdx-1-4-mature-example-1.json", "--select", "*", "--from", "metadata.component"],
84+
"args": ["query", "-i", "test/cyclonedx/1.4/cdx-1-4-mature-example-1.json", "--select", "*", "--from", "metadata.component"],
8585
"dlvFlags": ["--check-go-version=false"]
8686
},
8787
{
@@ -91,7 +91,7 @@
9191
"request": "launch",
9292
"mode": "debug",
9393
"program": "main.go", // "program": "${file}",
94-
"args": ["license", "list", "-i", "test/cyclonedx/cdx-1-3-license-list-complex.json", "--format", "json"],
94+
"args": ["license", "list", "-i", "test/cyclonedx/1.3/cdx-1-3-license-list-complex.json", "--format", "json"],
9595
"dlvFlags": ["--check-go-version=false"]
9696
},
9797
{
@@ -101,7 +101,7 @@
101101
"request": "launch",
102102
"mode": "debug",
103103
"program": "main.go", // "program": "${file}",
104-
"args": ["license", "list", "-i", "test/cyclonedx/cdx-1-3-license-list-complex.json", "--format", "json", "--summary"],
104+
"args": ["license", "list", "-i", "test/cyclonedx/1.3/cdx-1-3-license-list-complex.json", "--format", "json", "--summary"],
105105
"dlvFlags": ["--check-go-version=false"]
106106
},
107107
{
@@ -111,7 +111,7 @@
111111
"request": "launch",
112112
"mode": "debug",
113113
"program": "main.go", // "program": "${file}",
114-
"args": ["license", "list", "-i", "test/cyclonedx/cdx-1-3-license-list-complex.json", "--where", "usage-policy=needs-review|deny|UNDEFINED"],
114+
"args": ["license", "list", "-i", "test/cyclonedx/1.3/cdx-1-3-license-list-complex.json", "--where", "usage-policy=needs-review|deny|UNDEFINED"],
115115
"dlvFlags": ["--check-go-version=false"]
116116
},
117117
{
@@ -121,7 +121,7 @@
121121
"request": "launch",
122122
"mode": "debug",
123123
"program": "main.go", // "program": "${file}",
124-
"args": ["diff", "-i", "test/cyclonedx/cdx-1-4-mature-example-1.json", "--input-revision", "test/diff/cdx-1-4-mature-example-1-delta.json"],
124+
"args": ["diff", "-i", "test/cyclonedx/1.4/cdx-1-4-mature-example-1.json", "--input-revision", "test/diff/cdx-1-4-mature-example-1-delta.json"],
125125
"dlvFlags": ["--check-go-version=false"]
126126
},
127127
]

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,13 +1606,13 @@ This example effectively extracts the first-order package manifest from the SBOM
16061606
In this example, only the `--from` clause is needed to select an object. The `--select` clause is omitted which is equivalent to using the "select all" wildcard character `*` which returns all fields and values from the `component` object.
16071607

16081608
```bash
1609-
./sbom-utility query -i test/cyclonedx/cdx-1-4-mature-example-1.json --from metadata.component
1609+
./sbom-utility query -i test/cyclonedx/1.4/cdx-1-4-mature-example-1.json --from metadata.component
16101610
```
16111611

16121612
is equivalent to using the wildcard character (which may need to be enclosed in single or double quotes depending on your shell):
16131613

16141614
```bash
1615-
./sbom-utility query -i test/cyclonedx/cdx-1-4-mature-example-1.json --select '*' --from metadata.component -q
1615+
./sbom-utility query -i test/cyclonedx/1.4/cdx-1-4-mature-example-1.json --select '*' --from metadata.component -q
16161616
```
16171617

16181618
```json
@@ -1647,7 +1647,7 @@ is equivalent to using the wildcard character (which may need to be enclosed in
16471647
In this example, the `--from` clause references the top-level `metadata.supplier` object.
16481648

16491649
```bash
1650-
./sbom-utility query -i test/cyclonedx/cdx-1-4-mature-example-1.json --from metadata.supplier -q
1650+
./sbom-utility query -i test/cyclonedx/1.4/cdx-1-4-mature-example-1.json --from metadata.supplier -q
16511651
```
16521652

16531653
```json
@@ -1686,7 +1686,7 @@ The result, which also uses the `--indent 2` flag:
16861686
In this example, the `--from` filter will return the entire JSON components array.
16871687

16881688
```bash
1689-
./sbom-utility query -i test/cyclonedx/cdx-1-4-mature-example-1.json --from components -q
1689+
./sbom-utility query -i test/cyclonedx/1.4/cdx-1-4-mature-example-1.json --from components -q
16901690
```
16911691

16921692
```json
@@ -1736,7 +1736,7 @@ In this example, the `--from` filter will return the entire JSON components arra
17361736
In this example, the `--where` filter will be applied to a set of `properties` results to only include entries that match the specified regex.
17371737

17381738
```bash
1739-
./sbom-utility query -i test/cyclonedx/cdx-1-4-mature-example-1.json --from metadata.properties --where name=urn:example.com:classification -q
1739+
./sbom-utility query -i test/cyclonedx/1.4/cdx-1-4-mature-example-1.json --from metadata.properties --where name=urn:example.com:classification -q
17401740
```
17411741

17421742
```json
@@ -1751,7 +1751,7 @@ In this example, the `--where` filter will be applied to a set of `properties` r
17511751
additionally, you can apply a `--select` clause to simply obtain the matching entry's `value`:
17521752

17531753
```bash
1754-
./sbom-utility query -i test/cyclonedx/cdx-1-4-mature-example-1.json --select value --from metadata.properties --where name=urn:example.com:classification -q
1754+
./sbom-utility query -i test/cyclonedx/1.4/cdx-1-4-mature-example-1.json --select value --from metadata.properties --where name=urn:example.com:classification -q
17551755
```
17561756

17571757
```json
@@ -1935,7 +1935,7 @@ This example shows a few entries of the JSON output that exhibit the three types
19351935
This example shows the default text output from using the summary flag:
19361936

19371937
```bash
1938-
./sbom-utility license list -i test/cyclonedx/cdx-1-3-license-list.json --summary -q
1938+
./sbom-utility license list -i test/cyclonedx/1.3/cdx-1-3-license-list.json --summary -q
19391939
```
19401940

19411941
```bash
@@ -1973,7 +1973,7 @@ The list command results can be filtered using the `--where` flag using the colu
19731973
The following example shows filtering of component licenses using the `license-type` column where the license was described as a `name` value:
19741974

19751975
```bash
1976-
./sbom-utility license list -i test/cyclonedx/cdx-1-3-license-list.json --summary --where license-type=name -q
1976+
./sbom-utility license list -i test/cyclonedx/1.3/cdx-1-3-license-list.json --summary --where license-type=name -q
19771977
```
19781978

19791979
```bash
@@ -1990,7 +1990,7 @@ needs-review name UFL ACME Application pkg:app/[email protected]
19901990
In another example, the list is filtered by the `usage-policy` where the value is `needs-review`:
19911991

19921992
```bash
1993-
./sbom-utility license list -i test/cyclonedx/cdx-1-3-license-list.json --summary --where usage-policy=needs-review -q
1993+
./sbom-utility license list -i test/cyclonedx/1.3/cdx-1-3-license-list.json --summary --where usage-policy=needs-review -q
19941994
```
19951995

19961996
```bash
@@ -2141,7 +2141,7 @@ Currently, all `resource list` command results are sorted by resource `type` the
21412141
#### Example: resource list
21422142

21432143
```bash
2144-
./sbom-utility resource list -i test/cyclonedx/cdx-1-3-resource-list.json -q
2144+
./sbom-utility resource list -i test/cyclonedx/1.3/cdx-1-3-resource-list.json -q
21452145
```
21462146

21472147
```bash
@@ -2167,7 +2167,7 @@ service:example.com/myservices/foo service Foo
21672167
This example uses the `type` flag to specific `service`. The other valid type is `component`. Future versions of CycloneDX schema will include more resource types such as "ml" (machine learning) or "tool".
21682168

21692169
```bash
2170-
./sbom-utility resource list -i test/cyclonedx/cdx-1-3-resource-list.json --type service -q
2170+
./sbom-utility resource list -i test/cyclonedx/1.3/cdx-1-3-resource-list.json --type service -q
21712171
```
21722172

21732173
```bash
@@ -2180,15 +2180,15 @@ service Foo Foo service service:example.com/myservi
21802180
**Note** The results would be equivalent to using the `--where` filter:
21812181

21822182
```bash
2183-
./sbom-utility resource list -i test/cyclonedx/cdx-1-3-resource-list.json --where "resource-type=service" -q
2183+
./sbom-utility resource list -i test/cyclonedx/1.3/cdx-1-3-resource-list.json --where "resource-type=service" -q
21842184
```
21852185

21862186
##### Example: list with `name` regex match
21872187

21882188
This example uses the `where` filter on the `name` field. In this case we supply an exact "startswith" regex. for the `name` filter.
21892189

21902190
```bash
2191-
./sbom-utility resource list -i test/cyclonedx/cdx-1-3-resource-list.json --where "name=Library A" -q
2191+
./sbom-utility resource list -i test/cyclonedx/1.3/cdx-1-3-resource-list.json --where "name=Library A" -q
21922192
```
21932193

21942194
```bash
@@ -2532,7 +2532,7 @@ If you wish to build binaries for all supported combinations of `GOOS` and `GOAR
25322532
Developers can run using the current source code in their local branch using `go run main.go`. For example:
25332533

25342534
```bash
2535-
go run main.go validate -i test/cyclonedx/cdx-1-4-mature-example-1.json
2535+
go run main.go validate -i test/cyclonedx/1.4/cdx-1-4-mature-example-1.json
25362536
```
25372537

25382538
### Debugging
@@ -2553,7 +2553,7 @@ In order to see global variables while debugging a specific configuration, you c
25532553
"request": "launch",
25542554
"mode": "debug",
25552555
"program": "main.go",
2556-
"args": ["validate", "-i", "test/cyclonedx/cdx-1-3-min-required.json","-t"]
2556+
"args": ["validate", "-i", "test/cyclonedx/1.3/cdx-1-3-min-required.json","-t"]
25572557
},
25582558
```
25592559

cmd/component_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ import (
3232

3333
// Test "resource list" command
3434
const (
35-
// test/cyclonedx/cdx-1-3-resource-list.json
35+
// test/cyclonedx/1.3/cdx-1-3-resource-list.json
3636
TEST_COMPONENT_LIST_CDX_1_3 = TEST_RESOURCE_LIST_CDX_1_3
37-
// test/cyclonedx/cdx-1-5-mature-example-1.json
38-
TEST_COMPONENT_LIST_CDX_1_5_MATURE = TEST_CDX_1_5_MATURE_EXAMPLE_1_BASE
3937
// test/cyclonedx/1.6/cdx-1-6-valid-cbom-full-1.6.json
4038
TEST_COMPONENT_LIST_CDX_1_6_CBOM = TEST_CDX_1_6_CRYPTO_BOM
4139
// test/cyclonedx/1.6/cdx-1-6-valid-mlbom-environmental-considerations.json
@@ -172,9 +170,7 @@ func TestComponentListCdx13Markdown(t *testing.T) {
172170
// -------------------------------------------
173171

174172
func TestComponentListCdx15MatureCsv(t *testing.T) {
175-
ti := NewComponentTestInfoBasic(TEST_COMPONENT_LIST_CDX_1_5_MATURE, FORMAT_CSV, nil)
176-
//ti.ListSummary = false
177-
//ti.WhereClause = "version=2.0"
173+
ti := NewComponentTestInfoBasic(TEST_CDX_1_5_MATURE_EXAMPLE_1_BASE, FORMAT_CSV, nil)
178174
ti.ResultExpectedLineCount = 5 // title + 3 data + EOF LF
179175
ti.ResultLineContainsValuesAtLineNum = 3
180176
ti.ResultLineContainsValues = []string{"sample"}
@@ -197,7 +193,7 @@ func TestComponentListCdx16MachineLearningBOMCsv(t *testing.T) {
197193
innerTestComponentList(t, ti, COMPONENT_TEST_DEFAULT_FLAGS)
198194
}
199195

200-
// ./sbom-utility component list -i test/cyclonedx/cdx-1-3-resource-list.json --where "number-licenses=0" --quiet --format=txt
196+
// ./sbom-utility component list -i test/cyclonedx/1.3/cdx-1-3-resource-list.json --where "number-licenses=0" --quiet --format=txt
201197
//
202198
// library Library NoLicense 1.0.0 Library "NoLicense" description. pkg:lib/[email protected] 0 0
203199
func TestComponentListCdx13WhereNumLicensesCsv(t *testing.T) {

cmd/license_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ import (
3131

3232
const (
3333
// Test "license list" command
34-
TEST_LICENSE_LIST_CDX_1_3 = "test/cyclonedx/cdx-1-3-license-list.json"
35-
TEST_LICENSE_LIST_CDX_1_3_NONE_FOUND = "test/cyclonedx/cdx-1-3-license-list-none-found.json"
36-
TEST_LICENSE_LIST_CDX_1_4_NONE_FOUND = "test/cyclonedx/cdx-1-4-license-list-none-found.json"
37-
TEST_LICENSE_LIST_CDX_1_5_LICENSE_CHOICE_VARIANTS = "test/cyclonedx/cdx-1-5-license-choice-variants.json"
38-
TEST_LICENSE_LIST_CDX_1_5_MATURE_EXAMPLE_1 = "test/cyclonedx/cdx-1-5-mature-example-1.json"
39-
40-
TEST_LICENSE_LIST_TEXT_CDX_1_4_INVALID_LICENSE_ID = "test/cyclonedx/cdx-1-4-license-policy-invalid-spdx-id.json"
41-
TEST_LICENSE_LIST_TEXT_CDX_1_4_INVALID_LICENSE_NAME = "test/cyclonedx/cdx-1-4-license-policy-invalid-license-name.json"
42-
TEST_LICENSE_LIST_CDX_1_4_LICENSE_EXPRESSION_IN_NAME = "test/cyclonedx/cdx-1-4-license-expression-in-name.json"
34+
TEST_LICENSE_LIST_CDX_1_3 = "test/cyclonedx/1.3/cdx-1-3-license-list.json"
35+
TEST_LICENSE_LIST_CDX_1_3_NONE_FOUND = "test/cyclonedx/1.3/cdx-1-3-license-list-none-found.json"
36+
TEST_LICENSE_LIST_CDX_1_4_NONE_FOUND = "test/cyclonedx/1.4/cdx-1-4-license-list-none-found.json"
37+
TEST_LICENSE_LIST_CDX_1_5_LICENSE_CHOICE_VARIANTS = "test/cyclonedx/1.5/cdx-1-5-license-choice-variants.json"
38+
TEST_LICENSE_LIST_CDX_1_5_MATURE_EXAMPLE_1 = TEST_CDX_1_5_MATURE_EXAMPLE_1_BASE
39+
40+
TEST_LICENSE_LIST_TEXT_CDX_1_4_INVALID_LICENSE_ID = "test/cyclonedx/1.4/cdx-1-4-license-policy-invalid-spdx-id.json"
41+
TEST_LICENSE_LIST_TEXT_CDX_1_4_INVALID_LICENSE_NAME = "test/cyclonedx/1.4/cdx-1-4-license-policy-invalid-license-name.json"
42+
TEST_LICENSE_LIST_CDX_1_4_LICENSE_EXPRESSION_IN_NAME = "test/cyclonedx/1.4/cdx-1-4-license-expression-in-name.json"
4343
)
4444

4545
type LicenseTestInfo struct {
@@ -360,7 +360,7 @@ func TestLicenseListTextCdx15WherePURLTypeIsNPM(t *testing.T) {
360360
// Test custom marshal of CDXLicense (empty CDXAttachment)
361361
func TestLicenseListCdx13JsonEmptyAttachment(t *testing.T) {
362362
lti := NewLicenseTestInfo(
363-
"test/cyclonedx/cdx-1-3-license-list-no-attachment.json",
363+
"test/cyclonedx/1.3/cdx-1-3-license-list-no-attachment.json",
364364
FORMAT_JSON,
365365
false)
366366
lti.ResultExpectedLineCount = 37

cmd/resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import (
3333

3434
const (
3535
// Test "resource list" command
36-
TEST_RESOURCE_LIST_CDX_1_3 = "test/cyclonedx/cdx-1-3-resource-list.json"
37-
TEST_RESOURCE_LIST_CDX_1_3_NONE_FOUND = "test/cyclonedx/cdx-1-3-resource-list-none-found.json"
36+
TEST_RESOURCE_LIST_CDX_1_3 = "test/cyclonedx/1.3/cdx-1-3-resource-list.json"
37+
TEST_RESOURCE_LIST_CDX_1_3_NONE_FOUND = "test/cyclonedx/1.3/cdx-1-3-resource-list-none-found.json"
3838
TEST_RESOURCE_LIST_CDX_1_4_SAAS_1 = "examples/cyclonedx/SaaSBOM/apigateway-microservices-datastores/bom.json"
3939
)
4040

cmd/validate.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ func LoadCompileSchemaDependencies(
244244
if err != nil {
245245
return
246246
}
247+
} else {
248+
getLogger().Warningf("No schema dependencies found. bomSchemaInstance: %v", bomSchemaInstance)
247249
}
248250
return
249251
}
@@ -342,7 +344,7 @@ func Validate(writer io.Writer, persistentFlags utils.PersistentCommandFlags, va
342344
// If the BOM schema has $refs to other schemas, attempt to load and compile
343345
// them from those included as built-in resources
344346
jsonBOMSchema, errLoadCompile = LoadCompileSchemaDependencies(jsonBOMSchemaLoader, bom.SchemaInfo, bom.SchemaInfo.Dependencies)
345-
if err != nil {
347+
if errLoadCompile != nil {
346348
return INVALID, bom, schemaErrors, errLoadCompile
347349
}
348350
}

0 commit comments

Comments
 (0)