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

fix(inspector): fix timeout secrets inspector #5419

Merged
merged 4 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions e2e/fixtures/samples/configs/config-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
path: fixtures/samples/positive.dockerfile
queries-path: ../assets/queries
timeout: 12
3 changes: 3 additions & 0 deletions e2e/fixtures/samples/configs/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
path: /path/e2e/fixtures/samples/positive.dockerfile
queries-path: /path/assets/queries
timeout: 12
6 changes: 3 additions & 3 deletions e2e/testcases/e2e-cli-029_scan_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
27 changes: 27 additions & 0 deletions e2e/testcases/e2e-cli-056_scan_timeout.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 4 additions & 1 deletion e2e/utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/secrets/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down