Skip to content

Commit

Permalink
Merge pull request Checkmarx#4575 from Checkmarx/tests/e2e-sonarqube-…
Browse files Browse the repository at this point in the history
…template

feat(e2e): add tests to validate sonaqube reports
  • Loading branch information
cxlucas authored Dec 2, 2021
2 parents 1518de9 + 3ecc71d commit bd1e07a
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
4 changes: 4 additions & 0 deletions e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func checkExpectedOutput(t *testing.T, tt *testcases.TestCase, argIndex int) {
if utils.Contains(resultsFormats, "glsast") {
utils.JSONSchemaValidation(t, "gl-sast-"+jsonFileName, "result-gl-sast.json")
}
// Check result file (SONARQUBE)
if utils.Contains(resultsFormats, "sonarqube") {
utils.JSONSchemaValidation(t, "sonarqube-"+jsonFileName, "result-sonarqube.json")
}
// Check result file (SARIF)
if utils.Contains(resultsFormats, "sarif") {
utils.JSONSchemaValidation(t, tt.Args.ExpectedResult[argIndex].ResultsFile+".sarif", "result-sarif.json")
Expand Down
58 changes: 58 additions & 0 deletions e2e/fixtures/schemas/result-sonarqube.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"type": "object",
"required": [
"issues"
],
"properties": {
"issues": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"engineId",
"ruleId",
"severity",
"type",
"primaryLocation"
],
"properties": {
"engineId": {
"type": "string",
"minLength": 1
},
"ruleId": {
"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}$"
},
"severity": {
"type": "string",
"enum": [
"INFO",
"MINOR",
"MAJOR",
"CRITICAL"
]
},
"type": {
"type": "string",
"enum": [
"VULNERABILITY",
"CODE_SMELL"
]
},
"primaryLocation": {
"$ref" : "sonarqubeLocations.json"
},
"secondaryLocations": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "sonarqubeLocations.json"
}
}
}
}
}
}
}
30 changes: 30 additions & 0 deletions e2e/fixtures/schemas/sonarqubeLocations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "object",
"required": [
"message",
"filePath",
"textRange"
],
"properties": {
"message": {
"type": "string",
"minLength": 1
},
"filePath": {
"type": "string",
"pattern": "^([\\w\\-. ]+(\\\\|\\/))*([\\w\\-. ]+(\\\\|\\/).(.)*)$"
},
"textRange": {
"type": "object",
"required": [
"startLine"
],
"properties": {
"startLine": {
"type": "integer",
"minimum": 1
}
}
}
}
}
4 changes: 2 additions & 2 deletions e2e/testcases/e2e-cli-031_scan_report-formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ func init() { //nolint
Args: args{
Args: []cmdArgs{
[]string{"scan", "--output-path", "output", "--output-name", "E2E_CLI_031_RESULT",
"--report-formats", "json,SARIF,glsast,Html",
"--report-formats", "json,SARIF,glsast,Html,SonarQUBE",
"-q", "../assets/queries", "-p", "fixtures/samples/terraform.tf"},
},
ExpectedResult: []ResultsValidation{
{
ResultsFile: "E2E_CLI_031_RESULT",
ResultsFormats: []string{"json", "sarif", "glsast", "html"},
ResultsFormats: []string{"json", "sarif", "glsast", "html", "sonarqube"},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ func init() { //nolint
Args: args{
Args: []cmdArgs{
[]string{"scan", "--output-path", "output", "--output-name", "E2E_CLI_040_RESULT",
"--report-formats", "json,sarif,glsast,html",
"--report-formats", "json,sarif,glsast,html,sonarqube",
"-q", "../assets/queries", "-p", "fixtures/samples/positive.yaml"},
},
ExpectedResult: []ResultsValidation{
{
ResultsFile: "E2E_CLI_040_RESULT",
ResultsFormats: []string{"json", "sarif", "glsast", "html"},
ResultsFormats: []string{"json", "sarif", "glsast", "html", "sonarqube"},
},
},
},
Expand Down

0 comments on commit bd1e07a

Please sign in to comment.