Skip to content

Commit

Permalink
Fix functional tests that do not validate (#111)
Browse files Browse the repository at this point in the history
* fix some test cases that do not pass schema validation

Signed-off-by: Matt Rutkowski <[email protected]>

* fix some test cases that do not pass schema validation

Signed-off-by: Matt Rutkowski <[email protected]>

---------

Signed-off-by: Matt Rutkowski <[email protected]>
  • Loading branch information
mrutkows authored Nov 8, 2024
1 parent df2e6c4 commit c56e9dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
23 changes: 21 additions & 2 deletions cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package cmd

// "github.com/iancoleman/orderedmap"
import (
"bytes"
"encoding/json"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
// }
7 changes: 6 additions & 1 deletion test/cyclonedx/cdx-1-5-license-choice-variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"components": [
{
"name": "Variant 1: id field only",
"type": "library",
"licenses": [
{
"license": {
Expand All @@ -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"
Expand All @@ -33,6 +36,7 @@
},
{
"name": "Variant 4: id and text (attachment)",
"type": "library",
"licenses": [
{
"license": {
Expand All @@ -49,6 +53,7 @@
},
{
"name": "Variant 5: id and properties",
"type": "library",
"licenses": [
{
"license": {
Expand Down

0 comments on commit c56e9dc

Please sign in to comment.