@@ -250,3 +250,69 @@ passed
250250 }
251251--- response_body
252252passed
253+
254+
255+
256+ === TEST 5: validate IPv6 address format in upstream nodes
257+ --- config
258+ location /t {
259+ content_by_lua_block {
260+ local schema_def = require("apisix.schema_def")
261+ local core = require("apisix.core")
262+ local upstream = require("apisix.upstream")
263+ local t = require("lib.test_admin")
264+ -- Test valid IPv6 addresses (enclosed in brackets)
265+ local valid_cases = {
266+ {
267+ nodes = {
268+ {host = "[::1]", port = 80, weight = 1},
269+ },
270+ type = "roundrobin"
271+ },
272+ {
273+ nodes = {
274+ {host = "[2001:db8::1]", port = 80, weight = 1},
275+ },
276+ type = "roundrobin"
277+ }
278+ }
279+
280+ for _, ups in ipairs(valid_cases) do
281+ local ok, err = upstream.check_schema(ups)
282+ if not ok then
283+ ngx.log(ngx.ERR, "Expected valid case failed: ", err)
284+ end
285+ assert(ok, "Valid IPv6 case should pass: " .. (err or ""))
286+ end
287+
288+ -- Test invalid IPv6 addresses (not enclosed in brackets)
289+ local invalid_cases = {
290+ {
291+ nodes = {
292+ {host = "::1", port = 80, weight = 1},
293+ },
294+ type = "roundrobin"
295+ },
296+ {
297+ nodes = {
298+ {host = "2001:db8::1", port = 80, weight = 1},
299+ },
300+ type = "roundrobin"
301+ }
302+ }
303+
304+ for i, ups in ipairs(invalid_cases) do
305+ local ok, err = upstream.check_schema(ups)
306+ if ok then
307+ ngx.log(ngx.ERR, "Expected invalid case passed: ", i)
308+ end
309+ assert(not ok, "Invalid IPv6 case should fail")
310+ assert(string.find(err, "IPv6 address must be enclosed with '%[' and '%]'"),
311+ "Error should mention IPv6 enclosure requirement")
312+ end
313+
314+ ngx.say("passed")
315+ }
316+ }
317+ --- response_body
318+ passed
0 commit comments