Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor output writer #514

Merged
merged 53 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b62cdee
Add Sast and Review tests
attiasas Sep 21, 2023
9fe0e79
add sast test, fix other jas
attiasas Sep 21, 2023
213885a
start adding review tests
attiasas Sep 21, 2023
bb45375
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Sep 27, 2023
cf521d3
done output tests
attiasas Sep 27, 2023
9e12379
done tests implementation, start combine writer
attiasas Sep 28, 2023
e7f823a
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Sep 28, 2023
55359f4
fix tests
attiasas Sep 28, 2023
9fcc04f
combine Jas output
attiasas Sep 28, 2023
e1d5a1c
combine more
attiasas Sep 28, 2023
da4f7bb
more combine
attiasas Oct 1, 2023
31ee4f4
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Oct 1, 2023
a743ed6
rename subTitleDepth
attiasas Oct 3, 2023
b3f0a3c
combine more
attiasas Oct 3, 2023
96cbf22
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Oct 3, 2023
3040fda
combine more
attiasas Oct 3, 2023
007822e
combine more
attiasas Oct 4, 2023
2c3ffaf
finish markdown table
attiasas Oct 4, 2023
648f50e
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Oct 4, 2023
5d217ee
tidy
attiasas Oct 4, 2023
55e06f0
done combine implementations
attiasas Oct 5, 2023
b5457f1
done merge
attiasas Oct 5, 2023
25f72be
combine sast tests
attiasas Oct 5, 2023
cdfd14e
combine iac tests
attiasas Oct 5, 2023
845b917
combine applicable tests
attiasas Oct 5, 2023
a2d580c
finish combine review comment content
attiasas Oct 5, 2023
1d6d3a1
fix static test
attiasas Oct 5, 2023
1fac667
combine more, add tests for summary structure
attiasas Oct 8, 2023
7828e24
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Oct 8, 2023
07fe11c
fix merge
attiasas Oct 8, 2023
6437b98
done content tests
attiasas Oct 8, 2023
ed1ed43
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Oct 8, 2023
1d82c6b
add tests to comment content filter
attiasas Oct 8, 2023
35a32a6
cleanup
attiasas Oct 8, 2023
b8b4a82
fix scan all pull requests tests
attiasas Oct 9, 2023
7bd8dcd
start fix scan pull request
attiasas Oct 9, 2023
b438381
fix tests
attiasas Oct 9, 2023
6bdb0d1
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Oct 9, 2023
c77c9fc
finish all output writer tests
attiasas Oct 9, 2023
fa8142c
start adjust content format, spaces and new lines
attiasas Oct 9, 2023
196b149
fix tests
attiasas Oct 9, 2023
5f2072a
fix all tests
attiasas Oct 10, 2023
8d3c082
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Oct 10, 2023
8953f81
fix tests
attiasas Oct 10, 2023
e2b188d
fix tests
attiasas Oct 10, 2023
d578f57
fix pip tests
attiasas Oct 10, 2023
618bf91
fix
attiasas Oct 10, 2023
75fadb3
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Oct 11, 2023
2d45ff2
fix merge
attiasas Oct 11, 2023
5d0698c
remove unused
attiasas Oct 11, 2023
ed92fd2
Merge remote-tracking branch 'upstream/dev' into add_sast_and_review_…
attiasas Oct 15, 2023
f0cce5a
review changes
attiasas Oct 16, 2023
96ca263
remove comments
attiasas Oct 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Sast and Review tests
  • Loading branch information
