mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
* phase-1 Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> * factory Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> * wip: feat(cli): add an image scanning command Add a CLI command that launches an image scan. Does not scan images yet. Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * wip: feat: add image scanning service Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * chore: include dependencies Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * wip: adjust image scanning service Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * wip: feat: use scanning service in CLI Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * use iface Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> * touches Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> * continue Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> * add cmd Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> * support single workload scan Signed-off-by: Amir Malka <amirm@armosec.io> * fix conflict Signed-off-by: Amir Malka <amirm@armosec.io> * identifiers * go mod * feat(imagescan): add an image scanning command This commit adds a CLI command and an associated package that scan images for vulnerabilities. Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> feat(imagescan): fail on exceeding the severity threshold Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * chore(imagescan): include dependencies This commit adds the dependencies necessary for image scanning. Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * chore(imagescan): add dependencies to httphandler Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * added unit tests Signed-off-by: Amir Malka <amirm@armosec.io> * merge * more * integrate img scan * added unit tests Signed-off-by: Amir Malka <amirm@armosec.io> * more refactoring Signed-off-by: Amir Malka <amirm@armosec.io> * add scanned workload reference to opasessionobj Signed-off-by: Amir Malka <amirm@armosec.io> * fix GetWorkloadParentKind Signed-off-by: Amir Malka <amirm@armosec.io> * remove namespace argument from pullSingleResource, using field selector instead Signed-off-by: Amir Malka <amirm@armosec.io> * removed designators (unused) field from PolicyIdentifier, and designators argument from GetResources function Signed-off-by: Amir Malka <amirm@armosec.io> * changes * changes * fixes * changes * feat(imagescan): add an image scanning command This commit adds a CLI command and an associated package that scan images for vulnerabilities. Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> feat(imagescan): fail on exceeding the severity threshold Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * chore(imagescan): include dependencies This commit adds the dependencies necessary for image scanning. Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * chore(imagescan): add dependencies to httphandler Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * chore(imagescan): create vuln db with dedicated function Remove commented out code, too. Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * docs(imagescan): provide package-level docs Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> * finish merge * image scan tests * continue * fixes * refactor * rm duplicate * start fixes * update gh actions Signed-off-by: David Wertenteil <dwertent@armosec.io> * pr fixes * fix test * improvements --------- Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> Signed-off-by: Vlad Klokun <vklokun@protonmail.ch> Signed-off-by: Amir Malka <amirm@armosec.io> Signed-off-by: David Wertenteil <dwertent@armosec.io> Co-authored-by: Daniel Grunberger <danielgrunberger@armosec.io> Co-authored-by: Vlad Klokun <vklokun@protonmail.ch> Co-authored-by: Amir Malka <amirm@armosec.io> Co-authored-by: David Wertenteil <dwertent@armosec.io>
141 lines
3.3 KiB
Go
141 lines
3.3 KiB
Go
package scan
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kubescape/kubescape/v2/core/cautils"
|
|
)
|
|
|
|
// Test_validateControlScanInfo tests how scan info is validated for the `scan control` command
|
|
func Test_validateControlScanInfo(t *testing.T) {
|
|
testCases := []struct {
|
|
Description string
|
|
ScanInfo *cautils.ScanInfo
|
|
Want error
|
|
}{
|
|
{
|
|
"Empty severity should be valid for scan info",
|
|
&cautils.ScanInfo{FailThresholdSeverity: ""},
|
|
nil,
|
|
},
|
|
{
|
|
"High severity should be valid for scan info",
|
|
&cautils.ScanInfo{FailThresholdSeverity: "High"},
|
|
nil,
|
|
},
|
|
{
|
|
"Unknown severity should be invalid for scan info",
|
|
&cautils.ScanInfo{FailThresholdSeverity: "Unknown"},
|
|
ErrUnknownSeverity,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(
|
|
tc.Description,
|
|
func(t *testing.T) {
|
|
var want error = tc.Want
|
|
|
|
got := validateControlScanInfo(tc.ScanInfo)
|
|
|
|
if got != want {
|
|
t.Errorf("got: %v, want: %v", got, want)
|
|
}
|
|
},
|
|
)
|
|
}
|
|
}
|
|
|
|
// Test_validateFrameworkScanInfo tests how scan info is validated for the `scan framework` command
|
|
func Test_validateFrameworkScanInfo(t *testing.T) {
|
|
testCases := []struct {
|
|
Description string
|
|
ScanInfo *cautils.ScanInfo
|
|
Want error
|
|
}{
|
|
{
|
|
"Empty severity should be valid for scan info",
|
|
&cautils.ScanInfo{FailThresholdSeverity: ""},
|
|
nil,
|
|
},
|
|
{
|
|
"High severity should be valid for scan info",
|
|
&cautils.ScanInfo{FailThresholdSeverity: "High"},
|
|
nil,
|
|
},
|
|
{
|
|
"Unknown severity should be invalid for scan info",
|
|
&cautils.ScanInfo{FailThresholdSeverity: "Unknown"},
|
|
ErrUnknownSeverity,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(
|
|
tc.Description,
|
|
func(t *testing.T) {
|
|
var want error = tc.Want
|
|
|
|
got := validateFrameworkScanInfo(tc.ScanInfo)
|
|
|
|
if got != want {
|
|
t.Errorf("got: %v, want: %v", got, want)
|
|
}
|
|
},
|
|
)
|
|
}
|
|
}
|
|
|
|
func Test_validateSeverity(t *testing.T) {
|
|
testCases := []struct {
|
|
Description string
|
|
Input string
|
|
Want error
|
|
}{
|
|
{"low should be a valid severity", "low", nil},
|
|
{"Low should be a valid severity", "Low", nil},
|
|
{"medium should be a valid severity", "medium", nil},
|
|
{"Medium should be a valid severity", "Medium", nil},
|
|
{"high should be a valid severity", "high", nil},
|
|
{"Critical should be a valid severity", "Critical", nil},
|
|
{"critical should be a valid severity", "critical", nil},
|
|
{"Unknown should be an invalid severity", "Unknown", ErrUnknownSeverity},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
t.Run(testCase.Description, func(t *testing.T) {
|
|
input := testCase.Input
|
|
want := testCase.Want
|
|
got := validateSeverity(input)
|
|
|
|
if got != want {
|
|
t.Errorf("got: %v, want: %v", got, want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_validateWorkloadIdentifier(t *testing.T) {
|
|
testCases := []struct {
|
|
Description string
|
|
Input string
|
|
Want error
|
|
}{
|
|
{"valid workload identifier should be valid", "deployment/test", nil},
|
|
{"invalid workload identifier missing kind", "deployment", ErrInvalidWorkloadIdentifier},
|
|
{"invalid workload identifier with namespace", "ns/deployment/name", ErrInvalidWorkloadIdentifier},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
t.Run(testCase.Description, func(t *testing.T) {
|
|
input := testCase.Input
|
|
want := testCase.Want
|
|
got := validateWorkloadIdentifier(input)
|
|
|
|
if got != want {
|
|
t.Errorf("got: %v, want: %v", got, want)
|
|
}
|
|
})
|
|
}
|
|
}
|