Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Amir Malka <[email protected]>
  • Loading branch information
amirmalka committed Mar 3, 2024
1 parent 4a0c9c7 commit f5cac88
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 10 additions & 8 deletions mainhandler/vulnscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,16 @@ func getImageScanConfig(k8sAPI IWorkloadsGetter, namespace string, pod *corev1.P
}
}

// TODO: this should not happen every scan
// build a list of secrets from the the registry secrets
secrets, err := cloudsupport.GetImageRegistryCredentials(imageTag, pod)
if err != nil {
return nil, err
}
for i := range secrets {
imageScanConfig.authConfigs = append(imageScanConfig.authConfigs, secrets[i])
if pod != nil {
// TODO: this should not happen every scan
// build a list of secrets from the the registry secrets
secrets, err := cloudsupport.GetImageRegistryCredentials(imageTag, pod)
if err != nil {
return nil, err
}
for i := range secrets {
imageScanConfig.authConfigs = append(imageScanConfig.authConfigs, secrets[i])
}
}

return &imageScanConfig, nil
Expand Down
5 changes: 2 additions & 3 deletions mainhandler/vulnscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/kubescape/k8s-interface/k8sinterface"
"github.com/kubescape/k8s-interface/workloadinterface"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
)

//go:embed testdata/vulnscan/registry-secret.json
Expand Down Expand Up @@ -45,13 +44,13 @@ func Test_ActionHandler_getImageScanConfig(t *testing.T) {

k8sApiMock := &WorkloadsGetterMock{}

res, err := getImageScanConfig(k8sApiMock, "", &v1.Pod{}, "nginx:latest") // no registry treated as docker.io
res, err := getImageScanConfig(k8sApiMock, "", nil, "nginx:latest") // no registry treated as docker.io
assert.NoError(t, err)
assert.Equal(t, expectedAuthConfigs, res.authConfigs)
assert.True(t, *res.insecure)
assert.Nil(t, res.skipTLSVerify)

res, err = getImageScanConfig(k8sApiMock, "", &v1.Pod{}, "quay.IO/kubescape/nginx:latest")
res, err = getImageScanConfig(k8sApiMock, "", nil, "quay.IO/kubescape/nginx:latest")
assert.NoError(t, err)
assert.Equal(t, expectedAuthConfigs, res.authConfigs)
assert.Nil(t, res.insecure)
Expand Down

0 comments on commit f5cac88

Please sign in to comment.