diff --git a/e2e/fixtures/samples/config-dev.json b/e2e/fixtures/samples/configs/config-dev.json similarity index 100% rename from e2e/fixtures/samples/config-dev.json rename to e2e/fixtures/samples/configs/config-dev.json diff --git a/e2e/fixtures/samples/configs/config-dev.yaml b/e2e/fixtures/samples/configs/config-dev.yaml new file mode 100644 index 00000000000..19209d1b879 --- /dev/null +++ b/e2e/fixtures/samples/configs/config-dev.yaml @@ -0,0 +1,3 @@ +path: fixtures/samples/positive.dockerfile +queries-path: ../assets/queries +timeout: 12 diff --git a/e2e/fixtures/samples/config.json b/e2e/fixtures/samples/configs/config.json similarity index 100% rename from e2e/fixtures/samples/config.json rename to e2e/fixtures/samples/configs/config.json diff --git a/e2e/fixtures/samples/configs/config.yaml b/e2e/fixtures/samples/configs/config.yaml new file mode 100644 index 00000000000..c209f2dd8ba --- /dev/null +++ b/e2e/fixtures/samples/configs/config.yaml @@ -0,0 +1,3 @@ +path: /path/e2e/fixtures/samples/positive.dockerfile +queries-path: /path/assets/queries +timeout: 12 diff --git a/e2e/testcases/e2e-cli-029_scan_config.go b/e2e/testcases/e2e-cli-029_scan_config.go index 8c38bb85835..d4c0457fea7 100644 --- a/e2e/testcases/e2e-cli-029_scan_config.go +++ b/e2e/testcases/e2e-cli-029_scan_config.go @@ -7,11 +7,11 @@ func init() { //nolint Name: "should load a config file [E2E-CLI-029]", Args: args{ Args: []cmdArgs{ - []string{"scan", "--config", "/path/e2e/fixtures/samples/config.json", "--type", "cloudformation"}, + []string{"scan", "--config", "/path/e2e/fixtures/samples/configs/config.json", "--type", "cloudformation"}, - []string{"scan", "--config", "/path/e2e/fixtures/samples/config.json"}, + []string{"scan", "--config", "/path/e2e/fixtures/samples/configs/config.json"}, - []string{"scan", "--config", "/path/e2e/fixtures/samples/config.json", "--silent"}, + []string{"scan", "--config", "/path/e2e/fixtures/samples/configs/config.json", "--silent"}, }, }, WantStatus: []int{50, 0, 126}, diff --git a/e2e/testcases/e2e-cli-056_scan_timeout.go b/e2e/testcases/e2e-cli-056_scan_timeout.go new file mode 100644 index 00000000000..0095f8f3cae --- /dev/null +++ b/e2e/testcases/e2e-cli-056_scan_timeout.go @@ -0,0 +1,27 @@ +package testcases + +import ( + "regexp" +) + +// E2E-CLI-056 - Kics scan command with timeout flag +// should stop a query execution when reaching the provided timeout (seconds) +func init() { //nolint + testSample := TestCase{ + Name: "should timeout queries when reaching the timeout limit [E2E-CLI-056]", + Args: args{ + Args: []cmdArgs{ + []string{"scan", "--config", "/path/e2e/fixtures/samples/configs/config.yaml", "-v"}, + []string{"scan", "-p", "/path/e2e/fixtures/samples/positive.dockerfile", "--timeout", "1", "-v"}, + []string{"scan", "-p", "/path/e2e/fixtures/samples/positive.dockerfile", "--timeout", "0", "-v"}, + }, + }, + WantStatus: []int{50, 50, 126}, + Validation: func(outputText string) bool { + matchTimeoutLog, _ := regexp.MatchString("Query execution timeout=(0|1|12)s", outputText) + return matchTimeoutLog + }, + } + + Tests = append(Tests, testSample) +} diff --git a/e2e/utils/helper.go b/e2e/utils/helper.go index 9d9d3f9123d..1bac4b8b8ec 100644 --- a/e2e/utils/helper.go +++ b/e2e/utils/helper.go @@ -49,8 +49,11 @@ func RunCommand(kicsArgs []string, useDocker, useMock bool, kicsDockerImage stri // KicsDevPathAdapter adapts the path to enable kics locally execution func KicsDevPathAdapter(path string) string { - if path == "/path/e2e/fixtures/samples/config.json" { + // [e2e-029] and [e2e-056] config tests + if path == "/path/e2e/fixtures/samples/configs/config.json" { path = strings.Replace(path, "config.json", "config-dev.json", -1) + } else if path == "/path/e2e/fixtures/samples/configs/config.yaml" { + path = strings.Replace(path, "config.yaml", "config-dev.yaml", -1) } regex := regexp.MustCompile(`/path/\w+/`) matches := regex.FindString(path) diff --git a/pkg/engine/secrets/inspector.go b/pkg/engine/secrets/inspector.go index 1f2529735d4..896822eb5c7 100644 --- a/pkg/engine/secrets/inspector.go +++ b/pkg/engine/secrets/inspector.go @@ -163,7 +163,7 @@ func NewInspector( func (c *Inspector) inspectQuery(ctx context.Context, basePaths []string, files model.FileMetadatas, i int) ([]model.Vulnerability, error) { - timeoutCtx, cancel := context.WithTimeout(ctx, c.queryExecutionTimeout*time.Second) + timeoutCtx, cancel := context.WithTimeout(ctx, c.queryExecutionTimeout) defer cancel() cleanFiles := cleanFiles(files)