diff --git a/models/tool.go b/models/tool.go index 73cd1eb..2325bf7 100644 --- a/models/tool.go +++ b/models/tool.go @@ -13,7 +13,8 @@ type driver struct { type rule struct { Id string `json:"id"` ShortDescription *textBlock `json:"shortDescription"` - HelpUri string `json:"helpUri"` + HelpUri string `json:"helpUri,omitempty"` + Help *textBlock `json:"help,omitempty"` Properties map[string]string `json:"properties,omitempty"` } @@ -45,6 +46,13 @@ func (rule *rule) WithHelpUri(helpUrl string) *rule { return rule } +func (rule *rule) WithHelp(helpText string) *rule { + rule.Help = &textBlock{ + Text: helpText, + } + return rule +} + func (rule *rule) WithProperties(properties map[string]string) *rule { rule.Properties = properties return rule diff --git a/test/run_stage_test.go b/test/run_stage_test.go index 41d7c2e..c9b5cce 100644 --- a/test/run_stage_test.go +++ b/test/run_stage_test.go @@ -2,9 +2,10 @@ package test import ( "encoding/json" - "github.com/stretchr/testify/assert" "testing" + "github.com/stretchr/testify/assert" + "github.com/owenrumney/go-sarif/models" ) @@ -68,3 +69,20 @@ func (rt *runTest) a_result_is_added_to_the_run() *runTest { rt.run.AddResultDetails(rule, result, resultLocation) return rt } + +func (rt *runTest) a_result_is_added_to_the_run_with_help_text() *runTest { + resultLocation := "/tmp/result/code" + + rule := rt.run.AddRule("AWS001"). + WithDescription("S3 Bucket has an ACL defined which allows public access."). + WithHelp("you can learn more about this check https://www.tfsec.dev/docs/aws/AWS001"). + WithProperties(map[string]string{"propertyName": "propertyValue"}) + + result := rt.run.AddResult(rule.Id). + WithLevel("error"). + WithMessage("Resource 'my_bucket' has an ACL which allows public access."). + WithLocationDetails(resultLocation, 1, 1) + + rt.run.AddResultDetails(rule, result, resultLocation) + return rt +} diff --git a/test/run_test.go b/test/run_test.go index 2bec1e4..2be709d 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -49,3 +49,14 @@ func Test_create_a_run_with_a_result_added(t *testing.T) { the_run_is_converted_to_a_string() then.the_json_string_representation_of_the_run_should_be(expected) } + +func Test_create_a_run_with_a_result_added_and_help_text_provided(t *testing.T) { + given, when, then := createNewRunTest(t) + + expected := `{"tool":{"driver":{"name":"tfsec","informationUri":"https://tfsec.dev","rules":[{"id":"AWS001","shortDescription":{"text":"S3 Bucket has an ACL defined which allows public access."},"help":{"text":"you can learn more about this check https://www.tfsec.dev/docs/aws/AWS001"},"properties":{"propertyName":"propertyValue"}}]}},"artifacts":[{"location":{"uri":"/tmp/result/code"}}],"results":[{"level":"error","message":{"text":"Resource 'my_bucket' has an ACL which allows public access."},"ruleId":"AWS001","ruleIndex":0,"locations":[{"physicalLocation":{"artifactLocation":{"uri":"/tmp/result/code","index":0},"region":{"startLine":1,"startColumn":1}}}]}]}` + + given.a_new_run_is_created() + when.a_result_is_added_to_the_run_with_help_text().and(). + the_run_is_converted_to_a_string() + then.the_json_string_representation_of_the_run_should_be(expected) +}