Skip to content

Commit

Permalink
fix(tests): fixing tests for new flag
Browse files Browse the repository at this point in the history
Signed-off-by: Rogério Peixoto <[email protected]>
  • Loading branch information
rogeriopeixotocx committed Apr 29, 2021
1 parent 85f1fcb commit 781142d
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions e2e/fixtures/E2E_CLI_002
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Flags:
--preview-lines int number of lines to be display in CLI results (min: 1, max: 30) (default 3)
-q, --queries-path string path to directory with queries (default "./assets/queries")
--report-formats strings formats in which the results will be exported (json, sarif, html)
--timeout int number of seconds the query has to execute before being canceled (default 60)
-t, --type strings case insensitive list of platform types to scan
(Ansible, CloudFormation, Dockerfile, Kubernetes, OpenAPI, Terraform)

Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/E2E_CLI_003
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Flags:
--preview-lines int number of lines to be display in CLI results (min: 1, max: 30) (default 3)
-q, --queries-path string path to directory with queries (default "./assets/queries")
--report-formats strings formats in which the results will be exported (json, sarif, html)
--timeout int number of seconds the query has to execute before being canceled (default 60)
-t, --type strings case insensitive list of platform types to scan
(Ansible, CloudFormation, Dockerfile, Kubernetes, OpenAPI, Terraform)

Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/E2E_CLI_004
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Flags:
--preview-lines int number of lines to be display in CLI results (min: 1, max: 30) (default 3)
-q, --queries-path string path to directory with queries (default "./assets/queries")
--report-formats strings formats in which the results will be exported (json, sarif, html)
--timeout int number of seconds the query has to execute before being canceled (default 60)
-t, --type strings case insensitive list of platform types to scan
(Ansible, CloudFormation, Dockerfile, Kubernetes, OpenAPI, Terraform)

Expand Down
2 changes: 2 additions & 0 deletions e2e/fixtures/E2E_CLI_010
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Flags:
--preview-lines int number of lines to be display in CLI results (min: 1, max: 30) (default 3)
-q, --queries-path string path to directory with queries (default "./assets/queries")
--report-formats strings formats in which the results will be exported (json, sarif, html)
--timeout int number of seconds the query has to execute before being canceled (default 60)
-t, --type strings case insensitive list of platform types to scan
(Ansible, CloudFormation, Dockerfile, Kubernetes, OpenAPI, Terraform)

Expand All @@ -48,6 +49,7 @@ Global Flags:
--log-level string determines log level (TRACE,DEBUG,INFO,WARN,ERROR,FATAL) (default "INFO")
--log-path string path to log files, (defaults to ${PWD}/info.log)
--no-color disable CLI color output
--profiling string enables performance profiler that prints resource consumption metrics in the logs during the execution (CPU, MEM)
-s, --silent silence stdout messages (mutually exclusive with verbose and ci)
-v, --verbose write logs to stdout too (mutually exclusive with silent)

1 change: 1 addition & 0 deletions e2e/fixtures/E2E_CLI_016_INVALID_SCAN_FLAG
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Flags:
--preview-lines int number of lines to be display in CLI results (min: 1, max: 30) (default 3)
-q, --queries-path string path to directory with queries (default "./assets/queries")
--report-formats strings formats in which the results will be exported (json, sarif, html)
--timeout int number of seconds the query has to execute before being canceled (default 60)
-t, --type strings case insensitive list of platform types to scan
(Ansible, CloudFormation, Dockerfile, Kubernetes, OpenAPI, Terraform)

Expand Down
25 changes: 12 additions & 13 deletions pkg/engine/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const (
DefaultQueryURI = "https://github.com/Checkmarx/kics/"
DefaultIssueType = model.IssueTypeIncorrectValue

regoQuery = `result = data.Cx.CxPolicy`
executeTimeout = 60 * time.Second
regoQuery = `result = data.Cx.CxPolicy`
)

// ErrNoResult - error representing when a query didn't return a result
Expand Down Expand Up @@ -75,9 +74,9 @@ type Inspector struct {
excludeResults map[string]bool
detector *detector.DetectLine

enableCoverageReport bool
coverageReport cover.Report
queryExecTimeoutSeconds time.Duration
enableCoverageReport bool
coverageReport cover.Report
queryExecTimeout time.Duration
}

// QueryContext contains the context where the query is executed, which scan it belongs, basic information of query,
Expand Down Expand Up @@ -176,13 +175,13 @@ func NewInspector(
log.Info().Msgf("Query execution timeout=%v", queryExecTimeout)

return &Inspector{
queries: opaQueries,
vb: vb,
tracker: tracker,
failedQueries: failedQueries,
excludeResults: excludeResults,
detector: lineDetctor,
queryExecTimeoutSeconds: queryExecTimeout,
queries: opaQueries,
vb: vb,
tracker: tracker,
failedQueries: failedQueries,
excludeResults: excludeResults,
detector: lineDetctor,
queryExecTimeout: queryExecTimeout,
}, nil
}

Expand Down Expand Up @@ -273,7 +272,7 @@ func (c *Inspector) GetFailedQueries() map[string]error {
}

func (c *Inspector) doRun(ctx *QueryContext) ([]model.Vulnerability, error) {
timeoutCtx, cancel := context.WithTimeout(ctx.ctx, c.queryExecTimeoutSeconds)
timeoutCtx, cancel := context.WithTimeout(ctx.ctx, c.queryExecTimeout)
defer cancel()

options := []rego.EvalOption{rego.EvalInput(ctx.payload)}
Expand Down
2 changes: 2 additions & 0 deletions pkg/engine/inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"reflect"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -296,6 +297,7 @@ func TestInspect(t *testing.T) { //nolint
coverageReport: tt.fields.coverageReport,
excludeResults: tt.fields.excludeResults,
detector: inspDetector,
queryExecTimeout: time.Duration(60) * time.Second,
}
got, err := c.Inspect(tt.args.ctx, tt.args.scanID, tt.args.files, true, []string{filepath.FromSlash("assets/queries/")})
if tt.wantErr {
Expand Down
1 change: 1 addition & 0 deletions test/queries_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func testQueryHasGoodReturnParams(t *testing.T, entry queryEntry) {
trk,
source.ExcludeQueries{ByIDs: []string{}, ByCategories: []string{}},
map[string]bool{},
60,
)
require.Nil(t, err)
require.NotNil(t, inspector)
Expand Down
2 changes: 1 addition & 1 deletion test/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func testQuery(tb testing.TB, entry queryEntry, filesPath []string, expectedVuln
engine.DefaultVulnerabilityBuilder,
&tracker.CITracker{},
source.ExcludeQueries{ByIDs: []string{}, ByCategories: []string{}},
map[string]bool{})
map[string]bool{}, 60)

require.Nil(tb, err)
require.NotNil(tb, inspector)
Expand Down
2 changes: 1 addition & 1 deletion test/similarity_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func createInspectorAndGetVulnerabilities(ctx context.Context, t testing.TB,
engine.DefaultVulnerabilityBuilder,
&tracker.CITracker{},
source.ExcludeQueries{ByIDs: []string{}, ByCategories: []string{}},
map[string]bool{})
map[string]bool{}, 60)

require.Nil(t, err)
require.NotNil(t, inspector)
Expand Down

0 comments on commit 781142d

Please sign in to comment.