Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: confusion when substituting ENV in config file #11545

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
111 changes: 111 additions & 0 deletions t/cli/cli_envsubst_confusion.t
Original file line number Diff line number Diff line change
@@ -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
Loading