Skip to content

Commit

Permalink
feat(cli): parse IPv6 resolver address (#3187)
Browse files Browse the repository at this point in the history
Fix #3186.

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander authored Jan 5, 2021
1 parent 67df073 commit cc884f1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
60 changes: 60 additions & 0 deletions t/cli/cli.t
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit cc884f1

Please sign in to comment.