Skip to content

Commit

Permalink
Add the option to provide help text instead of uri
Browse files Browse the repository at this point in the history
  • Loading branch information
owenrumney committed Oct 27, 2020
1 parent 81ad3ed commit ddea5a5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
10 changes: 9 additions & 1 deletion models/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion test/run_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions test/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit ddea5a5

Please sign in to comment.