|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# |
| 4 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | +# contributor license agreements. See the NOTICE file distributed with |
| 6 | +# this work for additional information regarding copyright ownership. |
| 7 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 8 | +# (the "License"); you may not use this file except in compliance with |
| 9 | +# the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | + |
| 20 | +. ./t/cli/common.sh |
| 21 | + |
| 22 | +# check admin ui enabled |
| 23 | + |
| 24 | +git checkout conf/config.yaml |
| 25 | + |
| 26 | +make init |
| 27 | + |
| 28 | +grep "location ^~ /ui/" conf/nginx.conf > /dev/null |
| 29 | +if [ ! $? -eq 0 ]; then |
| 30 | + echo "failed: failed to enable embedded admin ui" |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +make run |
| 35 | + |
| 36 | +## check /ui redirects to /ui/ |
| 37 | + |
| 38 | +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/ui) |
| 39 | +if [ ! $code -eq 301 ]; then |
| 40 | + echo "failed: failed to redirect /ui to /ui/" |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | + |
| 44 | +## check /ui/ accessible |
| 45 | + |
| 46 | +mkdir -p ui/assets |
| 47 | +echo "test_html" > ui/index.html |
| 48 | +echo "test_js" > ui/assets/test.js |
| 49 | +echo "test_css" > ui/assets/test.css |
| 50 | + |
| 51 | +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/ui/) |
| 52 | +if [ ! $code -eq 200 ]; then |
| 53 | + echo "failed: /ui/ not accessible" |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +## check /ui/index.html accessible |
| 58 | + |
| 59 | +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/ui/index.html) |
| 60 | +if [ ! $code -eq 200 ]; then |
| 61 | + echo "failed: /ui/index.html not accessible" |
| 62 | + exit 1 |
| 63 | +fi |
| 64 | + |
| 65 | +## check /ui/assets/test.js accessible |
| 66 | + |
| 67 | +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/ui/assets/test.js) |
| 68 | +if [ ! $code -eq 200 ]; then |
| 69 | + echo "failed: /ui/assets/test.js not accessible" |
| 70 | + exit 1 |
| 71 | +fi |
| 72 | + |
| 73 | +## check /ui/assets/test.css accessible |
| 74 | + |
| 75 | +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/ui/assets/test.css) |
| 76 | +if [ ! $code -eq 200 ]; then |
| 77 | + echo "failed: /ui/assets/test.css not accessible" |
| 78 | + exit 1 |
| 79 | +fi |
| 80 | + |
| 81 | +## check /ui/ single-page-application fallback |
| 82 | + |
| 83 | +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/ui/not_exist) |
| 84 | +if [ ! $code -eq 200 ]; then |
| 85 | + echo "failed: /ui/not_exist not accessible" |
| 86 | + exit 1 |
| 87 | +fi |
| 88 | + |
| 89 | +make stop |
| 90 | + |
| 91 | +# test ip restriction |
| 92 | + |
| 93 | +git checkout conf/config.yaml |
| 94 | + |
| 95 | +echo " |
| 96 | +deployment: |
| 97 | + admin: |
| 98 | + enable_admin_ui: true |
| 99 | + allow_admin: |
| 100 | + - 1.1.1.1/32 |
| 101 | +" > conf/config.yaml |
| 102 | + |
| 103 | +make run |
| 104 | + |
| 105 | +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/ui/) |
| 106 | +if [ ! $code -eq 403 ]; then |
| 107 | + echo "failed: ip restriction not working, expected 403, got $code" |
| 108 | + exit 1 |
| 109 | +fi |
| 110 | + |
| 111 | +make stop |
| 112 | + |
| 113 | +# test admin ui disabled |
| 114 | + |
| 115 | +git checkout conf/config.yaml |
| 116 | + |
| 117 | +echo " |
| 118 | +deployment: |
| 119 | + admin: |
| 120 | + enable_admin_ui: false |
| 121 | +" > conf/config.yaml |
| 122 | + |
| 123 | +make init |
| 124 | + |
| 125 | +#### When grep cannot find the value, it uses 1 as the exit code. |
| 126 | +#### Due to the use of set -e, any non-zero exit will terminate the |
| 127 | +#### script, so grep is written inside the if statement here. |
| 128 | +if grep "location ^~ /ui/" conf/nginx.conf > /dev/null; then |
| 129 | + echo "failed: failed to disable embedded admin ui" |
| 130 | + exit 1 |
| 131 | +fi |
| 132 | + |
| 133 | +# test admin UI explicitly enabled |
| 134 | + |
| 135 | +git checkout conf/config.yaml |
| 136 | + |
| 137 | +echo " |
| 138 | +deployment: |
| 139 | + admin: |
| 140 | + enable_admin_ui: true |
| 141 | +" > conf/config.yaml |
| 142 | + |
| 143 | +make init |
| 144 | + |
| 145 | +if ! grep "location ^~ /ui/" conf/nginx.conf > /dev/null; then |
| 146 | + echo "failed: failed to explicitly enable embedded admin ui" |
| 147 | + exit 1 |
| 148 | +fi |
0 commit comments