Skip to content

Commit

Permalink
Randomized input passwords for the TF chart
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dimitrov <[email protected]>
  • Loading branch information
cranzy committed Mar 5, 2024
1 parent c84b5fd commit 4e2923b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
38 changes: 31 additions & 7 deletions test/smoke/smoke_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//go:build smoke && !unit

package smoke_test

import (
"fmt"
"log"
"testing"

"github.com/Mirantis/mcc/pkg/config"
Expand All @@ -17,7 +17,7 @@ var AWS = map[string]interface{}{

var MKE_CONNECT = map[string]interface{}{
"username": "admin",
"password": "m!rantis2024",
"password": "",
"insecure": false,
}

Expand All @@ -38,13 +38,25 @@ var NETWORK = map[string]interface{}{

// TestSmallCluster deploys a small test cluster
func TestSmallCluster(t *testing.T) {
log.Println("TestSmallCluster")
nodegroups := map[string]interface{}{
"MngrUbuntu22": test.Platforms["Ubuntu22"].GetManager(),
"WrkUbuntu22": test.Platforms["Ubuntu22"].GetWorker(),
"WrkWindows19": test.Platforms["Windows2019"].GetWorker(),
}

name := "smoke-small"
uTestId, err := test.GenerateRandomString(5)
if err != nil {
t.Fatal(err)
}
name := fmt.Sprintf("smoke-%s", uTestId)

rndPassword, err := test.GenerateRandomString(12)
if err != nil {
t.Fatal(err)
}

MKE_CONNECT["password"] = rndPassword

// Create a temporary directory to store Terraform files
tempSSHKeyPathDir := t.TempDir()
Expand All @@ -59,7 +71,7 @@ func TestSmallCluster(t *testing.T) {
"network": NETWORK,
"ssh_pk_location": tempSSHKeyPathDir,
"nodegroups": nodegroups,
"windows_password": "w!ndozePassw0rd",
"windows_password": rndPassword,
},
}

Expand Down Expand Up @@ -87,6 +99,7 @@ func TestSmallCluster(t *testing.T) {

// TestSupportedMatrixCluster deploys a cluster with all supported platforms
func TestSupportedMatrixCluster(t *testing.T) {
log.Println("TestSupportedMatrixCluster")
nodegroups := map[string]interface{}{
"MngrUbuntu22": test.Platforms["Ubuntu22"].GetManager(),
"MngrRocky9": test.Platforms["Rocky9"].GetManager(),
Expand All @@ -103,7 +116,18 @@ func TestSupportedMatrixCluster(t *testing.T) {
"WrkWindows22": test.Platforms["Windows2022"].GetWorker(),
}

name := "smoke-full"
uTestId, err := test.GenerateRandomString(5)
if err != nil {
t.Fatal(err)
}
name := fmt.Sprintf("smoke-%s", uTestId)

rndPassword, err := test.GenerateRandomString(12)
if err != nil {
t.Fatal(err)
}

MKE_CONNECT["password"] = rndPassword

// Create a temporary directory to store Terraform files
tempSSHKeyPathDir := t.TempDir()
Expand All @@ -118,7 +142,7 @@ func TestSupportedMatrixCluster(t *testing.T) {
"network": NETWORK,
"ssh_pk_location": tempSSHKeyPathDir,
"nodegroups": nodegroups,
"windows_password": "w!ndozePassw0rd",
"windows_password": rndPassword,
},
}

Expand Down
16 changes: 16 additions & 0 deletions test/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test

import (
"crypto/rand"
"encoding/base64"
)

// GenerateRandomString generates a random string of a given length
func GenerateRandomString(length int) (string, error) {
bytes := make([]byte, length)
_, err := rand.Read(bytes)
if err != nil {
return "", err
}
return base64.URLEncoding.EncodeToString(bytes)[:length], nil
}

0 comments on commit 4e2923b

Please sign in to comment.