Skip to content

Commit

Permalink
Merge pull request Checkmarx#4437 from Checkmarx/tests/fix-e2e-bom-test
Browse files Browse the repository at this point in the history
feat(e2e): added custom JSON Schema Validation for BoM Results
  • Loading branch information
cxlucas authored Nov 2, 2021
2 parents 3d64e30 + 1bb321a commit b6b4af6
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
E2E_KICS_BINARY: ${{ steps.getbin.outputs.kics }}
E2E_KICS_QUERIES_PATH: ${{ steps.getbin.outputs.queries }}
run: |
go test "github.com/Checkmarx/kics/e2e" -json > results.json
go test "github.com/Checkmarx/kics/e2e" -timeout 1500s -json > results.json
- name: Generate E2E Report
if: always()
run: |
Expand Down
4 changes: 4 additions & 0 deletions e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func checkExpectedOutput(t *testing.T, tt *testcases.TestCase, argIndex int) {
if utils.Contains(resultsFormats, "json") {
utils.JSONSchemaValidation(t, jsonFileName, "result.json")
}
// Check result file (JSON including BoM)
if utils.Contains(resultsFormats, "json-bom") {
utils.JSONSchemaValidation(t, jsonFileName, "resultBoM.json")
}
// Check result file (GLSAST)
if utils.Contains(resultsFormats, "glsast") {
utils.JSONSchemaValidation(t, "gl-sast-"+jsonFileName, "result-gl-sast.json")
Expand Down
124 changes: 0 additions & 124 deletions e2e/fixtures/schemas/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,130 +247,6 @@
"items": {
"type": "string"
}
},
"bill_of_materials": {
"type": "array",
"items": {
"type": "object",
"required": [
"query_name",
"query_id",
"query_url",
"severity",
"platform",
"category",
"description",
"description_id",
"files"
],
"properties": {
"query_name": {
"type": "string"
},
"query_id": {
"type": "string",
"pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-4{1}[a-f0-9]{3}-[89ab]{1}[a-f0-9]{3}-[a-f0-9]{12}$"
},
"query_url": {
"type": "string",
"format": "uri"
},
"severity": {
"type": "string",
"const": "TRACE"
},
"platform": {
"type": "string",
"enum": [
"Common",
"Ansible",
"CloudFormation",
"Dockerfile",
"Kubernetes",
"OpenAPI",
"Terraform",
"AzureResourceManager"
]
},
"category": {
"type": "string",
"category": "Bill Of Materials"
},
"description": {
"type": "string",
"minLength": 1
},
"description_id": {
"type": "string",
"pattern": "^[a-f0-9]{8}$"
},
"files": {
"type": "array",
"items": {
"type": "object",
"required": [
"file_name",
"similarity_id",
"line",
"issue_type",
"search_key",
"search_line",
"search_value",
"expected_value",
"actual_value"
],
"properties": {
"file_name": {
"type": "string",
"oneOf": [
{
"pattern": "^(.)*(:)*(http:|https:|www\\.)(.)+$"
},
{
"pattern": "^([\\w\\-. ]+(\\\\|\\/))*([\\w\\-. ]+(\\\\|\\/).(.)*)$"
}
]
},
"similarity_id": {
"type": "string",
"pattern": "^[A-Fa-f0-9]{64}$"
},
"line": {
"type": "integer",
"minimum": 1
},
"issue_type": {
"type": "string",
"const": "BillOfMaterials"
},
"search_key": {
"type": "string",
"minLength": 0
},
"search_line": {
"type": "integer",
"minimum": 0
},
"search_value": {
"type": "string"
},
"expected_value": {
"type": "string"
},
"actual_value": {
"type": "string"
},
"value": {
"type": [
"string",
"null"
]
}
}
}
}
}
}
}
}
}
140 changes: 140 additions & 0 deletions e2e/fixtures/schemas/resultBoM.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"allOf": [
{
"$ref" : "result.json"
},
{
"type": "object",
"required": [
"bill_of_materials"
],
"properties": {
"bill_of_materials": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"query_name",
"query_id",
"query_url",
"severity",
"platform",
"category",
"description",
"description_id",
"files"
],
"properties": {
"query_name": {
"type": "string"
},
"query_id": {
"type": "string",
"pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-4{1}[a-f0-9]{3}-[89ab]{1}[a-f0-9]{3}-[a-f0-9]{12}$"
},
"query_url": {
"type": "string",
"format": "uri"
},
"severity": {
"type": "string",
"const": "TRACE"
},
"platform": {
"type": "string",
"enum": [
"Common",
"Ansible",
"CloudFormation",
"Dockerfile",
"Kubernetes",
"OpenAPI",
"Terraform",
"AzureResourceManager"
]
},
"category": {
"type": "string",
"category": "Bill Of Materials"
},
"description": {
"type": "string",
"minLength": 1
},
"description_id": {
"type": "string",
"pattern": "^[a-f0-9]{8}$"
},
"files": {
"type": "array",
"items": {
"type": "object",
"required": [
"file_name",
"similarity_id",
"line",
"issue_type",
"search_key",
"search_line",
"search_value",
"expected_value",
"actual_value"
],
"properties": {
"file_name": {
"type": "string",
"oneOf": [
{
"pattern": "^(.)*(:)*(http:|https:|www\\.)(.)+$"
},
{
"pattern": "^([\\w\\-. ]+(\\\\|\\/))*([\\w\\-. ]+(\\\\|\\/).(.)*)$"
}
]
},
"similarity_id": {
"type": "string",
"pattern": "^[A-Fa-f0-9]{64}$"
},
"line": {
"type": "integer",
"minimum": 1
},
"issue_type": {
"type": "string",
"const": "BillOfMaterials"
},
"search_key": {
"type": "string",
"minLength": 0
},
"search_line": {
"type": "integer",
"minimum": 0
},
"search_value": {
"type": "string"
},
"expected_value": {
"type": "string"
},
"actual_value": {
"type": "string"
},
"value": {
"type": [
"string",
"null"
]
}
}
}
}
}
}
}
}
}
]
}
2 changes: 1 addition & 1 deletion e2e/testcases/e2e-cli-050_scan_bill-of-materials.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() { //nolint
ExpectedResult: []ResultsValidation{
{
ResultsFile: "results",
ResultsFormats: []string{"json"},
ResultsFormats: []string{"json-bom"},
},
},
},
Expand Down

0 comments on commit b6b4af6

Please sign in to comment.