github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/verify-install/dex/dex_test.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package dex 5 6 import ( 7 "fmt" 8 . "github.com/onsi/ginkgo/v2" 9 . "github.com/onsi/gomega" 10 "github.com/verrazzano/verrazzano/pkg/k8sutil" 11 "github.com/verrazzano/verrazzano/pkg/vzcr" 12 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1beta1" 13 "github.com/verrazzano/verrazzano/platform-operator/constants" 14 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 15 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 16 "time" 17 ) 18 19 var ( 20 isDexSupported bool 21 isDexInstalled bool 22 inClusterVZ *v1beta1.Verrazzano 23 ) 24 25 const ( 26 waitTimeout = 3 * time.Minute 27 pollingInterval = 10 * time.Second 28 29 pkceClientSecret = "verrazzano-pkce" //nolint:gosec //#gosec G101 30 ) 31 32 var t = framework.NewTestFramework("dex") 33 34 var beforeSuite = t.BeforeSuiteFunc(func() { 35 var err error 36 kubeConfigPath := getKubeConfigOrAbort() 37 isDexSupported, err = pkg.IsVerrazzanoMinVersion(constants.VerrazzanoVersion1_7_0, kubeConfigPath) 38 if err != nil { 39 AbortSuite(fmt.Sprintf("Failed to check Verrazzano min version %s: %v", constants.VerrazzanoVersion1_7_0, err)) 40 } 41 42 inClusterVZ, err = pkg.GetVerrazzanoInstallResourceInClusterV1beta1(kubeConfigPath) 43 if err != nil { 44 AbortSuite(fmt.Sprintf("Failed to get Verrazzano from the cluster: %v", err)) 45 } 46 isDexInstalled = vzcr.IsDexEnabled(inClusterVZ) 47 }) 48 49 // AfterEach wraps Ginkgo AfterEach to emit a metric 50 var _ = t.AfterEach(func() {}) 51 52 var _ = BeforeSuite(beforeSuite) 53 54 func getKubeConfigOrAbort() string { 55 kubeConfigPath, err := k8sutil.GetKubeConfigLocation() 56 if err != nil { 57 AbortSuite(fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error())) 58 } 59 return kubeConfigPath 60 } 61 62 // 'It' Wrapper to only run spec if the Dex is supported on the current Verrazzano version and is installed 63 func WhenDexInstalledIt(description string, f func()) { 64 t.It(description, func() { 65 if isDexSupported && isDexInstalled { 66 f() 67 } else { 68 t.Logs.Infof("Skipping check '%v', Dex is not installed on this cluster", description) 69 } 70 }) 71 } 72 73 var _ = t.Describe("Dex", Label("f:platform-lcm.install"), func() { 74 t.Context("after successful installation", func() { 75 // GIVEN the Dex is installed 76 // WHEN we check to make sure the pods exist 77 // THEN we successfully find the pods in the cluster 78 WhenDexInstalledIt("expected pod is running", func() { 79 pods := []string{"dex"} 80 t.Logs.Infof("Expected Dex pods: %v", pods) 81 82 Eventually(func() (bool, error) { 83 result, err := pkg.PodsRunning(constants.DexNamespace, pods) 84 if err != nil { 85 t.Logs.Errorf("Pods %v are not running in the namespace: %v, error: %v", pods, constants.VerrazzanoMonitoringNamespace, err) 86 } 87 return result, err 88 }, waitTimeout, pollingInterval).Should(BeTrue(), "Expected Dex pod should be running") 89 }) 90 91 // GIVEN the Dex is installed 92 // WHEN we check to make sure the ingress is created 93 // THEN we successfully find the ingresses in the cluster 94 WhenDexInstalledIt("Dex ingress exists", func() { 95 ing := []string{constants.DexIngress} 96 t.Logs.Infof("Expected Dex ingresses %v", ing) 97 Eventually(func() (bool, error) { 98 return pkg.IngressesExist(inClusterVZ, constants.DexNamespace, ing) 99 }, waitTimeout, pollingInterval).Should(BeTrue(), "Expected Dex Ingress should exist") 100 }) 101 102 // GIVEN the Dex is installed 103 // WHEN we check to make sure the PKCE secret is created 104 // THEN we successfully find the secret in the cluster 105 WhenDexInstalledIt("PKCE secret exists", func() { 106 Eventually(func() bool { 107 result, err := pkg.DoesSecretExist(constants.DexNamespace, pkceClientSecret) 108 if err != nil { 109 AbortSuite(fmt.Sprintf("Secret %s does not exist in the namespace: %v, error: %v", pkceClientSecret, constants.DexNamespace, err)) 110 } 111 return result 112 }, waitTimeout, pollingInterval).Should(BeTrue(), "Failed to find PKCE secret") 113 }) 114 }) 115 })