From 081b21fbba902705bb7a8647252490fe5ab5ca38 Mon Sep 17 00:00:00 2001 From: soulbird Date: Mon, 25 Apr 2022 14:41:55 +0800 Subject: [PATCH] fix: upstream nodes cant't include ipv6 addr (#6908) --- apisix/schema_def.lua | 2 +- t/admin/upstream-array-nodes.t | 35 ++++++++++++++++++++++++++++++++++ t/plugin/referer-restriction.t | 1 - 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index 3f72111d87da..96cc11eaa715 100644 --- a/apisix/schema_def.lua +++ b/apisix/schema_def.lua @@ -37,7 +37,7 @@ local id_schema = { } } -local host_def_pat = "^\\*?[0-9a-zA-Z-._]+$" +local host_def_pat = "^\\*?[0-9a-zA-Z-._\\[\\]:]+$" local host_def = { type = "string", pattern = host_def_pat, diff --git a/t/admin/upstream-array-nodes.t b/t/admin/upstream-array-nodes.t index d6cfaf0125eb..16855526c1c7 100644 --- a/t/admin/upstream-array-nodes.t +++ b/t/admin/upstream-array-nodes.t @@ -450,3 +450,38 @@ GET /t {"error_msg":"invalid configuration: property \"nodes\" validation failed: object matches none of the required"} --- no_error_log [error] + + + +=== TEST 14: nodes host include ipv6 addr +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "upstream": { + "nodes": [ + { + "host":"[::1]", + "port":8082, + "weight":1 + } + ], + "type": "roundrobin" + }, + "uri": "/index.html" + }]] + ) + + ngx.status = code + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] diff --git a/t/plugin/referer-restriction.t b/t/plugin/referer-restriction.t index 80914cf754c6..fa4fe5fb4a32 100644 --- a/t/plugin/referer-restriction.t +++ b/t/plugin/referer-restriction.t @@ -173,7 +173,6 @@ hello world local cases = { "x.*", "~y.xn", - "::1", } for _, c in ipairs(cases) do local ok, err = plugin.check_schema({