-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathstandalone_hubtemplates_test.go
151 lines (108 loc) · 5.8 KB
/
standalone_hubtemplates_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright Contributors to the Open Cluster Management project
package integration
import (
"context"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"open-cluster-management.io/governance-policy-propagator/test/utils"
"github.com/stolostron/governance-policy-framework/test/common"
)
var _ = Describe("GRC: [P1][Sev1][policy-grc] Test standalone hub templating", Ordered, Serial, Label("SVT"), func() {
const (
standaloneConfigPolYAML = "../resources/standalone_hubtemplates/standalone-hubtemplates-test.yaml"
standaloneConfigPolUpdated = "../resources/standalone_hubtemplates/standalone-hubtemplates-test-updated.yaml"
standaloneConfigPolName = "standalone-hubtemplates-test"
standaloneConfigPolNS = "open-cluster-management-policies"
addonPolYAML = "../resources/standalone_hubtemplates/config-standalone-addon.yaml"
addonPolName = "config-standalone-addon"
rbacPolYAML = "../resources/standalone_hubtemplates/config-standalone-rbac.yaml"
rbacPolName = "config-standalone-rbac"
hubClusterNamespace = "local-cluster"
)
AfterAll(func(ctx SpecContext) {
By("Deleting policies")
_, err := common.OcHub("delete", "-f", standaloneConfigPolYAML, "--ignore-not-found")
Expect(err).ToNot(HaveOccurred())
utils.GetWithTimeout(clientHubDynamic, common.GvrConfigurationPolicy,
standaloneConfigPolName, standaloneConfigPolNS, false, defaultTimeoutSeconds)
common.DoCleanupPolicy(addonPolYAML, common.GvrConfigurationPolicy)
common.DoCleanupPolicy(rbacPolYAML, common.GvrConfigurationPolicy)
})
It("Cannot resolve the policy when the addon is not enabled", func(ctx context.Context) {
_, err := common.OcHub("create", "-f", standaloneConfigPolYAML)
Expect(err).ToNot(HaveOccurred())
Eventually(func() string {
plc := utils.GetWithTimeout(clientHubDynamic, common.GvrConfigurationPolicy,
standaloneConfigPolName, standaloneConfigPolNS, true, defaultTimeoutSeconds)
compliance, _, _ := unstructured.NestedString(plc.Object, "status", "compliant")
return compliance
}, defaultTimeoutSeconds, 2).Should(Equal("NonCompliant"))
Consistently(func() string {
plc := utils.GetWithTimeout(clientHubDynamic, common.GvrConfigurationPolicy,
standaloneConfigPolName, standaloneConfigPolNS, true, defaultTimeoutSeconds)
details, _, _ := unstructured.NestedSlice(plc.Object, "status", "compliancyDetails")
Expect(details).To(HaveLen(1))
conds, _, _ := unstructured.NestedSlice(details[0].(map[string]interface{}), "conditions")
Expect(conds).To(HaveLen(1))
msg, _, _ := unstructured.NestedString(conds[0].(map[string]interface{}), "message")
return msg
}, 10, 2).Should(ContainSubstring("governance-standalone-hub-templating addon must be enabled"))
})
It("Is able to successfully enforce the addon policy", func(ctx context.Context) {
_, err := common.OcHub("create", "-f", addonPolYAML)
Expect(err).ToNot(HaveOccurred())
Eventually(func() string {
plc := utils.GetWithTimeout(clientHubDynamic, common.GvrConfigurationPolicy,
addonPolName, hubClusterNamespace, true, defaultTimeoutSeconds)
compliance, _, _ := unstructured.NestedString(plc.Object, "status", "compliant")
return compliance
}, defaultTimeoutSeconds, 2).Should(Equal("Compliant"))
})
It("Resolves the template after the addon is enabled", func(ctx context.Context) {
Eventually(func() string {
plc := utils.GetWithTimeout(clientHubDynamic, common.GvrConfigurationPolicy,
standaloneConfigPolName, standaloneConfigPolNS, true, defaultTimeoutSeconds)
compliance, _, _ := unstructured.NestedString(plc.Object, "status", "compliant")
return compliance
}, defaultTimeoutSeconds, 2).Should(Equal("Compliant"))
})
It("Cannot resolve other resources without additional RBAC", func(ctx context.Context) {
_, err := common.OcHub("apply", "-f", standaloneConfigPolUpdated)
Expect(err).ToNot(HaveOccurred())
Eventually(func() string {
plc := utils.GetWithTimeout(clientHubDynamic, common.GvrConfigurationPolicy,
standaloneConfigPolName, standaloneConfigPolNS, true, defaultTimeoutSeconds)
compliance, _, _ := unstructured.NestedString(plc.Object, "status", "compliant")
return compliance
}, defaultTimeoutSeconds, 2).Should(Equal("NonCompliant"))
Consistently(func() string {
plc := utils.GetWithTimeout(clientHubDynamic, common.GvrConfigurationPolicy,
standaloneConfigPolName, standaloneConfigPolNS, true, defaultTimeoutSeconds)
details, _, _ := unstructured.NestedSlice(plc.Object, "status", "compliancyDetails")
Expect(details).To(HaveLen(1))
conds, _, _ := unstructured.NestedSlice(details[0].(map[string]interface{}), "conditions")
Expect(conds).To(HaveLen(1))
msg, _, _ := unstructured.NestedString(conds[0].(map[string]interface{}), "message")
return msg
}, 10, 2).Should(ContainSubstring(`cannot list resource "configmaps"`))
})
It("Is able to successfully configure additional RBAC permissions", func(ctx context.Context) {
_, err := common.OcHub("create", "-f", rbacPolYAML)
Expect(err).ToNot(HaveOccurred())
Eventually(func() string {
plc := utils.GetWithTimeout(clientHubDynamic, common.GvrConfigurationPolicy,
rbacPolName, hubClusterNamespace, true, defaultTimeoutSeconds)
compliance, _, _ := unstructured.NestedString(plc.Object, "status", "compliant")
return compliance
}, defaultTimeoutSeconds, 2).Should(Equal("Compliant"))
})
It("Resolves the template after RBAC is configured", func(ctx context.Context) {
Eventually(func() string {
plc := utils.GetWithTimeout(clientHubDynamic, common.GvrConfigurationPolicy,
standaloneConfigPolName, standaloneConfigPolNS, true, defaultTimeoutSeconds)
compliance, _, _ := unstructured.NestedString(plc.Object, "status", "compliant")
return compliance
}, defaultTimeoutSeconds, 2).Should(Equal("Compliant"))
})
})