github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/container/containerv2/openshift_test.go (about) 1 package containerv2 2 3 /******************************************************************************* 4 * IBM Confidential 5 * OCO Source Materials 6 * IBM Cloud Schematics 7 * (C) Copyright IBM Corp. 2023 All Rights Reserved. 8 * The source code for this program is not published or otherwise divested of 9 * its trade secrets, irrespective of what has been deposited with 10 * the U.S. Copyright Office. 11 ******************************************************************************/ 12 13 import ( 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 ) 17 18 const ( 19 OauthPrivateEndpoint = "https://c200-e.private.test.containers.cloud.ibm.com:31579/.well-known/oauth-authorization-server" 20 OauthVirtualPrivateEndpoint = "https://clusterID.vpe.private.test.containers.cloud.ibm.com:31579/.well-known/oauth-authorization-server" 21 ServerPrivateEndpoint = "https://c200.private.test.containers.cloud.ibm.com:31580" 22 ServerVirtualPrivateEndpoint = "https://clusterID.vpe.private.test.containers.cloud.ibm.com:31580" 23 ) 24 25 var _ = Describe("Openshift utils", func() { 26 Describe("Openshift related AuthEndpoint modification", func() { 27 Context("AuthEndpoint is configured with private", func() { 28 It("should not change it", func() { 29 clusterInfo := ClusterInfo{ 30 ServiceEndpoints: Endpoints{ 31 PrivateServiceEndpointEnabled: true, 32 PrivateServiceEndpointURL: ServerPrivateEndpoint, 33 }, 34 VirtualPrivateEndpointURL: ServerVirtualPrivateEndpoint, 35 } 36 authServer, err := reconfigureAuthorizationEndpoint(OauthPrivateEndpoint, "private", &clusterInfo) 37 Expect(authServer).ShouldNot(BeEmpty()) 38 Expect(err).NotTo(HaveOccurred()) 39 Expect(authServer).Should(Equal(OauthPrivateEndpoint)) 40 }) 41 }) 42 Context("AuthEndpoint is configured with VPE", func() { 43 It("should not change it", func() { 44 clusterInfo := ClusterInfo{ 45 ServiceEndpoints: Endpoints{ 46 PrivateServiceEndpointEnabled: true, 47 PrivateServiceEndpointURL: ServerPrivateEndpoint, 48 }, 49 VirtualPrivateEndpointURL: ServerVirtualPrivateEndpoint, 50 } 51 authServer, err := reconfigureAuthorizationEndpoint(OauthVirtualPrivateEndpoint, VirtualPrivateEndpoint, &clusterInfo) 52 Expect(authServer).ShouldNot(BeEmpty()) 53 Expect(err).NotTo(HaveOccurred()) 54 Expect(authServer).Should(Equal(OauthVirtualPrivateEndpoint)) 55 }) 56 }) 57 Context("AuthEndpoint is configured with Private", func() { 58 It("should replace to VPE - case for ROKS 4.12", func() { 59 clusterInfo := ClusterInfo{ 60 ServiceEndpoints: Endpoints{ 61 PrivateServiceEndpointEnabled: true, 62 PrivateServiceEndpointURL: ServerPrivateEndpoint, 63 }, 64 VirtualPrivateEndpointURL: ServerVirtualPrivateEndpoint, 65 } 66 authServer, err := reconfigureAuthorizationEndpoint(OauthPrivateEndpoint, VirtualPrivateEndpoint, &clusterInfo) 67 Expect(authServer).ShouldNot(BeEmpty()) 68 Expect(err).NotTo(HaveOccurred()) 69 Expect(authServer).Should(Equal(OauthVirtualPrivateEndpoint)) 70 }) 71 }) 72 Context("AuthEndpoint is configured with VPE", func() { 73 It("should replace to Private - case for ROKS 4.13", func() { 74 clusterInfo := ClusterInfo{ 75 ServiceEndpoints: Endpoints{ 76 PrivateServiceEndpointEnabled: true, 77 PrivateServiceEndpointURL: ServerPrivateEndpoint, 78 }, 79 VirtualPrivateEndpointURL: ServerVirtualPrivateEndpoint, 80 } 81 authServer, err := reconfigureAuthorizationEndpoint(OauthVirtualPrivateEndpoint, PrivateServiceEndpoint, &clusterInfo) 82 Expect(authServer).ShouldNot(BeEmpty()) 83 Expect(err).NotTo(HaveOccurred()) 84 Expect(authServer).Should(Equal(OauthPrivateEndpoint)) 85 }) 86 }) 87 Context("AuthEndpoint is empty", func() { 88 It("should shall fail", func() { 89 clusterInfo := ClusterInfo{ 90 ServiceEndpoints: Endpoints{ 91 PrivateServiceEndpointEnabled: true, 92 PrivateServiceEndpointURL: ServerPrivateEndpoint, 93 }, 94 VirtualPrivateEndpointURL: ServerVirtualPrivateEndpoint, 95 } 96 authServer, err := reconfigureAuthorizationEndpoint("", PrivateEndpointDNS, &clusterInfo) 97 Expect(authServer).Should(BeEmpty()) 98 Expect(err).Should(HaveOccurred()) 99 }) 100 }) 101 Context("AuthEndpoint is configured with private - request to change", func() { 102 It("should fail as Virtual Private Endpoint URL is empty", func() { 103 clusterInfo := ClusterInfo{ 104 ServiceEndpoints: Endpoints{ 105 PrivateServiceEndpointEnabled: false, 106 PrivateServiceEndpointURL: "", 107 }, 108 VirtualPrivateEndpointURL: "", 109 } 110 authServer, err := reconfigureAuthorizationEndpoint(OauthPrivateEndpoint, VirtualPrivateEndpoint, &clusterInfo) 111 Expect(authServer).Should(BeEmpty()) 112 Expect(err).Should(HaveOccurred()) 113 }) 114 }) 115 Context("AuthEndpoint is configured with VPE - request to change", func() { 116 It("should fail as Private Service Endpoint URL is empty", func() { 117 clusterInfo := ClusterInfo{ 118 ServiceEndpoints: Endpoints{ 119 PrivateServiceEndpointEnabled: true, 120 PrivateServiceEndpointURL: "", 121 }, 122 VirtualPrivateEndpointURL: ServerVirtualPrivateEndpoint, 123 } 124 authServer, err := reconfigureAuthorizationEndpoint(OauthVirtualPrivateEndpoint, PrivateServiceEndpoint, &clusterInfo) 125 Expect(authServer).Should(BeEmpty()) 126 Expect(err).Should(HaveOccurred()) 127 }) 128 }) 129 Context("AuthEndpoint is configured with VPE", func() { 130 It("should not change it as endpointType is empty", func() { 131 clusterInfo := ClusterInfo{ 132 ServiceEndpoints: Endpoints{ 133 PrivateServiceEndpointEnabled: false, 134 PrivateServiceEndpointURL: "", 135 }, 136 VirtualPrivateEndpointURL: ServerVirtualPrivateEndpoint, 137 } 138 authServer, err := reconfigureAuthorizationEndpoint(OauthVirtualPrivateEndpoint, "", &clusterInfo) 139 Expect(authServer).NotTo(BeEmpty()) 140 Expect(err).NotTo(HaveOccurred()) 141 Expect(authServer).Should(Equal(OauthVirtualPrivateEndpoint)) 142 }) 143 }) 144 }) 145 })