Skip to content

Commit

Permalink
OCM-9817 | test: automate id:75210 delete byo oidc config via rosacli
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwang-RH committed Jul 26, 2024
1 parent 6f483e8 commit 299e00a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 6 deletions.
88 changes: 88 additions & 0 deletions tests/e2e/test_rosacli_cluster_post.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package e2e

import (
"context"
"fmt"
"io"
nets "net/http"
"strings"

"github.com/aws/aws-sdk-go-v2/service/iam"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/openshift-online/ocm-common/pkg/aws/aws_client"
Expand Down Expand Up @@ -374,6 +376,92 @@ var _ = Describe("Create cluster with the version in some channel group testing"
Expect(versionOutput.ChannelGroup).To(Equal(profile.ChannelGroup))
})
})

var _ = Describe("Delete BYO OIDC cluster testing",
labels.Feature.Cluster, func() {
defer GinkgoRecover()
var (
rosaClient *rosacli.Client
ocmResourceService rosacli.OCMResourceService
clusterService rosacli.ClusterService
clusterID string
err error
awsClient *aws_client.AWSClient
oidcEndpointUrlC string
clusterConfig *config.ClusterConfig
oidcConfigC string
oidcProviderArn string
profile *profilehandler.Profile
)

BeforeEach(func() {
By("Init the client and get profile and config")
awsClient, err = aws_client.CreateAWSClient("", "")
Expect(err).To(BeNil())
rosaClient = rosacli.NewClient()
clusterService = rosaClient.Cluster
ocmResourceService = rosaClient.OCMResource

clusterConfig, err = config.ParseClusterProfile()
Expect(err).ToNot(HaveOccurred())

profile = profilehandler.LoadProfileYamlFileByENV()
Expect(err).ToNot(HaveOccurred())
})

It("to verifiy the byo oidc cluster is deleted successfully - [id:75210]",
labels.Critical, labels.Runtime.DestroyPost,
func() {

By("Check if it is using oidc config")
if profile.ClusterConfig.OIDCConfig == "" {
Skip("Skip this case as it is only for byo oidc cluster")
}
By("Get aws account id")
rosaClient.Runner.JsonFormat()
whoamiOutput, err := ocmResourceService.Whoami()
Expect(err).To(BeNil())
rosaClient.Runner.UnsetFormat()
whoamiData := ocmResourceService.ReflectAccountsInfo(whoamiOutput)
AWSAccountID := whoamiData.AWSAccountID

By("Get the oidc config and cluster id from cluster config file")
clusterID = config.GetClusterID()
oidcConfigC = clusterConfig.Aws.Sts.OidcConfigID

By("Get oidc endpoint URL from cluster detail json file")
clusterDetail, err := profilehandler.ParserClusterDetail()
Expect(err).To(BeNil())
oidcEndpointUrlC = clusterDetail.OIDCEndpointURL
oidcEndpointUrlC, err = common.ExtractOIDCProviderFromOidcUrl(oidcEndpointUrlC)
Expect(err).To(BeNil())

By("Check the cluster is deleted")
rosaClient.Runner.UnsetArgs()
clusterListout, err := clusterService.List()
Expect(err).To(BeNil())
clusterList, err := clusterService.ReflectClusterList(clusterListout)
Expect(err).To(BeNil())
Expect(clusterList.IsExist(clusterID)).To(BeFalse())

By("Check the oidc config is deleted")
out, err := ocmResourceService.GetOIDCConfigFromList(oidcConfigC)
Expect(err).To(BeNil())
Expect(out).To(Equal(rosacli.OIDCConfig{}))

By("Check oidc provider is deleted")
oidcProviderArn = fmt.Sprintf("arn:aws:iam::%s:oidc-provider/%s", AWSAccountID, oidcEndpointUrlC)
_, err = awsClient.IamClient.GetOpenIDConnectProvider(
context.TODO(),
&iam.GetOpenIDConnectProviderInput{
OpenIDConnectProviderArn: &oidcProviderArn,
},
)
Expect(err).ToNot(BeNil())
Expect(err.Error()).To(ContainSubstring("NoSuchEntity"))

})
})
var _ = Describe("Create BYO OIDC cluster testing",
labels.Feature.Cluster, func() {
defer GinkgoRecover()
Expand Down
16 changes: 16 additions & 0 deletions tests/utils/common/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"bytes"
"fmt"
"net/url"
"regexp"
"strings"

Expand Down Expand Up @@ -105,3 +106,18 @@ func ParseIssuerURLFromCommand(command string) string {
re := regexp.MustCompile(`https://[^\s]+`)
return re.FindString(command)
}

// Extract oidc provider from the 'OIDC Endpoint URL' field of `rosa describe cluster`
func ExtractOIDCProviderFromOidcUrl(urlString string) (string, error) {
parsedURL, err := url.Parse(urlString)
if err != nil {
return "", err
}
host := parsedURL.Host
path := strings.TrimPrefix(parsedURL.Path, "/")
fmt.Printf("The past host and path is %s and %s\n", host, path)
oidcProvider := fmt.Sprintf("%s/%s", host, path)
oidcProvider = strings.Split(oidcProvider, " ")[0]

return oidcProvider, nil
}
13 changes: 7 additions & 6 deletions tests/utils/profilehandler/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ type UserData struct {

// ClusterDetail will record basic cluster info to support other team's testing
type ClusterDetail struct {
APIURL string `json:"api_url,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
ClusterName string `json:"cluster_name,omitempty"`
ClusterType string `json:"cluster_type,omitempty"`
ConsoleURL string `json:"console_url,omitempty"`
InfraID string `json:"infra_id,omitempty"`
APIURL string `json:"api_url,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
ClusterName string `json:"cluster_name,omitempty"`
ClusterType string `json:"cluster_type,omitempty"`
ConsoleURL string `json:"console_url,omitempty"`
InfraID string `json:"infra_id,omitempty"`
OIDCEndpointURL string `json:"oidc_endpoint_url,omitempty"`
}

type ProxyDetail struct {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/profilehandler/profile_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ func CreateClusterByProfileWithoutWaiting(
clusterDetail.ClusterID = description.ID
clusterDetail.ClusterName = description.Name
clusterDetail.ClusterType = "rosa"
clusterDetail.OIDCEndpointURL = description.OIDCEndpointURL

// Need to do the post step when cluster has no oidcconfig enabled
if profile.ClusterConfig.OIDCConfig == "" && profile.ClusterConfig.STS {
Expand Down

0 comments on commit 299e00a

Please sign in to comment.