attiasas committed Sep 21, 2023
commit b62cdee81e717c33468ca735a61f3f4d1fefb029
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230921113452-0414290c7deb
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,8 @@ github.com/jfrog/froggit-go v1.14.2 h1:55x1anQtaiARlSBMVT59aFU6Mmx90tpcvvAuuPsZm
github.com/jfrog/froggit-go v1.14.2/go.mod h1:0jRAaZZusaFFnITosmx6CA60SKryuoaCasJyUrP/c1s=
github.com/jfrog/gofrog v1.3.0 h1:o4zgsBZE4QyDbz2M7D4K6fXPTBJht+8lE87mS9bw7Gk=
github.com/jfrog/gofrog v1.3.0/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
github.com/jfrog/jfrog-cli-core/v2 v2.43.3 h1:aZN+ZP2vIBBw2+U9F/iQ4Q2USmfXcxB8yN755azvjQo=
github.com/jfrog/jfrog-cli-core/v2 v2.43.3/go.mod h1:DKTOX9TsPkyI68GM4XdDTD7XDr+tOBqeK70DZZmu+4Q=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230921113452-0414290c7deb h1:XZwpeMkPPlaRvqqdPTZYdz+y5H9s19kYNEAHSp+j6x4=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230921113452-0414290c7deb/go.mod h1:DKTOX9TsPkyI68GM4XdDTD7XDr+tOBqeK70DZZmu+4Q=
github.com/jfrog/jfrog-client-go v1.32.3 h1:B2M8Gu8EMrokbHWPPDgN1b7YRWwf0oe746epvQASK6c=
github.com/jfrog/jfrog-client-go v1.32.3/go.mod h1:UewnwkIf/77HzBgwCPzOHZCK6V/Nw5/JwdzN/tRb4aU=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
Expand Down
115 changes: 115 additions & 0 deletions utils/outputwriter/outputwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,118 @@ func testGetLicensesTableContent(t *testing.T, writer OutputWriter) {
expected = "\n| License1 | Comp1 1.0 | Dep1 2.0 |\n| License2 | Comp2 2.0 | Dep2 3.0 |"
assert.Equal(t, expected, result)
}

func TestMarkAsQuote(t *testing.T) {
testCases := []struct {
input string
expectedOutput string
}{
{
input: "",
expectedOutput: "``",
},
{
input: "quote",
expectedOutput: "`quote`",
},
}
for _, tc := range testCases {
assert.Equal(t, tc.expectedOutput, MarkAsQuote(tc.input))
}
}

func TestMarkAsCodeSnippet(t *testing.T) {
testCases := []struct {
input string
expectedOutput string
}{
{
input: "",
expectedOutput: "```\n\n```",
},
{
input: "snippet",
expectedOutput: "```\nsnippet\n```",
},
}
for _, tc := range testCases {
assert.Equal(t, tc.expectedOutput, MarkAsCodeSnippet(tc.input))
}
}

func TestGetLocationDescription(t *testing.T) {
testCases := []struct {
input formats.Location
expectedOutput string
}{
{
input: formats.Location{
File: "file1",
StartLine: 1,
Snippet: "snippet",
},
expectedOutput: "\n```\nsnippet\n```\nat `file1` (line 1)\n",
},
{
input: formats.Location{
File: "dir/other-dir/file1",
StartLine: 134,
Snippet: "clientTestUtils.ChangeDirAndAssert(t, prevWd)",
},
expectedOutput: "\n```\nclientTestUtils.ChangeDirAndAssert(t, prevWd)\n```\nat `dir/other-dir/file1` (line 134)\n",
},
}
for _, tc := range testCases {
assert.Equal(t, tc.expectedOutput, GetLocationDescription(tc.input))
}
}

func TestGetJasMarkdownDescription(t *testing.T) {
testCases := []struct {
severity string
finding string
expectedOutput string
}{
{
severity: "High",
finding: "finding",
expectedOutput: "| Severity | Finding |\n| :--------------: | :---: |\n| High | finding |",
},
{
severity: "Low",
finding: "finding (other)",
expectedOutput: "| Severity | Finding |\n| :--------------: | :---: |\n| Low | finding (other) |",
},
}
for _, tc := range testCases {
assert.Equal(t, tc.expectedOutput, GetJasMarkdownDescription(tc.severity, tc.finding))
}
}

func TestGetApplicabilityMarkdownDescription(t *testing.T) {
testCases := []struct {
severity string
cve string
impactedDependency string
finding string
expectedOutput string
}{
{
severity: "High",
cve: "CVE-100-234",
impactedDependency: "dependency:1.0.0",
finding: "applicable finding",
expectedOutput: "| Severity | Impacted Dependency | Finding | CVE |\n| :--------------: | :---: | :---: | :---: |\n| High | dependency:1.0.0 | applicable finding | CVE-100-234 |",
},
{
severity: "Low",
cve: "CVE-222-233",
impactedDependency: "dependency:3.4.1",
finding: "applicable finding (diff)",
expectedOutput: "| Severity | Impacted Dependency | Finding | CVE |\n| :--------------: | :---: | :---: | :---: |\n| Low | dependency:3.4.1 | applicable finding (diff) | CVE-222-233 |",
},
}
for _, tc := range testCases {
assert.Equal(t, tc.expectedOutput, GetApplicabilityMarkdownDescription(tc.severity, tc.cve, tc.impactedDependency, tc.finding))
}
}
3 changes: 1 addition & 2 deletions utils/reviewcomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ func getFrogbotReviewComments(existingComments []vcsclient.CommentInfo) (reviewC
}

