-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathvulnscanhandlerhelper_test.go
113 lines (105 loc) · 2.8 KB
/
vulnscanhandlerhelper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package mainhandler
import (
"testing"
"github.com/armosec/armoapi-go/identifiers"
"github.com/armosec/armoapi-go/apis"
"github.com/stretchr/testify/assert"
)
func getSetCronjobCommand() *apis.Command {
jobParams := apis.CronJobParams{
JobName: "",
CronTabSchedule: "",
}
return &apis.Command{
CommandName: apis.TypeSetVulnScanCronJob,
WildWlid: "wlid://cluster-minikube",
Args: map[string]interface{}{
"jobParams": jobParams,
},
}
}
// Extract vuln-scan command from create cronjob command
func TestGetVulnScanRequest(t *testing.T) {
commandSet := getSetCronjobCommand()
commandsScan := getVulnScanRequest(commandSet)
assert.NotEqual(t, commandsScan.Commands[0].CommandName, commandSet.CommandName)
assert.Equal(t, commandsScan.Commands[0].CommandName, (apis.NotificationPolicyType)(apis.TypeScanImages))
assert.Equal(t, commandsScan.Commands[0].Args, map[string]interface{}(nil))
}
func TestGetNamespaceFromVulnScanCommand(t *testing.T) {
tests := []struct {
name string
command *apis.Command
expectedNamespace string
}{
{
name: "no namespace in WildWlid - empty string",
command: &apis.Command{
CommandName: apis.TypeSetVulnScanCronJob,
WildWlid: "wlid://cluster-minikube",
Args: map[string]interface{}{
"jobParams": apis.CronJobParams{
JobName: "",
CronTabSchedule: "",
},
},
},
expectedNamespace: "",
},
{
name: "invalid command - empty string",
command: &apis.Command{
CommandName: apis.TypeSetVulnScanCronJob,
Args: map[string]interface{}{
"jobParams": apis.CronJobParams{
JobName: "",
CronTabSchedule: "",
},
},
},
expectedNamespace: "",
},
{
name: "namespace from designators",
command: &apis.Command{
CommandName: apis.TypeSetVulnScanCronJob,
Designators: []identifiers.PortalDesignator{
{
DesignatorType: identifiers.DesignatorAttributes,
Attributes: map[string]string{
identifiers.AttributeCluster: "minikube",
identifiers.AttributeNamespace: "test-333",
},
},
},
Args: map[string]interface{}{
"jobParams": apis.CronJobParams{
JobName: "",
CronTabSchedule: "",
},
},
},
expectedNamespace: "test-333",
},
{
name: "namespace from WildWlid",
command: &apis.Command{
CommandName: apis.TypeSetVulnScanCronJob,
WildWlid: "wlid://cluster-minikube/namespace-test-123",
Args: map[string]interface{}{
"jobParams": apis.CronJobParams{
JobName: "",
CronTabSchedule: "",
},
},
},
expectedNamespace: "test-123",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ns := getNamespaceFromVulnScanCommand(tc.command)
assert.Equal(t, tc.expectedNamespace, ns)
})
}
}