mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
* bump version Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> * bump version for httphandler Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> * fix args validation Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> * errors as const Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> --------- Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io> Co-authored-by: Daniel Grunberger <danielgrunberger@armosec.io>
151 lines
3.6 KiB
Go
151 lines
3.6 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,
|
|
},
|
|
{
|
|
"Security view should be invalid for scan info",
|
|
&cautils.ScanInfo{View: string(cautils.SecurityViewType)},
|
|
ErrSecurityViewNotSupported,
|
|
},
|
|
{
|
|
"Empty view should be valid for scan info",
|
|
&cautils.ScanInfo{},
|
|
nil,
|
|
},
|
|
}
|
|
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|