Validate metadata.name of managed cluster (#304)

Signed-off-by: Jian Qiu <jqiu@redhat.com>
This commit is contained in:
Jian Qiu
2023-03-16 09:43:13 +08:00
committed by GitHub
parent 8791e8e4f8
commit f39b00d4e7
9 changed files with 32 additions and 1514 deletions

View File

@@ -201,6 +201,18 @@ var _ = ginkgo.Describe("Admission webhook", func() {
gomega.Expect(u.deleteManageClusterAndRelatedNamespace(clusterName)).ToNot(gomega.HaveOccurred())
})
ginkgo.It("Should respond bad request when cluster name is invalid", func() {
clusterName := fmt.Sprintf("webhook.spoke-%s", rand.String(6))
ginkgo.By(fmt.Sprintf("create a managed cluster %q with an invalid name", clusterName))
managedCluster := newManagedCluster(clusterName, false, validURL)
_, err := clusterClient.ClusterV1().ManagedClusters().Create(context.TODO(), managedCluster, metav1.CreateOptions{})
gomega.Expect(err).To(gomega.HaveOccurred())
gomega.Expect(errors.IsBadRequest(err)).Should(gomega.BeTrue())
gomega.Expect(u.deleteManageClusterAndRelatedNamespace(clusterName)).ToNot(gomega.HaveOccurred())
})
ginkgo.It("Should forbid the request when creating an accepted managed cluster by unauthorized user", func() {
sa := fmt.Sprintf("webhook-sa-%s", rand.String(6))
clusterName := fmt.Sprintf("webhook-spoke-%s", rand.String(6))