From c56e9dc70ec75956a35eea38c5e77307118bf218 Mon Sep 17 00:00:00 2001 From: Matt Rutkowski Date: Fri, 8 Nov 2024 08:02:35 -0600 Subject: [PATCH] Fix functional tests that do not validate (#111) * fix some test cases that do not pass schema validation Signed-off-by: Matt Rutkowski * fix some test cases that do not pass schema validation Signed-off-by: Matt Rutkowski --------- Signed-off-by: Matt Rutkowski --- cmd/validate.go | 23 +++++++++++++++++-- .../cdx-1-5-license-choice-variants.json | 7 +++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cmd/validate.go b/cmd/validate.go index 5a72ed25..590c3e2c 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -18,7 +18,6 @@ package cmd -// "github.com/iancoleman/orderedmap" import ( "bytes" "encoding/json" @@ -31,7 +30,7 @@ import ( "github.com/CycloneDX/sbom-utility/schema" "github.com/CycloneDX/sbom-utility/utils" "github.com/spf13/cobra" - "github.com/xeipuuv/gojsonschema" + "github.com/xeipuuv/gojsonschema" // TODO: switch to: https://github.com/santhosh-tekuri/jsonschema ) const ( @@ -377,3 +376,23 @@ func validateCustom(document *schema.BOM, policyConfig *schema.LicensePolicyConf return VALID, nil } + +// func isJSONSchema(filePath string) (isSchema bool, err error) { +// isSchema = false +// file, err := os.Open(filePath) +// if err != nil { +// return +// } +// defer file.Close() +// // decode +// decoder := json.NewDecoder(file) +// var jsonData map[string]interface{} +// err = decoder.Decode(&jsonData) +// if err != nil { +// return +// } +// // if schema tag present then likely a schema file (for now) +// _, hasSchema := jsonData["$schema"] +// isSchema = hasSchema +// return +// } diff --git a/test/cyclonedx/cdx-1-5-license-choice-variants.json b/test/cyclonedx/cdx-1-5-license-choice-variants.json index a26e28ff..afe537a7 100644 --- a/test/cyclonedx/cdx-1-5-license-choice-variants.json +++ b/test/cyclonedx/cdx-1-5-license-choice-variants.json @@ -5,6 +5,7 @@ "components": [ { "name": "Variant 1: id field only", + "type": "library", "licenses": [ { "license": { @@ -15,16 +16,18 @@ }, { "name": "Variant 2: name field only", + "type": "library", "licenses": [ { "license": { - "id": "MIT" + "name": "MIT" } } ] }, { "name": "Variant 3: expression only", + "type": "library", "licenses": [ { "expression": "MIT OR Apache-2.0" @@ -33,6 +36,7 @@ }, { "name": "Variant 4: id and text (attachment)", + "type": "library", "licenses": [ { "license": { @@ -49,6 +53,7 @@ }, { "name": "Variant 5: id and properties", + "type": "library", "licenses": [ { "license": {