Skip to content

Commit

Permalink
Merge pull request Checkmarx#6809 from Dstklr/feature/add-platform-fi…
Browse files Browse the repository at this point in the history
…eld-to-sarif-format

feat(kics): add platform field to sarif format
  • Loading branch information
asofsilva authored Dec 14, 2023
2 parents f57c4a6 + 84360a0 commit 302f2ca
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
10 changes: 9 additions & 1 deletion e2e/fixtures/schemas/result-sarif-required.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,15 @@
]
},
"message": {
"$ref": "#/definitions/text_object"
"type": "object",
"additionalProperties": true,
"required": ["text"],
"properties": {
"text": {
"type": "string",
"minLength": 1
}
}
},
"locations": {
"type": "array",
Expand Down
10 changes: 9 additions & 1 deletion e2e/fixtures/schemas/result-sarif.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,15 @@
]
},
"message": {
"$ref": "#/definitions/text_object"
"type": "object",
"additionalProperties": true,
"required": ["text"],
"properties": {
"text": {
"type": "string",
"minLength": 1
}
}
},
"locations": {
"type": "array",
Expand Down
8 changes: 6 additions & 2 deletions pkg/report/model/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type ruleCISMetadata struct {
}

type sarifMessage struct {
Text string `json:"text"`
Text string `json:"text"`
MessageProperties sarifProperties `json:"properties,omitempty"`
}

type sarifComponentReference struct {
Expand Down Expand Up @@ -294,7 +295,10 @@ func (sr *sarifReport) BuildSarifIssue(issue *model.QueryResult) {
ResultRuleID: issue.QueryID,
ResultRuleIndex: ruleIndex,
ResultKind: kind,
ResultMessage: sarifMessage{Text: issue.Files[idx].KeyActualValue},
ResultMessage: sarifMessage{
Text: issue.Files[idx].KeyActualValue,
MessageProperties: sarifProperties{"platform": issue.Platform},
},
ResultLocations: []sarifLocation{
{
PhysicalLocation: sarifPhysicalLocation{
Expand Down
17 changes: 13 additions & 4 deletions pkg/report/model/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var sarifTests = []sarifTest{
ResultRuleID: "1",
ResultRuleIndex: 0,
ResultKind: "fail",
ResultMessage: sarifMessage{Text: "test"},
ResultMessage: sarifMessage{Text: "test", MessageProperties: sarifProperties{"platform": ""}},
ResultLocations: []sarifLocation{
{
PhysicalLocation: sarifPhysicalLocation{
Expand Down Expand Up @@ -193,7 +193,10 @@ var sarifTests = []sarifTest{
ResultRuleID: "1",
ResultRuleIndex: 0,
ResultKind: "fail",
ResultMessage: sarifMessage{Text: "test"},
ResultMessage: sarifMessage{
Text: "test",
MessageProperties: sarifProperties{"platform": ""},
},
ResultLocations: []sarifLocation{
{
PhysicalLocation: sarifPhysicalLocation{
Expand All @@ -207,7 +210,10 @@ var sarifTests = []sarifTest{
ResultRuleID: "1",
ResultRuleIndex: 0,
ResultKind: "fail",
ResultMessage: sarifMessage{Text: "test"},
ResultMessage: sarifMessage{
Text: "test",
MessageProperties: sarifProperties{"platform": ""},
},
ResultLocations: []sarifLocation{
{
PhysicalLocation: sarifPhysicalLocation{
Expand All @@ -221,7 +227,10 @@ var sarifTests = []sarifTest{
ResultRuleID: "2",
ResultRuleIndex: 1,
ResultKind: "informational",
ResultMessage: sarifMessage{Text: "test"},
ResultMessage: sarifMessage{
Text: "test",
MessageProperties: sarifProperties{"platform": ""},
},
ResultLocations: []sarifLocation{
{
PhysicalLocation: sarifPhysicalLocation{
Expand Down

0 comments on commit 302f2ca

Please sign in to comment.