This is an automated email from the ASF dual-hosted git repository.
shuyangw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new eeb3d55 test: break down cli test_main.sh (#3887)
eeb3d55 is described below
commit eeb3d55a7e48627848ae9bad8f0223d85e73ea96
Author: 罗泽轩 <[email protected]>
AuthorDate: Tue Mar 23 21:57:14 2021 +0800
test: break down cli test_main.sh (#3887)
Signed-off-by: spacewander <[email protected]>
---
t/cli/test_access_log.sh | 185 ++++++++++++++++++++
t/cli/test_admin.sh | 184 ++++++++++++++++++++
t/cli/test_etcd.sh | 134 ++++++++++++++
t/cli/test_main.sh | 443 -----------------------------------------------
4 files changed, 503 insertions(+), 443 deletions(-)
diff --git a/t/cli/test_access_log.sh b/t/cli/test_access_log.sh
new file mode 100755
index 0000000..d1fc400
--- /dev/null
+++ b/t/cli/test_access_log.sh
@@ -0,0 +1,185 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+# log format
+
+git checkout conf/config.yaml
+
+echo '
+nginx_config:
+ http:
+ access_log_format: "$remote_addr - $remote_user [$time_local] $http_host
test_access_log_format"
+' > conf/config.yaml
+
+make init
+
+grep "test_access_log_format" conf/nginx.conf > /dev/null
+if [ ! $? -eq 0 ]; then
+ echo "failed: access_log_format in nginx.conf doesn't change"
+ exit 1
+fi
+
+echo "passed: access_log_format in nginx.conf is ok"
+
+# check enable access log
+
+echo '
+nginx_config:
+ http:
+ enable_access_log: true
+ access_log_format: "$remote_addr - $remote_user [$time_local] $http_host
test_enable_access_log_true"
+' > conf/config.yaml
+
+make init
+
+count_test_access_log=`grep -c "test_enable_access_log_true" conf/nginx.conf
|| true`
+if [ $count_test_access_log -eq 0 ]; then
+ echo "failed: nginx.conf file doesn't find access_log_format when enable
access log"
+ exit 1
+fi
+
+count_access_log_off=`grep -c "access_log off;" conf/nginx.conf || true`
+if [ $count_access_log_off -eq 3 ]; then
+ echo "failed: nginx.conf file find access_log off; when enable access log"
+ exit 1
+fi
+
+make run
+sleep 0.1
+curl http://127.0.0.1:9080/hi
+sleep 4
+tail -n 1 logs/access.log > output.log
+
+count_grep=`grep -c "test_enable_access_log_true" output.log || true`
+if [ $count_grep -eq 0 ]; then
+ echo "failed: not found test_enable_access_log in access.log "
+ exit 1
+fi
+
+make stop
+
+echo '
+nginx_config:
+ http:
+ enable_access_log: false
+ access_log_format: "$remote_addr - $remote_user [$time_local] $http_host
test_enable_access_log_false"
+' > conf/config.yaml
+
+make init
+
+count_test_access_log=`grep -c "test_enable_access_log_false" conf/nginx.conf
|| true`
+if [ $count_test_access_log -eq 1 ]; then
+ echo "failed: nginx.conf file find access_log_format when disable access
log"
+ exit 1
+fi
+
+count_access_log_off=`grep -c "access_log off;" conf/nginx.conf || true`
+if [ $count_access_log_off -ne 3 ]; then
+ echo "failed: nginx.conf file doesn't find access_log off; when disable
access log"
+ exit 1
+fi
+
+make run
+sleep 0.1
+curl http://127.0.0.1:9080/hi
+sleep 4
+tail -n 1 logs/access.log > output.log
+
+count_grep=`grep -c "test_enable_access_log_false" output.log || true`
+if [ $count_grep -eq 1 ]; then
+ echo "failed: found test_enable_access_log in access.log "
+ exit 1
+fi
+
+make stop
+
+echo "passed: enable_access_log is ok"
+
+# access log with JSON format
+
+echo '
+nginx_config:
+ http:
+ access_log_format: |-
+ {"@timestamp": "$time_iso8601", "client_ip": "$remote_addr", "status":
"$status"}
+ access_log_format_escape: json
+' > conf/config.yaml
+
+make init
+make run
+sleep 0.1
+curl http://127.0.0.1:9080/hello2
+sleep 4
+tail -n 1 logs/access.log > output.log
+
+if [ `grep -c '"client_ip": "127.0.0.1"' output.log` -eq '0' ]; then
+ echo "failed: invalid JSON log in access log"
+ exit 1
+fi
+
+if [ `grep -c 'main escape=json' conf/nginx.conf` -eq '0' ]; then
+ echo "failed: not found \"escape=json\" in conf/nginx.conf"
+ exit 1
+fi
+
+make stop
+
+echo "passed: access log with JSON format"
+
+# check uninitialized variable in access log when access admin
+git checkout conf/config.yaml
+
+rm logs/error.log
+make init
+make run
+
+code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1')
+make stop
+
+if [ ! $code -eq 200 ]; then
+ echo "failed: failed to access admin"
+ exit 1
+fi
+
+if grep -E 'using uninitialized ".+" variable while logging request'
logs/error.log; then
+ echo "failed: uninitialized variable found during writing access log"
+ exit 1
+fi
+
+echo "pass: uninitialized variable not found during writing access log"
+
+# don't log uninitialized access log variable when the HTTP request is
malformed
+
+git checkout conf/config.yaml
+
+rm logs/error.log
+./bin/apisix start
+sleep 1 # wait for apisix starts
+
+curl -v -k -i -m 20 -o /dev/null -s https://127.0.0.1:9080 || true
+if grep -E 'using uninitialized ".+" variable while logging request'
logs/error.log; then
+ echo "failed: log uninitialized access log variable when the HTTP request
is malformed"
+ exit 1
+fi
+
+make stop
+
+echo "don't log uninitialized access log variable when the HTTP request is
malformed"
diff --git a/t/cli/test_admin.sh b/t/cli/test_admin.sh
new file mode 100755
index 0000000..9d7dd4a
--- /dev/null
+++ b/t/cli/test_admin.sh
@@ -0,0 +1,184 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+# check admin https enabled
+
+git checkout conf/config.yaml
+
+echo "
+apisix:
+ admin_api_mtls:
+ admin_ssl_cert: '../t/certs/apisix_admin_ssl.crt'
+ admin_ssl_cert_key: '../t/certs/apisix_admin_ssl.key'
+ port_admin: 9180
+ https_admin: true
+" > conf/config.yaml
+
+make init
+
+grep "listen 9180 ssl" conf/nginx.conf > /dev/null
+if [ ! $? -eq 0 ]; then
+ echo "failed: failed to enabled https for admin"
+ exit 1
+fi
+
+make run
+
+code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
https://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1')
+if [ ! $code -eq 200 ]; then
+ echo "failed: failed to enabled https for admin"
+ exit 1
+fi
+
+make stop
+
+echo "passed: admin https enabled"
+
+# rollback to the default
+
+git checkout conf/config.yaml
+
+make init
+
+set +ex
+
+grep "listen 9080 ssl" conf/nginx.conf > /dev/null
+if [ ! $? -eq 1 ]; then
+ echo "failed: failed to rollback to the default admin config"
+ exit 1
+fi
+
+set -ex
+
+echo "passed: rollback to the default admin config"
+
+# set allow_admin in conf/config.yaml
+
+echo "
+apisix:
+ allow_admin:
+ - 127.0.0.9
+" > conf/config.yaml
+
+make init
+
+count=`grep -c "allow 127.0.0.9" conf/nginx.conf`
+if [ $count -eq 0 ]; then
+ echo "failed: not found 'allow 127.0.0.9;' in conf/nginx.conf"
+ exit 1
+fi
+
+echo "
+apisix:
+ allow_admin: ~
+" > conf/config.yaml
+
+make init
+
+count=`grep -c "allow all;" conf/nginx.conf`
+if [ $count -eq 0 ]; then
+ echo "failed: not found 'allow all;' in conf/nginx.conf"
+ exit 1
+fi
+
+echo "passed: empty allow_admin in conf/config.yaml"
+
+# missing admin key, allow any IP to access admin api
+
+git checkout conf/config.yaml
+
+echo '
+apisix:
+ allow_admin: ~
+ admin_key: ~
+' > conf/config.yaml
+
+make init > output.log 2>&1 | true
+
+grep -E "ERROR: missing valid Admin API token." output.log > /dev/null
+if [ ! $? -eq 0 ]; then
+ echo "failed: should show 'ERROR: missing valid Admin API token.'"
+ exit 1
+fi
+
+echo "pass: missing admin key and show ERROR message"
+
+# admin api, allow any IP but use default key
+
+echo '
+apisix:
+ allow_admin: ~
+ admin_key:
+ -
+ name: "admin"
+ key: edd1c9f034335f136f87ad84b625c8f1
+ role: admin
+' > conf/config.yaml
+
+make init > output.log 2>&1 | true
+
+grep -E "WARNING: using fixed Admin API token has security risk." output.log >
/dev/null
+if [ ! $? -eq 0 ]; then
+ echo "failed: need to show `WARNING: using fixed Admin API token has
security risk`"
+ exit 1
+fi
+
+echo "pass: show WARNING message if the user used default token and allow any
IP to access"
+
+# port_admin set
+echo '
+apisix:
+ port_admin: 9180
+' > conf/config.yaml
+
+rm logs/error.log
+make init
+make run
+
+code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1')
+make stop
+
+if [ ! $code -eq 200 ]; then
+ echo "failed: failed to access admin"
+ exit 1
+fi
+
+if grep -E 'using uninitialized ".+" variable while logging request'
logs/error.log; then
+ echo "failed: uninitialized variable found during writing access log"
+ exit 1
+fi
+
+echo "pass: uninitialized variable not found during writing access log
(port_admin set)"
+
+# Admin API can only be used with etcd config_center
+echo '
+apisix:
+ enable_admin: true
+ config_center: yaml
+' > conf/config.yaml
+
+out=$(make init 2>&1 || true)
+if ! echo "$out" | grep "Admin API can only be used with etcd config_center";
then
+ echo "failed: Admin API can only be used with etcd config_center"
+ exit 1
+fi
+
+echo "passed: Admin API can only be used with etcd config_center"
diff --git a/t/cli/test_etcd.sh b/t/cli/test_etcd.sh
new file mode 100755
index 0000000..2e20a39
--- /dev/null
+++ b/t/cli/test_etcd.sh
@@ -0,0 +1,134 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+# check etcd while enable auth
+git checkout conf/config.yaml
+
+export ETCDCTL_API=3
+etcdctl version
+etcdctl --endpoints=127.0.0.1:2379 user add "root:apache-api6"
+etcdctl --endpoints=127.0.0.1:2379 role add root
+etcdctl --endpoints=127.0.0.1:2379 user grant-role root root
+etcdctl --endpoints=127.0.0.1:2379 user get root
+etcdctl --endpoints=127.0.0.1:2379 auth enable
+etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 del /apisix --prefix
+
+echo '
+etcd:
+ host:
+ - "http://127.0.0.1:2379"
+ prefix: "/apisix"
+ timeout: 30
+ user: root
+ password: apache-api6
+' > conf/config.yaml
+
+make init
+cmd_res=`etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 get
/apisix --prefix`
+etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 auth disable
+etcdctl --endpoints=127.0.0.1:2379 role delete root
+etcdctl --endpoints=127.0.0.1:2379 user delete root
+
+init_kv=(
+"/apisix/consumers/ init_dir"
+"/apisix/global_rules/ init_dir"
+"/apisix/plugin_metadata/ init_dir"
+"/apisix/plugins/ init_dir"
+"/apisix/proto/ init_dir"
+"/apisix/routes/ init_dir"
+"/apisix/services/ init_dir"
+"/apisix/ssl/ init_dir"
+"/apisix/stream_routes/ init_dir"
+"/apisix/upstreams/ init_dir"
+)
+
+IFS=$'\n'
+for kv in ${init_kv[@]}
+do
+count=`echo $cmd_res | grep -c ${kv} || true`
+if [ $count -ne 1 ]; then
+ echo "failed: failed to match ${kv}"
+ exit 1
+fi
+done
+
+echo "passed: etcd auth enabled and init kv has been set up correctly"
+
+out=$(make init 2>&1 || true)
+if ! echo "$out" | grep 'authentication is not enabled'; then
+ echo "failed: properly handle the error when connecting to etcd without
auth"
+ exit 1
+fi
+
+echo "passed: properly handle the error when connecting to etcd without auth"
+
+# Check etcd connect refused
+git checkout conf/config.yaml
+
+echo '
+etcd:
+ host:
+ - "http://127.0.0.1:2389"
+ prefix: "/apisix"
+' > conf/config.yaml
+
+out=$(make init 2>&1 || true)
+if ! echo "$out" | grep "connection refused"; then
+ echo "failed: apisix should echo \"connection refused\""
+ exit 1
+fi
+
+echo "passed: Show connection refused info successfully"
+
+# Check etcd auth error
+git checkout conf/config.yaml
+
+export ETCDCTL_API=3
+etcdctl version
+etcdctl --endpoints=127.0.0.1:2379 user add "root:apache-api6"
+etcdctl --endpoints=127.0.0.1:2379 role add root
+etcdctl --endpoints=127.0.0.1:2379 user grant-role root root
+etcdctl --endpoints=127.0.0.1:2379 user get root
+etcdctl --endpoints=127.0.0.1:2379 auth enable
+etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 del /apisix --prefix
+
+echo '
+etcd:
+ host:
+ - "http://127.0.0.1:2379"
+ prefix: "/apisix"
+ timeout: 30
+ user: root
+ password: apache-api7
+' > conf/config.yaml
+
+out=$(make init 2>&1 || true)
+if ! echo "$out" | grep "invalid user ID or password"; then
+ echo "failed: should echo \"invalid user ID or password\""
+ exit 1
+fi
+
+echo "passed: show password error successfully"
+
+# clean etcd auth
+etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 auth disable
+etcdctl --endpoints=127.0.0.1:2379 role delete root
+etcdctl --endpoints=127.0.0.1:2379 user delete root
diff --git a/t/cli/test_main.sh b/t/cli/test_main.sh
index 3d611f3..ca287bb 100755
--- a/t/cli/test_main.sh
+++ b/t/cli/test_main.sh
@@ -367,57 +367,6 @@ fi
echo "passed: nginx.conf file contains worker_cpu_affinity configuration"
-# check admin https enabled
-
-git checkout conf/config.yaml
-
-echo "
-apisix:
- admin_api_mtls:
- admin_ssl_cert: '../t/certs/apisix_admin_ssl.crt'
- admin_ssl_cert_key: '../t/certs/apisix_admin_ssl.key'
- port_admin: 9180
- https_admin: true
-" > conf/config.yaml
-
-make init
-
-grep "listen 9180 ssl" conf/nginx.conf > /dev/null
-if [ ! $? -eq 0 ]; then
- echo "failed: failed to enabled https for admin"
- exit 1
-fi
-
-make run
-
-code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
https://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1')
-if [ ! $code -eq 200 ]; then
- echo "failed: failed to enabled https for admin"
- exit 1
-fi
-
-make stop
-
-echo "passed: admin https enabled"
-
-# rollback to the default
-
-git checkout conf/config.yaml
-
-make init
-
-set +ex
-
-grep "listen 9080 ssl" conf/nginx.conf > /dev/null
-if [ ! $? -eq 1 ]; then
- echo "failed: failed to rollback to the default admin config"
- exit 1
-fi
-
-set -ex
-
-echo "passed: rollback to the default admin config"
-
# check the 'worker_shutdown_timeout' in 'nginx.conf' .
make init
@@ -430,37 +379,6 @@ fi
echo "passed: worker_shutdown_timeout in nginx.conf is ok"
-# set allow_admin in conf/config.yaml
-
-echo "
-apisix:
- allow_admin:
- - 127.0.0.9
-" > conf/config.yaml
-
-make init
-
-count=`grep -c "allow 127.0.0.9" conf/nginx.conf`
-if [ $count -eq 0 ]; then
- echo "failed: not found 'allow 127.0.0.9;' in conf/nginx.conf"
- exit 1
-fi
-
-echo "
-apisix:
- allow_admin: ~
-" > conf/config.yaml
-
-make init
-
-count=`grep -c "allow all;" conf/nginx.conf`
-if [ $count -eq 0 ]; then
- echo "failed: not found 'allow all;' in conf/nginx.conf"
- exit 1
-fi
-
-echo "passed: empty allow_admin in conf/config.yaml"
-
# check the 'client_max_body_size' in 'nginx.conf' .
git checkout conf/config.yaml
@@ -543,142 +461,6 @@ fi
rm conf/config_original.yaml conf/customized_config.yaml
echo "passed: customized config.yaml copied and reverted succeeded"
-# log format
-
-git checkout conf/config.yaml
-
-echo '
-nginx_config:
- http:
- access_log_format: "$remote_addr - $remote_user [$time_local] $http_host
test_access_log_format"
-' > conf/config.yaml
-
-make init
-
-grep "test_access_log_format" conf/nginx.conf > /dev/null
-if [ ! $? -eq 0 ]; then
- echo "failed: access_log_format in nginx.conf doesn't change"
- exit 1
-fi
-
-echo "passed: access_log_format in nginx.conf is ok"
-
-# check enable access log
-
-echo '
-nginx_config:
- http:
- enable_access_log: true
- access_log_format: "$remote_addr - $remote_user [$time_local] $http_host
test_enable_access_log_true"
-' > conf/config.yaml
-
-make init
-
-count_test_access_log=`grep -c "test_enable_access_log_true" conf/nginx.conf
|| true`
-if [ $count_test_access_log -eq 0 ]; then
- echo "failed: nginx.conf file doesn't find access_log_format when enable
access log"
- exit 1
-fi
-
-count_access_log_off=`grep -c "access_log off;" conf/nginx.conf || true`
-if [ $count_access_log_off -eq 3 ]; then
- echo "failed: nginx.conf file find access_log off; when enable access log"
- exit 1
-fi
-
-make run
-sleep 0.1
-curl http://127.0.0.1:9080/hi
-sleep 4
-tail -n 1 logs/access.log > output.log
-
-count_grep=`grep -c "test_enable_access_log_true" output.log || true`
-if [ $count_grep -eq 0 ]; then
- echo "failed: not found test_enable_access_log in access.log "
- exit 1
-fi
-
-make stop
-
-echo '
-nginx_config:
- http:
- enable_access_log: false
- access_log_format: "$remote_addr - $remote_user [$time_local] $http_host
test_enable_access_log_false"
-' > conf/config.yaml
-
-make init
-
-count_test_access_log=`grep -c "test_enable_access_log_false" conf/nginx.conf
|| true`
-if [ $count_test_access_log -eq 1 ]; then
- echo "failed: nginx.conf file find access_log_format when disable access
log"
- exit 1
-fi
-
-count_access_log_off=`grep -c "access_log off;" conf/nginx.conf || true`
-if [ $count_access_log_off -ne 3 ]; then
- echo "failed: nginx.conf file doesn't find access_log off; when disable
access log"
- exit 1
-fi
-
-make run
-sleep 0.1
-curl http://127.0.0.1:9080/hi
-sleep 4
-tail -n 1 logs/access.log > output.log
-
-count_grep=`grep -c "test_enable_access_log_false" output.log || true`
-if [ $count_grep -eq 1 ]; then
- echo "failed: found test_enable_access_log in access.log "
- exit 1
-fi
-
-make stop
-
-echo "passed: enable_access_log is ok"
-
-# missing admin key, allow any IP to access admin api
-
-git checkout conf/config.yaml
-
-echo '
-apisix:
- allow_admin: ~
- admin_key: ~
-' > conf/config.yaml
-
-make init > output.log 2>&1 | true
-
-grep -E "ERROR: missing valid Admin API token." output.log > /dev/null
-if [ ! $? -eq 0 ]; then
- echo "failed: should show 'ERROR: missing valid Admin API token.'"
- exit 1
-fi
-
-echo "pass: missing admin key and show ERROR message"
-
-# admin api, allow any IP but use default key
-
-echo '
-apisix:
- allow_admin: ~
- admin_key:
- -
- name: "admin"
- key: edd1c9f034335f136f87ad84b625c8f1
- role: admin
-' > conf/config.yaml
-
-make init > output.log 2>&1 | true
-
-grep -E "WARNING: using fixed Admin API token has security risk." output.log >
/dev/null
-if [ ! $? -eq 0 ]; then
- echo "failed: need to show `WARNING: using fixed Admin API token has
security risk`"
- exit 1
-fi
-
-echo "pass: show WARNING message if the user used default token and allow any
IP to access"
-
# allow to merge configuration without middle layer
git checkout conf/config.yaml
@@ -828,231 +610,6 @@ fi
echo "passed: disable ssl_session_tickets by default"
-# access log with JSON format
-
-echo '
-nginx_config:
- http:
- access_log_format: |-
- {"@timestamp": "$time_iso8601", "client_ip": "$remote_addr", "status":
"$status"}
- access_log_format_escape: json
-' > conf/config.yaml
-
-make init
-make run
-sleep 0.1
-curl http://127.0.0.1:9080/hello2
-sleep 4
-tail -n 1 logs/access.log > output.log
-
-if [ `grep -c '"client_ip": "127.0.0.1"' output.log` -eq '0' ]; then
- echo "failed: invalid JSON log in access log"
- exit 1
-fi
-
-if [ `grep -c 'main escape=json' conf/nginx.conf` -eq '0' ]; then
- echo "failed: not found \"escape=json\" in conf/nginx.conf"
- exit 1
-fi
-
-make stop
-
-echo "passed: access log with JSON format"
-
-# check uninitialized variable in access log when access admin
-git checkout conf/config.yaml
-
-rm logs/error.log
-make init
-make run
-
-code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1')
-make stop
-
-if [ ! $code -eq 200 ]; then
- echo "failed: failed to access admin"
- exit 1
-fi
-
-if grep -E 'using uninitialized ".+" variable while logging request'
logs/error.log; then
- echo "failed: uninitialized variable found during writing access log"
- exit 1
-fi
-
-echo "pass: uninitialized variable not found during writing access log"
-
-# don't log uninitialized access log variable when the HTTP request is
malformed
-
-git checkout conf/config.yaml
-
-rm logs/error.log
-./bin/apisix start
-sleep 1 # wait for apisix starts
-
-curl -v -k -i -m 20 -o /dev/null -s https://127.0.0.1:9080 || true
-if grep -E 'using uninitialized ".+" variable while logging request'
logs/error.log; then
- echo "failed: log uninitialized access log variable when the HTTP request
is malformed"
- exit 1
-fi
-
-make stop
-
-echo "don't log uninitialized access log variable when the HTTP request is
malformed"
-
-# port_admin set
-echo '
-apisix:
- port_admin: 9180
-' > conf/config.yaml
-
-rm logs/error.log
-make init
-make run
-
-code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1')
-make stop
-
-if [ ! $code -eq 200 ]; then
- echo "failed: failed to access admin"
- exit 1
-fi
-
-if grep -E 'using uninitialized ".+" variable while logging request'
logs/error.log; then
- echo "failed: uninitialized variable found during writing access log"
- exit 1
-fi
-
-echo "pass: uninitialized variable not found during writing access log
(port_admin set)"
-
-# check etcd while enable auth
-git checkout conf/config.yaml
-
-export ETCDCTL_API=3
-etcdctl version
-etcdctl --endpoints=127.0.0.1:2379 user add "root:apache-api6"
-etcdctl --endpoints=127.0.0.1:2379 role add root
-etcdctl --endpoints=127.0.0.1:2379 user grant-role root root
-etcdctl --endpoints=127.0.0.1:2379 user get root
-etcdctl --endpoints=127.0.0.1:2379 auth enable
-etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 del /apisix --prefix
-
-echo '
-etcd:
- host:
- - "http://127.0.0.1:2379"
- prefix: "/apisix"
- timeout: 30
- user: root
- password: apache-api6
-' > conf/config.yaml
-
-make init
-cmd_res=`etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 get
/apisix --prefix`
-etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 auth disable
-etcdctl --endpoints=127.0.0.1:2379 role delete root
-etcdctl --endpoints=127.0.0.1:2379 user delete root
-
-init_kv=(
-"/apisix/consumers/ init_dir"
-"/apisix/global_rules/ init_dir"
-"/apisix/plugin_metadata/ init_dir"
-"/apisix/plugins/ init_dir"
-"/apisix/proto/ init_dir"
-"/apisix/routes/ init_dir"
-"/apisix/services/ init_dir"
-"/apisix/ssl/ init_dir"
-"/apisix/stream_routes/ init_dir"
-"/apisix/upstreams/ init_dir"
-)
-
-IFS=$'\n'
-for kv in ${init_kv[@]}
-do
-count=`echo $cmd_res | grep -c ${kv} || true`
-if [ $count -ne 1 ]; then
- echo "failed: failed to match ${kv}"
- exit 1
-fi
-done
-
-echo "passed: etcd auth enabled and init kv has been set up correctly"
-
-out=$(make init 2>&1 || true)
-if ! echo "$out" | grep 'authentication is not enabled'; then
- echo "failed: properly handle the error when connecting to etcd without
auth"
- exit 1
-fi
-
-echo "passed: properly handle the error when connecting to etcd without auth"
-
-# Admin API can only be used with etcd config_center
-echo '
-apisix:
- enable_admin: true
- config_center: yaml
-' > conf/config.yaml
-
-out=$(make init 2>&1 || true)
-if ! echo "$out" | grep "Admin API can only be used with etcd config_center";
then
- echo "failed: Admin API can only be used with etcd config_center"
- exit 1
-fi
-
-echo "passed: Admin API can only be used with etcd config_center"
-
-# Check etcd connect refused
-git checkout conf/config.yaml
-
-echo '
-etcd:
- host:
- - "http://127.0.0.1:2389"
- prefix: "/apisix"
-' > conf/config.yaml
-
-out=$(make init 2>&1 || true)
-if ! echo "$out" | grep "connection refused"; then
- echo "failed: apisix should echo \"connection refused\""
- exit 1
-fi
-
-echo "passed: Show connection refused info successfully"
-
-# Check etcd auth error
-git checkout conf/config.yaml
-
-export ETCDCTL_API=3
-etcdctl version
-etcdctl --endpoints=127.0.0.1:2379 user add "root:apache-api6"
-etcdctl --endpoints=127.0.0.1:2379 role add root
-etcdctl --endpoints=127.0.0.1:2379 user grant-role root root
-etcdctl --endpoints=127.0.0.1:2379 user get root
-etcdctl --endpoints=127.0.0.1:2379 auth enable
-etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 del /apisix --prefix
-
-echo '
-etcd:
- host:
- - "http://127.0.0.1:2379"
- prefix: "/apisix"
- timeout: 30
- user: root
- password: apache-api7
-' > conf/config.yaml
-
-out=$(make init 2>&1 || true)
-if ! echo "$out" | grep "invalid user ID or password"; then
- echo "failed: should echo \"invalid user ID or password\""
- exit 1
-fi
-
-echo "passed: show password error successfully"
-
-# clean etcd auth
-etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 auth disable
-etcdctl --endpoints=127.0.0.1:2379 role delete root
-etcdctl --endpoints=127.0.0.1:2379 user delete root
-
# support 3rd-party plugin
echo '
apisix: