From 85641e219f8c4a4284ba759f628726090825ffe4 Mon Sep 17 00:00:00 2001 From: yuwan Date: Tue, 7 May 2024 15:29:19 +0800 Subject: [PATCH] OCM-7537 | ci: fix id:45161,id:49137,id:66362,id:36128,id:43046 --- go.mod | 2 +- tests/e2e/test_rosacli_network_verifier.go | 1 - tests/e2e/test_rosacli_oidc_provider.go | 7 +----- tests/e2e/test_rosacli_user.go | 27 +++++++++------------- tests/utils/common/idp.go | 10 ++++---- tests/utils/config/cluster_command.go | 1 + 6 files changed, 19 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index 04923a9100..6eadf0592a 100644 --- a/go.mod +++ b/go.mod @@ -115,7 +115,7 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect github.com/zalando/go-keyring v0.2.3 // indirect - golang.org/x/crypto v0.22.0 // indirect + golang.org/x/crypto v0.22.0 golang.org/x/net v0.21.0 // indirect golang.org/x/oauth2 v0.16.0 // indirect golang.org/x/sys v0.19.0 // indirect diff --git a/tests/e2e/test_rosacli_network_verifier.go b/tests/e2e/test_rosacli_network_verifier.go index bfece7de97..3692d8bc92 100644 --- a/tests/e2e/test_rosacli_network_verifier.go +++ b/tests/e2e/test_rosacli_network_verifier.go @@ -141,7 +141,6 @@ var _ = Describe("Network verifier", "--hosted-cp", ) Expect(err).ToNot(HaveOccurred()) - }) }) diff --git a/tests/e2e/test_rosacli_oidc_provider.go b/tests/e2e/test_rosacli_oidc_provider.go index 386945a1d6..384a9dd338 100644 --- a/tests/e2e/test_rosacli_oidc_provider.go +++ b/tests/e2e/test_rosacli_oidc_provider.go @@ -47,7 +47,6 @@ var _ = Describe("OIDC provider", Expect(err).To(BeNil()) By("Check if cluster is using reusable oidc config") - UsingReusableOIDCConfig, err := clusterService.IsUsingReusableOIDCConfig(clusterID) Expect(err).To(BeNil()) notExistedClusterID := "notexistedclusterid111" @@ -61,11 +60,7 @@ var _ = Describe("OIDC provider", "-y") Expect(err).To(BeNil()) textData := rosaClient.Parser.TextData.Input(output).Parse().Tip() - if UsingReusableOIDCConfig { - Expect(textData).To(ContainSubstring("OIDC provider already exists")) - } else { - Expect(textData).To(ContainSubstring("is ready and does not need additional configuration")) - } + Expect(textData).To(ContainSubstring("OIDC provider already exists")) case false: By("Create oidc-provider on classic non-sts cluster") output, err := ocmResourceService.CreateOIDCProvider( diff --git a/tests/e2e/test_rosacli_user.go b/tests/e2e/test_rosacli_user.go index eea4aeeb47..5832b32c84 100644 --- a/tests/e2e/test_rosacli_user.go +++ b/tests/e2e/test_rosacli_user.go @@ -48,19 +48,27 @@ var _ = Describe("Edit User", ) By("Try to list the user when there is no one") + rosaClient.Runner.JsonFormat() + defer func() { + rosaClient.Runner.UnsetFormat() + }() + _, output, err := userService.ListUsers(clusterID) Expect(err).ToNot(HaveOccurred()) - textData := rosaClient.Parser.TextData.Input(output).Parse().Tip() - Expect(textData).To(ContainSubstring("INFO: There are no users configured for cluster '%s'", clusterID)) + if output.String() == "[]" { + textData := rosaClient.Parser.TextData.Input(output).Parse().Tip() + Expect(textData).To(ContainSubstring("INFO: There are no users configured for cluster '%s'", clusterID)) + } By("Grant dedicated-admins user") + rosaClient.Runner.UnsetFormat() out, err := userService.GrantUser( clusterID, dedicatedAdminsGroupName, dedicatedAdminsUserName, ) Expect(err).ToNot(HaveOccurred()) - textData = rosaClient.Parser.TextData.Input(out).Parse().Tip() + textData := rosaClient.Parser.TextData.Input(out).Parse().Tip() Expect(textData).Should(ContainSubstring("Granted role '%s' to user '%s' on cluster '%s'", dedicatedAdminsGroupName, dedicatedAdminsUserName, clusterID)) By("Grant cluster-admins user") @@ -129,7 +137,6 @@ var _ = Describe("Validate user", defer GinkgoRecover() var ( invalidPassword = "password1" // disallowed password - validPassword = "Th3long,validpassword" clusterID string rosaClient *rosacli.Client @@ -164,18 +171,6 @@ var _ = Describe("Validate user", textData = rosaClient.Parser.TextData.Input(output).Parse().Tip() Expect(err).To(HaveOccurred()) Expect(textData).Should(ContainSubstring("assword must be at least")) - - By("Try to create Hypershift cluster with admin username and password set (unsupported)") - output, err = clusterService.CreateDryRun(clusterID, "--hosted-cp", - "--cluster-admin-password", validPassword, - "--region", "us-west-2", - "--support-role-arn", "fake", - "--controlplane-iam-role", "fake", - "--worker-iam-role", "fake", - "--mode", "auto", "-y") - textData = rosaClient.Parser.TextData.Input(output).Parse().Tip() - Expect(err).To(HaveOccurred()) - Expect(textData).Should(ContainSubstring("is only supported in classic")) }) }) diff --git a/tests/utils/common/idp.go b/tests/utils/common/idp.go index 9ed651a873..5bb2ffdb45 100644 --- a/tests/utils/common/idp.go +++ b/tests/utils/common/idp.go @@ -2,22 +2,22 @@ package common import ( "fmt" - "os/exec" "strings" + "golang.org/x/crypto/bcrypt" + . "github.com/openshift/rosa/tests/utils/log" ) // Generate htpasspwd key value pair, return with a string func GenerateHtpasswdPair(user string, pass string) (string, string, string, error) { - generateCMD := fmt.Sprintf("htpasswd -Bbn %s %s", user, pass) - output, err := exec.Command("bash", "-c", generateCMD).Output() - htpasswdPair := strings.TrimSpace(string(output)) - parts := strings.SplitN(htpasswdPair, ":", 2) + hashedPassword, err := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost) if err != nil { Logger.Errorf("Fail to generate htpasswd file: %v", err) return "", "", "", err } + htpasswdPair := fmt.Sprintf("%s:%s", user, string(hashedPassword)) + parts := strings.SplitN(htpasswdPair, ":", 2) return htpasswdPair, parts[0], parts[1], nil } diff --git a/tests/utils/config/cluster_command.go b/tests/utils/config/cluster_command.go index 085b57310e..c36f5c3b89 100644 --- a/tests/utils/config/cluster_command.go +++ b/tests/utils/config/cluster_command.go @@ -80,6 +80,7 @@ func (c *command) GetFlagValue(flag string, flagWithVaue bool) string { // Add flags to the command func (c *command) AddFlags(flags ...string) { for _, flag := range flags { + c.cmd = strings.TrimSpace(c.cmd) // combine the command with space c.cmd += " " + flag }