@@ -10,7 +10,6 @@ import (
10
10
. "github.com/onsi/gomega"
11
11
"github.com/securego/gosec/v2"
12
12
"github.com/securego/gosec/v2/cwe"
13
- "github.com/securego/gosec/v2/report/core"
14
13
"github.com/securego/gosec/v2/report/junit"
15
14
"github.com/securego/gosec/v2/report/sonar"
16
15
"gopkg.in/yaml.v2"
@@ -37,10 +36,10 @@ func createIssue(ruleID string, weakness *cwe.Weakness) gosec.Issue {
37
36
}
38
37
}
39
38
40
- func createReportInfo (rule string , weakness * cwe.Weakness ) core .ReportInfo {
39
+ func createReportInfo (rule string , weakness * cwe.Weakness ) gosec .ReportInfo {
41
40
issue := createIssue (rule , weakness )
42
41
metrics := gosec.Metrics {}
43
- return core .ReportInfo {
42
+ return gosec .ReportInfo {
44
43
Errors : map [string ][]gosec.Error {},
45
44
Issues : []* gosec.Issue {
46
45
& issue ,
@@ -61,7 +60,7 @@ var _ = Describe("Formatter", func() {
61
60
})
62
61
Context ("when converting to Sonarqube issues" , func () {
63
62
It ("it should parse the report info" , func () {
64
- data := & core .ReportInfo {
63
+ data := & gosec .ReportInfo {
65
64
Errors : map [string ][]gosec.Error {},
66
65
Issues : []* gosec.Issue {
67
66
{
@@ -109,7 +108,7 @@ var _ = Describe("Formatter", func() {
109
108
})
110
109
111
110
It ("it should parse the report info with files in subfolders" , func () {
112
- data := & core .ReportInfo {
111
+ data := & gosec .ReportInfo {
113
112
Errors : map [string ][]gosec.Error {},
114
113
Issues : []* gosec.Issue {
115
114
{
@@ -156,7 +155,7 @@ var _ = Describe("Formatter", func() {
156
155
Expect (* issues ).To (Equal (* want ))
157
156
})
158
157
It ("it should not parse the report info for files from other projects" , func () {
159
- data := & core .ReportInfo {
158
+ data := & gosec .ReportInfo {
160
159
Errors : map [string ][]gosec.Error {},
161
160
Issues : []* gosec.Issue {
162
161
{
@@ -188,7 +187,7 @@ var _ = Describe("Formatter", func() {
188
187
})
189
188
190
189
It ("it should parse the report info for multiple projects projects" , func () {
191
- data := & core .ReportInfo {
190
+ data := & gosec .ReportInfo {
192
191
Errors : map [string ][]gosec.Error {},
193
192
Issues : []* gosec.Issue {
194
193
{
@@ -264,7 +263,7 @@ var _ = Describe("Formatter", func() {
264
263
It ("preserves order of issues" , func () {
265
264
issues := []* gosec.Issue {createIssueWithFileWhat ("i1" , "1" ), createIssueWithFileWhat ("i2" , "2" ), createIssueWithFileWhat ("i3" , "1" )}
266
265
267
- junitReport := junit .GenerateReport (& core .ReportInfo {Issues : issues })
266
+ junitReport := junit .GenerateReport (& gosec .ReportInfo {Issues : issues })
268
267
269
268
testSuite := junitReport .Testsuites [0 ]
270
269
@@ -290,7 +289,8 @@ var _ = Describe("Formatter", func() {
290
289
error := map [string ][]gosec.Error {}
291
290
292
291
buf := new (bytes.Buffer )
293
- err := CreateReport (buf , "csv" , false , []string {}, []* gosec.Issue {& issue }, & gosec.Metrics {}, error )
292
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {}, error )
293
+ err := CreateReport (buf , "csv" , false , []string {}, reportInfo )
294
294
Expect (err ).ShouldNot (HaveOccurred ())
295
295
pattern := "/home/src/project/test.go,1,test,HIGH,HIGH,1: testcode,CWE-%s\n "
296
296
expect := fmt .Sprintf (pattern , cwe .ID )
@@ -304,7 +304,8 @@ var _ = Describe("Formatter", func() {
304
304
error := map [string ][]gosec.Error {}
305
305
306
306
buf := new (bytes.Buffer )
307
- err := CreateReport (buf , "xml" , false , []string {}, []* gosec.Issue {& issue }, & gosec.Metrics {NumFiles : 0 , NumLines : 0 , NumNosec : 0 , NumFound : 0 }, error )
307
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {NumFiles : 0 , NumLines : 0 , NumNosec : 0 , NumFound : 0 }, error )
308
+ err := CreateReport (buf , "xml" , false , []string {}, reportInfo )
308
309
Expect (err ).ShouldNot (HaveOccurred ())
309
310
pattern := "Results:\n \n \n [/home/src/project/test.go:1] - %s (CWE-%s): test (Confidence: HIGH, Severity: HIGH)\n > 1: testcode\n \n \n \n Summary:\n Files: 0\n Lines: 0\n Nosec: 0\n Issues: 0\n \n "
310
311
expect := fmt .Sprintf (pattern , rule , cwe .ID )
@@ -324,7 +325,8 @@ var _ = Describe("Formatter", func() {
324
325
err := enc .Encode (data )
325
326
Expect (err ).ShouldNot (HaveOccurred ())
326
327
buf := new (bytes.Buffer )
327
- err = CreateReport (buf , "json" , false , []string {}, []* gosec.Issue {& issue }, & gosec.Metrics {}, error )
328
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {}, error )
329
+ err = CreateReport (buf , "json" , false , []string {}, reportInfo )
328
330
Expect (err ).ShouldNot (HaveOccurred ())
329
331
result := stripString (buf .String ())
330
332
expectation := stripString (expect .String ())
@@ -344,7 +346,8 @@ var _ = Describe("Formatter", func() {
344
346
err := enc .Encode (data )
345
347
Expect (err ).ShouldNot (HaveOccurred ())
346
348
buf := new (bytes.Buffer )
347
- err = CreateReport (buf , "html" , false , []string {}, []* gosec.Issue {& issue }, & gosec.Metrics {}, error )
349
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {}, error )
350
+ err = CreateReport (buf , "html" , false , []string {}, reportInfo )
348
351
Expect (err ).ShouldNot (HaveOccurred ())
349
352
result := stripString (buf .String ())
350
353
expectation := stripString (expect .String ())
@@ -364,7 +367,8 @@ var _ = Describe("Formatter", func() {
364
367
err := enc .Encode (data )
365
368
Expect (err ).ShouldNot (HaveOccurred ())
366
369
buf := new (bytes.Buffer )
367
- err = CreateReport (buf , "yaml" , false , []string {}, []* gosec.Issue {& issue }, & gosec.Metrics {}, error )
370
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {}, error )
371
+ err = CreateReport (buf , "yaml" , false , []string {}, reportInfo )
368
372
Expect (err ).ShouldNot (HaveOccurred ())
369
373
result := stripString (buf .String ())
370
374
expectation := stripString (expect .String ())
@@ -384,7 +388,8 @@ var _ = Describe("Formatter", func() {
384
388
err := enc .Encode (data )
385
389
Expect (err ).ShouldNot (HaveOccurred ())
386
390
buf := new (bytes.Buffer )
387
- err = CreateReport (buf , "junit-xml" , false , []string {}, []* gosec.Issue {& issue }, & gosec.Metrics {}, error )
391
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {}, error )
392
+ err = CreateReport (buf , "junit-xml" , false , []string {}, reportInfo )
388
393
Expect (err ).ShouldNot (HaveOccurred ())
389
394
expectation := stripString (fmt .Sprintf ("[/home/src/project/test.go:1] - test (Confidence: 2, Severity: 2, CWE: %s)" , cwe .ID ))
390
395
result := stripString (buf .String ())
@@ -404,7 +409,8 @@ var _ = Describe("Formatter", func() {
404
409
err := enc .Encode (data )
405
410
Expect (err ).ShouldNot (HaveOccurred ())
406
411
buf := new (bytes.Buffer )
407
- err = CreateReport (buf , "text" , false , []string {}, []* gosec.Issue {& issue }, & gosec.Metrics {}, error )
412
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {}, error )
413
+ err = CreateReport (buf , "text" , false , []string {}, reportInfo )
408
414
Expect (err ).ShouldNot (HaveOccurred ())
409
415
expectation := stripString (fmt .Sprintf ("[/home/src/project/test.go:1] - %s (CWE-%s): test (Confidence: HIGH, Severity: HIGH)" , rule , cwe .ID ))
410
416
result := stripString (buf .String ())
@@ -417,7 +423,8 @@ var _ = Describe("Formatter", func() {
417
423
issue := createIssue (rule , cwe )
418
424
error := map [string ][]gosec.Error {}
419
425
buf := new (bytes.Buffer )
420
- err := CreateReport (buf , "sonarqube" , false , []string {"/home/src/project" }, []* gosec.Issue {& issue }, & gosec.Metrics {}, error )
426
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {}, error )
427
+ err := CreateReport (buf , "sonarqube" , false , []string {"/home/src/project" }, reportInfo )
421
428
Expect (err ).ShouldNot (HaveOccurred ())
422
429
423
430
result := stripString (buf .String ())
@@ -438,7 +445,8 @@ var _ = Describe("Formatter", func() {
438
445
error := map [string ][]gosec.Error {}
439
446
440
447
buf := new (bytes.Buffer )
441
- err := CreateReport (buf , "golint" , false , []string {}, []* gosec.Issue {& issue }, & gosec.Metrics {}, error )
448
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {}, error )
449
+ err := CreateReport (buf , "golint" , false , []string {}, reportInfo )
442
450
Expect (err ).ShouldNot (HaveOccurred ())
443
451
pattern := "/home/src/project/test.go:1:1: [CWE-%s] test (Rule:%s, Severity:HIGH, Confidence:HIGH)\n "
444
452
expect := fmt .Sprintf (pattern , cwe .ID , rule )
@@ -452,7 +460,8 @@ var _ = Describe("Formatter", func() {
452
460
error := map [string ][]gosec.Error {}
453
461
454
462
buf := new (bytes.Buffer )
455
- err := CreateReport (buf , "sarif" , false , []string {}, []* gosec.Issue {& issue }, & gosec.Metrics {}, error )
463
+ reportInfo := gosec .NewReportInfo ([]* gosec.Issue {& issue }, & gosec.Metrics {}, error ).WithVersion ("v2.7.0" )
464
+ err := CreateReport (buf , "sarif" , false , []string {}, reportInfo )
456
465
Expect (err ).ShouldNot (HaveOccurred ())
457
466
458
467
result := stripString (buf .String ())
0 commit comments