Skip to content

Commit c8c4280

Browse files
MLE-4131: added e2e tests for path based routing (#196)
* added e2e tests for path-based routing
1 parent 3e6993c commit c8c4280

File tree

1 file changed

+274
-0
lines changed

1 file changed

+274
-0
lines changed

test/e2e/path_based_test.go

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
package e2e
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"os"
7+
"path/filepath"
8+
"strings"
9+
"testing"
10+
"time"
11+
12+
"github.com/gruntwork-io/terratest/modules/helm"
13+
"github.com/gruntwork-io/terratest/modules/k8s"
14+
"github.com/gruntwork-io/terratest/modules/random"
15+
"github.com/imroc/req/v3"
16+
"github.com/tidwall/gjson"
17+
)
18+
19+
func TestPathBasedRouting(t *testing.T) {
20+
// Path to the helm chart we will test
21+
helmChartPath, e := filepath.Abs("../../charts")
22+
if e != nil {
23+
t.Fatalf(e.Error())
24+
}
25+
username := "admin"
26+
password := "admin"
27+
28+
imageRepo, repoPres := os.LookupEnv("dockerRepository")
29+
imageTag, tagPres := os.LookupEnv("dockerVersion")
30+
31+
if !repoPres {
32+
imageRepo = "ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-centos"
33+
t.Logf("No imageRepo variable present, setting to default value: " + imageRepo)
34+
}
35+
36+
if !tagPres {
37+
imageTag = "11.0.nightly-centos-1.0.2"
38+
t.Logf("No imageTag variable present, setting to default value: " + imageTag)
39+
}
40+
41+
namespaceName := "ml-" + strings.ToLower(random.UniqueId())
42+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
43+
options := &helm.Options{
44+
KubectlOptions: kubectlOptions,
45+
SetValues: map[string]string{
46+
"persistence.enabled": "false",
47+
"replicaCount": "3",
48+
"image.repository": imageRepo,
49+
"image.tag": imageTag,
50+
"auth.adminUsername": username,
51+
"auth.adminPassword": password,
52+
"logCollection.enabled": "false",
53+
"haproxy.enabled": "true",
54+
"haproxy.replicaCount": "1",
55+
"haproxy.frontendPort": "80",
56+
"haproxy.pathbased.enabled": "true",
57+
},
58+
}
59+
60+
t.Logf("====Creating namespace: " + namespaceName)
61+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
62+
63+
defer t.Logf("====Deleting namespace: " + namespaceName)
64+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
65+
66+
t.Logf("====Installing Helm Chart")
67+
releaseName := "test-path"
68+
helm.Install(t, options, helmChartPath, releaseName)
69+
70+
podName := releaseName + "-2"
71+
svcName := releaseName + "-haproxy"
72+
73+
// wait until the pod is in Ready status
74+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 15, 20*time.Second)
75+
76+
tunnel := k8s.NewTunnel(
77+
kubectlOptions, k8s.ResourceTypeService, svcName, 8080, 80)
78+
defer tunnel.Close()
79+
tunnel.ForwardPort(t)
80+
81+
client := req.C().
82+
SetCommonBasicAuth(username, password).
83+
SetCommonRetryCount(15).
84+
SetCommonRetryFixedInterval(15 * time.Second)
85+
86+
paths := [3]string{"adminUI", "manage/dashboard", "console/qconsole/"}
87+
// using loop to verify path based routing
88+
for i := 0; i < len(paths); i++ {
89+
endpoint := fmt.Sprintf("http://localhost:8080/%s", paths[i])
90+
t.Logf("Verifying path based routing using %s", endpoint)
91+
resp, err := client.R().
92+
AddRetryCondition(func(resp *req.Response, err error) bool {
93+
if err != nil {
94+
t.Logf("error: %s", err.Error())
95+
}
96+
if resp.GetStatusCode() != 200 {
97+
t.Log("Waiting for MarkLogic cluster to be ready")
98+
}
99+
return resp.GetStatusCode() != 200
100+
}).
101+
Get(endpoint)
102+
103+
if err != nil {
104+
t.Errorf("Error routing to %s", paths[i])
105+
t.Fatalf(err.Error())
106+
}
107+
defer resp.Body.Close()
108+
}
109+
110+
appServers := [3]string{"Admin", "Manage", "App-Services"}
111+
// using loop to verify authentication for all 3 AppServers
112+
for i := 0; i < len(appServers); i++ {
113+
endpoint := fmt.Sprintf("http://localhost:8080/manage/manage/v2/servers/%s/properties?group-id=Default&format=json", appServers[i])
114+
t.Logf("Endpoint for %s AppServer is %s", appServers[i], endpoint)
115+
resp, err := client.R().
116+
AddRetryCondition(func(resp *req.Response, err error) bool {
117+
if err != nil {
118+
t.Logf("error: %s", err.Error())
119+
}
120+
t.Logf("StatusCode: %d", resp.GetStatusCode())
121+
if resp.GetStatusCode() != 200 {
122+
t.Log("Waiting for MarkLogic cluster to be ready")
123+
}
124+
return resp.GetStatusCode() != 200
125+
}).
126+
Get(endpoint)
127+
128+
if err != nil {
129+
t.Errorf("Error getting AppServer properties")
130+
t.Fatalf(err.Error())
131+
}
132+
defer resp.Body.Close()
133+
134+
body, err := io.ReadAll(resp.Body)
135+
if err != nil {
136+
t.Fatalf(err.Error())
137+
}
138+
serverAuthentication := gjson.Get(string(body), `authentication`)
139+
t.Logf("serverAuthentication: %s", serverAuthentication)
140+
//verify basic authentication is configured for AppServer
141+
t.Logf("Verifying authentication for %s AppServer", appServers[i])
142+
if serverAuthentication.Str != "basic" {
143+
t.Errorf("basic authentication is not configured for %s AppServer", appServers[i])
144+
}
145+
}
146+
}
147+
148+
func TestPathBasedRoutingWithTLS(t *testing.T) {
149+
// Path to the helm chart we will test
150+
helmChartPath, e := filepath.Abs("../../charts")
151+
if e != nil {
152+
t.Fatalf(e.Error())
153+
}
154+
username := "admin"
155+
password := "admin"
156+
157+
imageRepo, repoPres := os.LookupEnv("dockerRepository")
158+
imageTag, tagPres := os.LookupEnv("dockerVersion")
159+
160+
if !repoPres {
161+
imageRepo = "ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-centos"
162+
t.Logf("No imageRepo variable present, setting to default value: " + imageRepo)
163+
}
164+
165+
if !tagPres {
166+
imageTag = "11.0.nightly-centos-1.0.2"
167+
t.Logf("No imageTag variable present, setting to default value: " + imageTag)
168+
}
169+
170+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
171+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
172+
options := &helm.Options{
173+
KubectlOptions: kubectlOptions,
174+
SetValues: map[string]string{
175+
"persistence.enabled": "false",
176+
"replicaCount": "3",
177+
"image.repository": imageRepo,
178+
"image.tag": imageTag,
179+
"auth.adminUsername": username,
180+
"auth.adminPassword": password,
181+
"logCollection.enabled": "false",
182+
"tls.enableOnDefaultAppServers": "true",
183+
"haproxy.enabled": "true",
184+
"haproxy.replicaCount": "1",
185+
"haproxy.frontendPort": "80",
186+
"haproxy.pathbased.enabled": "true",
187+
},
188+
}
189+
190+
t.Logf("====Creating namespace: " + namespaceName)
191+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
192+
193+
defer t.Logf("====Deleting namespace: " + namespaceName)
194+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
195+
196+
t.Logf("====Installing Helm Chart")
197+
releaseName := "test-pb-tls"
198+
helm.Install(t, options, helmChartPath, releaseName)
199+
200+
podName := releaseName + "-2"
201+
svcName := releaseName + "-haproxy"
202+
203+
// wait until the pod is in Ready status
204+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 20*time.Second)
205+
206+
tunnel := k8s.NewTunnel(
207+
kubectlOptions, k8s.ResourceTypeService, svcName, 8080, 80)
208+
defer tunnel.Close()
209+
tunnel.ForwardPort(t)
210+
211+
client := req.C().
212+
EnableInsecureSkipVerify().
213+
SetCommonBasicAuth(username, password).
214+
SetCommonRetryCount(15).
215+
SetCommonRetryFixedInterval(15 * time.Second)
216+
217+
paths := [3]string{"adminUI", "manage/dashboard", "console/qconsole/"}
218+
// using loop to verify path based routing
219+
for i := 0; i < len(paths); i++ {
220+
endpoint := fmt.Sprintf("http://localhost:8080/%s", paths[i])
221+
t.Logf("Verifying path based routing using %s", endpoint)
222+
resp, err := client.R().
223+
AddRetryCondition(func(resp *req.Response, err error) bool {
224+
if err != nil {
225+
t.Logf("error: %s", err.Error())
226+
}
227+
if resp.GetStatusCode() != 200 {
228+
t.Log("Waiting for MarkLogic cluster to be ready")
229+
}
230+
return resp.GetStatusCode() != 200
231+
}).
232+
Get(endpoint)
233+
234+
if err != nil {
235+
t.Errorf("Error routing to %s", paths[i])
236+
t.Fatalf(err.Error())
237+
}
238+
defer resp.Body.Close()
239+
}
240+
241+
appServers := [3]string{"Admin", "Manage", "App-Services"}
242+
// using loop to verify authentication for all 3 AppServers
243+
for i := 0; i < len(appServers); i++ {
244+
endpoint := fmt.Sprintf("http://localhost:8080/manage/manage/v2/servers/%s/properties?group-id=Default&format=json", appServers[i])
245+
t.Logf("Endpoint for %s AppServer is %s", appServers[i], endpoint)
246+
resp, err := client.R().
247+
Get(endpoint)
248+
249+
if err != nil {
250+
t.Errorf("Error getting AppServer properties")
251+
t.Fatalf(err.Error())
252+
}
253+
defer resp.Body.Close()
254+
255+
body, err := io.ReadAll(resp.Body)
256+
if err != nil {
257+
t.Fatalf(err.Error())
258+
}
259+
260+
serverAuthentication := gjson.Get(string(body), `authentication`)
261+
//verify basic authentication is configured for AppServer
262+
t.Logf("Verifying authentication for %s AppServer", appServers[i])
263+
if serverAuthentication.Str != "basic" {
264+
t.Errorf("basic authentication is not configured for %s AppServer", appServers[i])
265+
}
266+
267+
sslAllowTLS := gjson.Get(string(body), `ssl-allow-tls`)
268+
//verify ssl is enabled for AppServer
269+
t.Logf("Verifying ssl for %s AppServer", appServers[i])
270+
if sslAllowTLS.Bool() != true {
271+
t.Errorf("ssl is not enabled for %s AppServer", appServers[i])
272+
}
273+
}
274+
}

0 commit comments

Comments
 (0)