1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-12-22 06:38:06 +00:00

fix: ignore the error from findConfigFile (#1440)

When we are trying to access a file from a directory which is not present then we get different error.
We dont have standard error method to check the msg so added string match for this case
This commit is contained in:
Devendra Turkar 2023-05-15 17:31:30 +05:30 committed by GitHub
parent e38c829dbc
commit b0e49c8789
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -241,7 +241,7 @@ func findConfigFile(candidates []string) string {
if err == nil {
return c
}
if !os.IsNotExist(err) {
if !os.IsNotExist(err) && !strings.HasSuffix(err.Error(), "not a directory") {
exitWithError(fmt.Errorf("error looking for file %s: %v", c, err))
}
}

View File

@ -15,6 +15,7 @@
package cmd
import (
"errors"
"io/ioutil"
"os"
"path/filepath"
@ -233,6 +234,7 @@ func TestFindConfigFile(t *testing.T) {
{input: []string{"myfile"}, statResults: []error{nil}, exp: "myfile"},
{input: []string{"thisfile", "thatfile"}, statResults: []error{os.ErrNotExist, nil}, exp: "thatfile"},
{input: []string{"thisfile", "thatfile"}, statResults: []error{os.ErrNotExist, os.ErrNotExist}, exp: ""},
{input: []string{"thisfile", "/etc/dummy/thatfile"}, statResults: []error{os.ErrNotExist, errors.New("stat /etc/dummy/thatfile: not a directory")}, exp: ""},
}
statFunc = fakestat