func getRegularCommentContent(comment ReviewComment) string {
content := outputwriter.MarkdownComment(CommentId)
return content + outputwriter.GetLocationDescription(comment.Location) + comment.CommentInfo.Content
return outputwriter.MarkdownComment(CommentId) + outputwriter.GetLocationDescription(comment.Location) + comment.CommentInfo.Content
}

func getNewReviewComments(repo *Repository, issues *IssuesCollection) (commentsToAdd []ReviewComment) {
Expand Down
46 changes: 46 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/formats"
"github.com/jfrog/jfrog-cli-core/v2/xray/utils"
"github.com/owenrumney/go-sarif/v2/sarif"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -374,3 +376,47 @@ func TestTechArrayToString(t *testing.T) {
})
}
}

func TestPrepareRunsForGithubReport(t *testing.T) {
testCases := []struct {
run *sarif.Run
expectedOutput *sarif.Run
}{
{
run: utils.CreateRunWithDummyResults(),
expectedOutput: sarif.NewRunWithInformationURI(sarifToolName, sarifToolUrl),
},
{
run: sarif.NewRunWithInformationURI("other tool", "other url").WithResults([]*sarif.Result{
utils.CreateResultWithOneLocation("file://root/dir/file", 0, 0, 0, 0, "snippet", "rule", "level"),
}).WithInvocations([]*sarif.Invocation{sarif.NewInvocation().WithWorkingDirectory(sarif.NewSimpleArtifactLocation("root/dir"))}),
expectedOutput: sarif.NewRunWithInformationURI(sarifToolName, sarifToolUrl).WithResults([]*sarif.Result{
utils.CreateResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule", "level"),
}).WithInvocations([]*sarif.Invocation{sarif.NewInvocation().WithWorkingDirectory(sarif.NewSimpleArtifactLocation("root/dir"))}),
},
{
run: sarif.NewRunWithInformationURI("other tool", "other url").WithResults([]*sarif.Result{
utils.CreateResultWithLocations("findings", "rule", "level",
utils.CreateLocation("file://root/dir/file", 0, 0, 0, 0, "snippet"),
utils.CreateLocation("file://root/dir/dir2/file2", 1, 1, 1, 1, "snippet2"),
).WithCodeFlows([]*sarif.CodeFlow{utils.CreateCodeFlow(utils.CreateThreadFlow(
utils.CreateLocation("file://root/dir/other/file", 2, 2, 2, 2, "other"),
utils.CreateLocation("file://root/dir/file", 0, 0, 0, 0, "snippet"),
))}),
}).WithInvocations([]*sarif.Invocation{sarif.NewInvocation().WithWorkingDirectory(sarif.NewSimpleArtifactLocation("root/dir"))}),
expectedOutput: sarif.NewRunWithInformationURI(sarifToolName, sarifToolUrl).WithResults([]*sarif.Result{
utils.CreateResultWithLocations("findings", "rule", "level",
utils.CreateLocation("file", 0, 0, 0, 0, "snippet"),
utils.CreateLocation("dir2/file2", 1, 1, 1, 1, "snippet2"),
).WithCodeFlows([]*sarif.CodeFlow{utils.CreateCodeFlow(utils.CreateThreadFlow(
utils.CreateLocation("other/file", 2, 2, 2, 2, "other"),
utils.CreateLocation("file", 0, 0, 0, 0, "snippet"),
))}),
}).WithInvocations([]*sarif.Invocation{sarif.NewInvocation().WithWorkingDirectory(sarif.NewSimpleArtifactLocation("root/dir"))}),
},
}
for _, tc := range testCases {
prepareRunsForGithubReport([]*sarif.Run{tc.run})
assert.Equal(t, tc.expectedOutput, tc.run)
}
}
Loading