Skip to content

Commit f080b8a

Browse files
committed
Add SSL to test CLI-Svc
Signed-off-by: Marc Khouzam <marc.khouzam@broadcom.com>
1 parent 1d8d410 commit f080b8a

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

Makefile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,27 @@ stop-airgapped-local-registry:
318318
@docker stop temp-airgapped-local-registry temp-airgapped-local-registry-with-auth > /dev/null 2>&1 && \
319319
echo "Stopping docker test airgapped repo if running..." || true
320320

321+
322+
.PHONY: setup-custom-cert-for-test-cli-service
323+
setup-custom-cert-for-test-cli-service: ## Setup up the custom ca cert for the test cli service in the config file
324+
@if [ ! -d $(ROOT_DIR)/hack/central-repo/certs ]; then \
325+
wget https://storage.googleapis.com/tanzu-cli/data/testcerts/local-central-repo-testcontent.bz2 -O $(ROOT_DIR)/hack/central-repo/local-central-repo-testcontent.bz2;\
326+
tar xjf $(ROOT_DIR)/hack/central-repo/local-central-repo-testcontent.bz2 -C $(ROOT_DIR)/hack/central-repo/;\
327+
fi
328+
@echo "Adding docker test cli service cert to the config file"
329+
@TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER="No" TANZU_CLI_EULA_PROMPT_ANSWER="Yes" $(ROOT_DIR)/bin/tanzu config cert delete localhost:9443 &> /dev/null || true
330+
$(ROOT_DIR)/bin/tanzu config cert add --host localhost:9443 --ca-cert $(ROOT_DIR)/hack/central-repo/certs/localhost.crt
331+
321332
.PHONY: start-test-cli-service
322-
start-test-cli-service: stop-test-cli-service ## Starts a test CLI service locally with docker
323-
@docker run -d --rm --name cli-service -p 8080:80 \
333+
start-test-cli-service: stop-test-cli-service setup-custom-cert-for-test-cli-service ## Starts a test CLI service locally with docker
334+
@docker run -d --rm --name cli-service -p 9443:443 \
335+
-v $(ROOT_DIR)/hack/central-repo/certs:/certs \
324336
-v $(ROOT_DIR)/hack/service/install.sh:/var/www/html/cli/v1/install/install.txt \
325337
-v $(ROOT_DIR)/hack/service/discovery:/var/www/html/cli/v1/plugin/discovery \
326338
-v $(ROOT_DIR)/hack/service/binaries:/var/www/html/cli/v1/binary \
327339
-v $(ROOT_DIR)/hack/service/cli-service.conf:/etc/nginx/conf.d/cli-service.conf \
328-
nginx:alpine && \
329-
echo "Started docker test cli service at 'localhost:8080'"
340+
nginx:alpine > /dev/null && \
341+
echo "Started docker test cli service at 'localhost:9443'"
330342

331343
.PHONY: stop-test-cli-service
332344
stop-test-cli-service: ## Stops and removes the local test CLI service

hack/service/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ This mock allows to run an nginx docker image which serves the same endpoints as
44
the ones the real CLI-Svc serves. It allows to test the CLI without using the
55
real CLI-Svc.
66

7-
The endpoints being mocked are:
7+
The endpoints being mocked use SSL and are:
88

9-
- localhost:8080/cli/v1/install
10-
- localhost:8080/cli/v1/plugin/discovery
11-
- localhost:8080/cli/v1/binary
9+
- localhost:9443/cli/v1/install
10+
- localhost:9443/cli/v1/plugin/discovery
11+
- localhost:9443/cli/v1/binary
1212

1313
## Using the test CLI-Svc
1414

@@ -19,19 +19,21 @@ To access the endpoints manually, e.g.,:
1919

2020
```console
2121
# NOTE: the trailing / is essential
22-
curl localhost:8080/cli/v1/plugin/discovery/
22+
curl https://localhost:9443/cli/v1/plugin/discovery/ --cacert hack/central-repo/certs/localhost.crt
23+
# or
24+
curl https://localhost:9443/cli/v1/plugin/discovery/ -k
2325
```
2426

2527
## Testing plugin discovery
2628

27-
If testing plugin discovery (localhost:8080/cli/v1/plugin/discovery/), the
29+
If testing plugin discovery (localhost:9443/cli/v1/plugin/discovery/), the
2830
test CLI-Svc will randomly serve different discovery data which is configured in
2931
`hack/service/cli-service.conf`.
3032

3133
To tell the CLI to use the test CLI-Svc we must execute:
3234

3335
```console
34-
export TANZU_CLI_PLUGIN_DISCOVERY_HOST_FOR_TANZU_CONTEXT=http://localhost:8080
36+
export TANZU_CLI_PLUGIN_DISCOVERY_HOST_FOR_TANZU_CONTEXT=http://localhost:9443
3537
```
3638

3739
To allow testing using different central repositories the endpoint serves some

hack/service/cli-service.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ split_clients "${msec}" $discovery {
99
}
1010

1111
server {
12-
listen 80;
12+
listen 443 ssl;
1313
server_name localhost;
1414
root /var/www/html;
15+
ssl_certificate /certs/localhost.crt;
16+
ssl_certificate_key /certs/localhost.key;
1517

1618
location /cli/v1/install {
1719
index install.txt;

0 commit comments

Comments
 (0)