Skip to content

Commit 6d145c1

Browse files
committed
add test case for random password
1 parent 72ad8fe commit 6d145c1

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

test/e2e/install_test.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1414
"github.com/gruntwork-io/terratest/modules/k8s"
1515
"github.com/gruntwork-io/terratest/modules/random"
16+
"github.com/stretchr/testify/assert"
17+
digestAuth "github.com/xinsnake/go-http-digest-auth-client"
1618
)
1719

1820
func TestHelmInstall(t *testing.T) {
@@ -61,21 +63,44 @@ func TestHelmInstall(t *testing.T) {
6163
podName := releaseName + "-marklogic-0"
6264
// wait until the pod is in Ready status
6365
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second)
64-
tunnel := k8s.NewTunnel(
65-
kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
66-
defer tunnel.Close()
67-
tunnel.ForwardPort(t)
68-
endpoint := fmt.Sprintf("http://%s", tunnel.Endpoint())
69-
t.Logf(`Endpoint: %s`, endpoint)
66+
tunnel7997 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
67+
defer tunnel7997.Close()
68+
tunnel7997.ForwardPort(t)
69+
endpoint7997 := fmt.Sprintf("http://%s", tunnel7997.Endpoint())
7070

71+
// verify if 7997 health check endpoint returns 200
7172
http_helper.HttpGetWithRetryWithCustomValidation(
7273
t,
73-
endpoint,
74+
endpoint7997,
7475
&tlsConfig,
7576
10,
7677
15*time.Second,
7778
func(statusCode int, body string) bool {
7879
return statusCode == 200
7980
},
8081
)
82+
83+
// testing generated Random Password
84+
secretName := releaseName + "-marklogic"
85+
secret := k8s.GetSecret(t, kubectlOptions, secretName)
86+
username := "admin"
87+
passwordArr := secret.Data["marklogic-password"]
88+
password := string(passwordArr[:])
89+
// the generated random password should have length of 10
90+
assert.Equal(t, 10, len(password))
91+
92+
tunnel_8002 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
93+
defer tunnel_8002.Close()
94+
tunnel_8002.ForwardPort(t)
95+
endpointManage := fmt.Sprintf("http://%s/manage/v2", tunnel_8002.Endpoint())
96+
97+
request := digestAuth.NewRequest(username, password, "GET", endpointManage, "")
98+
response, err := request.Execute()
99+
if err != nil {
100+
t.Fatalf(err.Error())
101+
}
102+
defer response.Body.Close()
103+
// the generated password should be able to access the manage endpoint
104+
assert.Equal(t, 200, response.StatusCode)
105+
81106
}

0 commit comments

Comments
 (0)