This is an automated email from the ASF dual-hosted git repository.
spacewander 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 cc884f1 feat(cli): parse IPv6 resolver address (#3187)
cc884f1 is described below
commit cc884f120790f618cd5ee361a699914e4fd5ae34
Author: 罗泽轩 <[email protected]>
AuthorDate: Mon Jan 4 21:01:17 2021 -0600
feat(cli): parse IPv6 resolver address (#3187)
Fix #3186.
Signed-off-by: spacewander <[email protected]>
---
apisix/cli/ops.lua | 4 +++-
t/cli/cli.t | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua
index 76d8442..a0852e5 100644
--- a/apisix/cli/ops.lua
+++ b/apisix/cli/ops.lua
@@ -103,7 +103,7 @@ local function local_dns_resolver(file_path)
local dns_addrs = {}
for line in file:lines() do
- local addr, n = line:gsub("^nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$",
"%1")
+ local addr, n = line:gsub("^nameserver%s+([^%s]+)%s*$", "%1")
if n == 1 then
table_insert(dns_addrs, addr)
end
@@ -112,6 +112,8 @@ local function local_dns_resolver(file_path)
file:close()
return dns_addrs
end
+-- exported for test
+_M.local_dns_resolver = local_dns_resolver
local function version()
diff --git a/t/cli/cli.t b/t/cli/cli.t
new file mode 100644
index 0000000..da86341
--- /dev/null
+++ b/t/cli/cli.t
@@ -0,0 +1,60 @@
+#
+# 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.
+#
+# unit test for cli module
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if (!$block->request) {
+ $block->set_value("request", "GET /t");
+ }
+
+ if (!$block->no_error_log) {
+ $block->set_value("no_error_log", "[error]\n[alert]");
+ }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: local_dns_resolver
+--- config
+ location /t {
+ content_by_lua_block {
+ local local_dns_resolver =
require("apisix.cli.ops").local_dns_resolver
+ local json_encode = require("toolkit.json").encode
+
ngx.say(json_encode(local_dns_resolver("$TEST_NGINX_HTML_DIR/resolv.conf")))
+ }
+ }
+--- user_files
+>>> resolv.conf
+# This file was automatically generated.
+nameserver 172.27.0.1
+
+nameserver fe80::215:5dff:fec5:8e1d
+--- response_body
+["172.27.0.1","fe80::215:5dff:fec5:8e1d"]