Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
felipe-avelar authored Mar 24, 2021
1 parent 049b2d4 commit fc25956
Show file tree
Hide file tree
Showing 17 changed files with 618 additions and 9 deletions.
8 changes: 4 additions & 4 deletions docs/configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ KICS is able to infer the format without the need of file extension.
"payload-path": "file path to store source internal representation in JSON format",
"preview-lines": 3,
"queries-path": "path to directory with queries (default ./assets/queries) (default './assets/queries')",
"report-formats": "formats in which the results will be exported (json, sarif)",
"report-formats": "formats in which the results will be exported (json, sarif, html)",
"type": "type of queries to use in the scan",
"verbose": true
}
Expand All @@ -87,7 +87,7 @@ path: "path to file or directory to scan"
payload-path: "file path to store source internal representation in JSON format"
preview-lines: 3
queries-path: "path to directory with queries (default ./assets/queries) (default './assets/queries')"
report-formats: "formats in which the results will be exported (json, sarif)"
report-formats: "formats in which the results will be exported (json, sarif, html)"
type: "type of queries to use in the scan"
verbose: true
```
Expand All @@ -108,7 +108,7 @@ path = "path to file or directory to scan"
payload-path = "file path to store source internal representation in JSON format"
preview-lines = 3
queries-path = "path to directory with queries (default ./assets/queries) (default './assets/queries')"
report-formats = "formats in which the results will be exported (json, sarif)"
report-formats = "formats in which the results will be exported (json, sarif, html)"
type = "type of queries to use in the scan"
verbose = true
```
Expand All @@ -129,7 +129,7 @@ verbose = true
"payload-path" = "file path to store source internal representation in JSON format"
"preview-lines" = 3
"queries-path" = "path to directory with queries (default ./assets/queries) (default './assets/queries')"
"report-formats" = "formats in which the results will be exported (json, sarif)"
"report-formats" = "formats in which the results will be exported (json, sarif, html)"
"type" = "type of queries to use in the scan"
"verbose" = true
```
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Flags:
-d, --payload-path string path to store internal representation JSON file
--preview-lines int number of lines to be display in CLI results (default: 3)
-q, --queries-path string path to directory with queries (default "./assets/queries")
--report-formats string formats in which the results will be exported (json, sarif)
--report-formats string formats in which the results will be exported (json, sarif, html)
-t, --type strings case insensitive list of platform types to scan
(Ansible, CloudFormation, Dockerfile, Kubernetes, Terraform)
-v, --verbose increase verbosity
Expand Down
Binary file added docs/img/html_report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions docs/results.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
KICS can export results in multiple formats which can be seen on the following list:
- JSON
- SARIF
- HTML

To export in one of this formats, the flag output-path can be used with the file path and extension, for example:

Expand All @@ -15,7 +16,7 @@ KICS also can export multiple format in a single scan, to do this the flags outp
where the output-path will be the directory containing all report files and report-formats all extensions wanted, like following example:

```bash
./kics scan -p <path-of-your-project-to-scan> -o ./output --report-formats "json,sarif"
./kics scan -p <path-of-your-project-to-scan> -o ./output --report-formats "json,sarif,html"
```

The last command will execute the scan and save JSON and SARIF reports on output folder.
Expand Down Expand Up @@ -286,4 +287,7 @@ The last command will execute the scan and save JSON and SARIF reports on output
}
]
}
```
```

#### HTML
<img src="https://raw.githubusercontent.com/Checkmarx/kics/master/docs/img/html_report.png" width="850">
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/tdewolff/minify/v2 v2.9.15
github.com/zclconf/go-cty v1.8.1
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 // indirect
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
)

Expand Down
27 changes: 27 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/checkpoint-restore/go-criu/v4 v4.1.0/go.mod h1:xUQBLp4RLc5zJtWY++yjOoMoB5lihDt7fai+75m+rGw=
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U=
github.com/chromedp/cdproto v0.0.0-20210222063305-a3ac505ff0bd/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
github.com/chromedp/cdproto v0.0.0-20210227213635-aabfe75e3e09 h1:IMau1ByzOdZdIh8RR0oDHY7KJ86g41VjY0f7oExu3RY=
github.com/chromedp/cdproto v0.0.0-20210227213635-aabfe75e3e09/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
github.com/chromedp/chromedp v0.6.6 h1:/cxTTWu097YeUBdFNuwe65crupzNP9CFVotrO1JzAdc=
github.com/chromedp/chromedp v0.6.6/go.mod h1:I+DAskCTsBRt/48EVXbfmIUdMsSIyTR3sdxrCOXlrLY=
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down Expand Up @@ -386,8 +394,14 @@ github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b/go.mod h1:aUCEOzz
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs=
github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/flock v0.0.0-20190320160742-5135e617513b/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
Expand Down Expand Up @@ -670,6 +684,7 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
github.com/maratori/testpackage v1.0.1/go.mod h1:ddKdw+XG0Phzhx8BFDTKgpWP4i7MpApTE5fXSKAqwDU=
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down Expand Up @@ -969,6 +984,11 @@ github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
github.com/tdakkota/asciicheck v0.0.0-20200416200610-e657995f937b/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
github.com/tdewolff/minify/v2 v2.9.15 h1:gZzGuFHvmxDjsAM6Eu53xo8A5NiaVu3gzamvHAxDpAI=
github.com/tdewolff/minify/v2 v2.9.15/go.mod h1:tK4qPnHUZgANtEGVMwTBxrF1eNIBkigHFYo7F3Y98GQ=
github.com/tdewolff/parse/v2 v2.5.14 h1:ftdD54vkOeLZ7VkEZxp+wZrYZyyPi43GGon5GwBTRUI=
github.com/tdewolff/parse/v2 v2.5.14/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho=
github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
github.com/tetafro/godot v0.4.2/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
Expand Down Expand Up @@ -1169,6 +1189,8 @@ golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 h1:b0LrWgu8+q7z4J+0Y3Umo5q1dL7NXBkKBWkaVkAq17E=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/oauth2 v0.0.0-20180724155351-3d292e4d0cdc/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down Expand Up @@ -1252,17 +1274,22 @@ golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200917073148-efd3b9a0ff20/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201013081832-0aaa2718063a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 h1:SgQ6LNaYJU0JIuEHv9+s6EbhSCwYeAf5Yvj6lpYlqAE=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005 h1:pDMpM2zh2MT0kHy037cKlSby2nEhD50SYqwQk76Nm40=
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
1 change: 1 addition & 0 deletions internal/console/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
var reportGenerators = map[string]func(path, filename string, body interface{}) error{
"json": report.PrintJSONReport,
"sarif": report.PrintSarifReport,
"html": report.PrintHTMLReport,
}

// ProgressBar represents a Progress
Expand Down
2 changes: 1 addition & 1 deletion internal/console/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func initScanCmd() {
"report-formats",
"",
[]string{},
"formats in which the results will be exported (json, sarif)",
"formats in which the results will be exported (json, sarif, html)",
)
scanCmd.Flags().IntVarP(&outputLines, "preview-lines", "", 3, "number of lines to be display in CLI results (default: 3)")
scanCmd.Flags().StringVarP(&payloadPath, "payload-path", "d", "", "path to store internal representation JSON file")
Expand Down
33 changes: 33 additions & 0 deletions pkg/report/commons.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
package report

import (
"fmt"
"html/template"
"os"
"strings"
"time"

"github.com/Checkmarx/kics/pkg/model"
"github.com/rs/zerolog/log"
)

var templateFuncs = template.FuncMap{
"lower": strings.ToLower,
"sprintf": fmt.Sprintf,
"severity": getSeverities,
"getCurrentTime": getCurrentTime,
"trimSpaces": trimSpaces,
}

var stringsSeverity = map[string]model.Severity{
"high": model.AllSeverities[0],
"medium": model.AllSeverities[1],
"low": model.AllSeverities[2],
"info": model.AllSeverities[3],
}

func trimSpaces(value string) string {
return strings.TrimPrefix(value, " ")
}

func getSeverities(severity string) model.Severity {
return stringsSeverity[severity]
}

func getCurrentTime() string {
dt := time.Now()
return fmt.Sprint(dt.Format("01/02/2006 15:04"))
}

func closeFile(path, filename string, file *os.File) {
err := file.Close()
if err != nil {
Expand Down
91 changes: 91 additions & 0 deletions pkg/report/html.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package report

import (
"bytes"
"fmt"
"html/template"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/rs/zerolog/log"
"github.com/tdewolff/minify/v2"
minifyCSS "github.com/tdewolff/minify/v2/css"
minifyHtml "github.com/tdewolff/minify/v2/html"
)

const (
templateFile = "report.tmpl"
)

var templatePath = ""

func includeSVG(name string) template.HTML {
svg, err := os.ReadFile(filepath.Join(templatePath, name))
if err != nil {
log.Err(err).Msgf("failed to open svg: %s", name)
return ""
}
return template.HTML(string(svg)) //nolint
}

func includeCSS(name string) template.HTML {
css, err := os.ReadFile(filepath.Join(templatePath, name))
if err != nil {
log.Err(err).Msgf("failed to open svg: %s", name)
return ""
}
minifier := minify.New()
minifier.AddFunc("text/css", minifyCSS.Minify)
cssMinified, err := minifier.Bytes("text/css", css)
if err != nil {
return ""
}
return template.HTML("<style>" + string(cssMinified) + "</style>") //nolint
}

// PrintHTMLReport creates a report file on HTML format
func PrintHTMLReport(path, filename string, body interface{}) error {
if !strings.HasSuffix(filename, ".html") {
filename += ".html"
}

_, templatePathFromStack, _, ok := runtime.Caller(0)
if !ok {
return fmt.Errorf("report error: Report template not found")
}
templatePath = templatePathFromStack
templateFuncs["includeSVG"] = includeSVG
templateFuncs["includeCSS"] = includeCSS

fullPath := filepath.Join(path, filename)
templatePath = filepath.Join(filepath.Dir(templatePath), "template", "html")
t := template.Must(template.New(templateFile).Funcs(templateFuncs).ParseFiles(filepath.Join(templatePath, templateFile)))

_ = os.MkdirAll(path, os.ModePerm)
f, err := os.OpenFile(filepath.Clean(fullPath), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
defer closeFile(fullPath, filename, f)
var buffer bytes.Buffer

err = t.Execute(&buffer, body)
if err != nil {
return err
}
minifier := minify.New()
minifier.AddFunc("text/html", minifyHtml.Minify)
minifier.Add("text/html", &minifyHtml.Minifier{
KeepDocumentTags: true,
KeepEndTags: true,
KeepQuotes: true,
})

minifierWriter := minifier.Writer("text/html", f)
defer minifierWriter.Close()

_, err = minifierWriter.Write(buffer.Bytes())
return err
}
45 changes: 45 additions & 0 deletions pkg/report/html_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package report

import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/Checkmarx/kics/pkg/model"
"github.com/Checkmarx/kics/test"
"github.com/stretchr/testify/require"
"golang.org/x/net/html"
)

var htmlTests = []struct {
caseTest jsonCaseTest
expectedResult model.Summary
}{
{
caseTest: jsonCaseTest{
summary: test.SummaryMock,
path: "./testdir",
filename: "testout",
},
expectedResult: test.SummaryMock,
},
}

// TestPrintHTMLReport tests the functions [PrintHTMLReport()] and all the methods called by them
func TestPrintHTMLReport(t *testing.T) {
for idx, test := range htmlTests {
t.Run(fmt.Sprintf("HTML File test case %d", idx), func(t *testing.T) {
err := PrintHTMLReport(test.caseTest.path, test.caseTest.filename, test.caseTest.summary)
require.NoError(t, err)
require.FileExists(t, filepath.Join(test.caseTest.path, test.caseTest.filename+".html"))
htmlString, err := os.ReadFile(filepath.Join(test.caseTest.path, test.caseTest.filename+".html"))
require.NoError(t, err)
valid, err := html.Parse(strings.NewReader(string(htmlString)))
require.NoError(t, err)
require.NotNil(t, valid)
os.RemoveAll(test.caseTest.path)
})
}
}
11 changes: 11 additions & 0 deletions pkg/report/template/html/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions pkg/report/template/html/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fc25956

Please sign in to comment.