This is an automated email from the ASF dual-hosted git repository.
chenjunxu 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 bffa9c88f fix: confusion when substituting ENV in config file (#11545)
bffa9c88f is described below
commit bffa9c88fc185f805870b2101f17d5384ad654d2
Author: Billy Zhou <[email protected]>
AuthorDate: Thu Sep 12 17:07:46 2024 +0800
fix: confusion when substituting ENV in config file (#11545)
---
apisix/cli/ops.lua | 2 +-
t/cli/cli_envsubst_confusion.t | 111 +++++++++++++++++++++++++++++++++++++++++
t/cli/test_main.sh | 12 ++---
t/cli/test_standalone.sh | 2 +-
4 files changed, 119 insertions(+), 8 deletions(-)
diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua
index 1ee068d6b..16547fce3 100644
--- a/apisix/cli/ops.lua
+++ b/apisix/cli/ops.lua
@@ -696,7 +696,7 @@ Please modify "admin_key" in conf/config.yaml .
for name, value in pairs(exported_vars) do
if value then
- table_insert(sys_conf["envs"], name .. "=" .. value)
+ table_insert(sys_conf["envs"], name)
end
end
end
diff --git a/t/cli/cli_envsubst_confusion.t b/t/cli/cli_envsubst_confusion.t
new file mode 100644
index 000000000..16d65e0ef
--- /dev/null
+++ b/t/cli/cli_envsubst_confusion.t
@@ -0,0 +1,111 @@
+#
+# 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.
+#
+
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+
+$ENV{SOME_STRING_VALUE_BUT_DIFFERENT} = 'astringvaluebutdifferent';
+$ENV{SOME_STRING_VALUE} = 'astringvalue';
+
+our $yaml_config = <<_EOC_;
+apisix:
+ node_listen: 1984
+deployment:
+ role: data_plane
+ role_data_plane:
+ config_provider: yaml
+_EOC_
+
+our $apisix_yaml = <<_EOC_;
+upstreams:
+ - id: 1
+ nodes:
+ - host: 127.0.0.1
+ port: 1980
+ weight: 1
+routes:
+ - uri: /hello
+ upstream_id: 1
+ plugins:
+ response-rewrite:
+ headers:
+ set:
+ X-Some-String-Value-But-Different: Different
\${{SOME_STRING_VALUE_BUT_DIFFERENT}}
+ X-Some-String-Value: \${{SOME_STRING_VALUE}}
+#END
+_EOC_
+
+our $response_headers_correct = <<_EOC_;
+X-Some-String-Value-But-Different: Different astringvaluebutdifferent
+X-Some-String-Value: astringvalue
+_EOC_
+
+our $response_headers_INCORRECT = <<_EOC_;
+X-Some-String-Value-But-Different: Different astringvalue
+X-Some-String-Value: astringvalue
+_EOC_
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if (!$block->request) {
+ $block->set_value("request", "GET /hello");
+ }
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: assignment style, the PREFIX 1st - incorrect
+--- main_config
+env SOME_STRING_VALUE=astringvalue;
+env SOME_STRING_VALUE_BUT_DIFFERENT=astringvaluebutdifferent;
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml eval: $::apisix_yaml
+--- response_headers eval: $::response_headers_INCORRECT
+
+
+
+=== TEST 2: assignment style, the DIFF 1st - correct
+--- main_config
+env SOME_STRING_VALUE_BUT_DIFFERENT=astringvaluebutdifferent;
+env SOME_STRING_VALUE=astringvalue;
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml eval: $::apisix_yaml
+--- response_headers eval: $::response_headers_correct
+
+
+
+=== TEST 3: declaration style, the PREFIX 1st - correct
+--- main_config
+env SOME_STRING_VALUE;
+env SOME_STRING_VALUE_BUT_DIFFERENT;
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml eval: $::apisix_yaml
+--- response_headers eval: $::response_headers_correct
+
+
+
+=== TEST 4: declaration style, the DIFF 1st - also correct
+--- main_config
+env SOME_STRING_VALUE_BUT_DIFFERENT;
+env SOME_STRING_VALUE;
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml eval: $::apisix_yaml
+--- response_headers eval: $::response_headers_correct
diff --git a/t/cli/test_main.sh b/t/cli/test_main.sh
index 963700017..62c128c94 100755
--- a/t/cli/test_main.sh
+++ b/t/cli/test_main.sh
@@ -348,7 +348,7 @@ deployment:
ETCD_HOST=127.0.0.1 ETCD_PORT=2379 make init
-if ! grep "env ETCD_HOST=127.0.0.1;" conf/nginx.conf > /dev/null; then
+if ! grep "env ETCD_HOST;" conf/nginx.conf > /dev/null; then
echo "failed: support environment variables in local_conf"
exit 1
fi
@@ -369,7 +369,7 @@ nginx_config:
ETCD_HOST=127.0.0.1 ETCD_PORT=2379 make init
-if grep "env ETCD_HOST=127.0.0.1;" conf/nginx.conf > /dev/null; then
+if grep "env ETCD_HOST=.*;" conf/nginx.conf > /dev/null; then
echo "failed: support environment variables in local_conf"
exit 1
fi
@@ -394,7 +394,7 @@ nginx_config:
ETCD_HOST=127.0.0.1 ETCD_PORT=2379 make init
-if grep "env ETCD_HOST=127.0.0.1;" conf/nginx.conf > /dev/null; then
+if grep "env ETCD_HOST;" conf/nginx.conf > /dev/null; then
echo "failed: support environment variables in local_conf"
exit 1
fi
@@ -414,7 +414,7 @@ tests:
make init
-if ! grep "env TEST_ENV=1.1.1.1;" conf/nginx.conf > /dev/null; then
+if ! grep "env TEST_ENV;" conf/nginx.conf > /dev/null; then
echo "failed: should use default value when environment not set"
exit 1
fi
@@ -426,7 +426,7 @@ tests:
make init
-if ! grep "env
TEST_ENV=very-long-domain-with-many-symbols.absolutely-non-exists-123ss.com:1234/path?param1=value1;"
conf/nginx.conf > /dev/null; then
+if ! grep "env TEST_ENV;" conf/nginx.conf > /dev/null; then
echo "failed: should use default value when environment not set"
exit 1
fi
@@ -438,7 +438,7 @@ tests:
TEST_ENV=127.0.0.1 make init
-if ! grep "env TEST_ENV=127.0.0.1;" conf/nginx.conf > /dev/null; then
+if ! grep "env TEST_ENV;" conf/nginx.conf > /dev/null; then
echo "failed: should use environment variable when environment is set"
exit 1
fi
diff --git a/t/cli/test_standalone.sh b/t/cli/test_standalone.sh
index 57b665294..d5844a2ce 100755
--- a/t/cli/test_standalone.sh
+++ b/t/cli/test_standalone.sh
@@ -54,7 +54,7 @@ routes:
# check for resolve variables
var_test_path=/test make init
-if ! grep "env var_test_path=/test;" conf/nginx.conf > /dev/null; then
+if ! grep "env var_test_path;" conf/nginx.conf > /dev/null; then
echo "failed: failed to resolve variables"
exit 1
fi