diff --git a/lua/apisix/plugins/basic-auth.lua b/lua/apisix/plugins/basic-auth.lua index 7c885898a3f7..b8cd8b94bf4e 100644 --- a/lua/apisix/plugins/basic-auth.lua +++ b/lua/apisix/plugins/basic-auth.lua @@ -30,6 +30,10 @@ local schema = { username = { type = "string" }, password = { type = "string" }, }, + oneOf = { + {required = {"username", "password"}}, + {required = {}} + } } local plugin_name = "basic-auth" diff --git a/rockspec/apisix-master-0.rockspec b/rockspec/apisix-master-0.rockspec index 5ad280b4fdd7..2cd3a91c3153 100644 --- a/rockspec/apisix-master-0.rockspec +++ b/rockspec/apisix-master-0.rockspec @@ -46,7 +46,7 @@ dependencies = { "luafilesystem = 1.7.0-2", "lua-tinyyaml = 0.1", "lua-resty-prometheus = 1.0", - "jsonschema = 0.6", + "jsonschema = 0.7", "lua-resty-ipmatcher = 0.6", } diff --git a/t/admin/global-rules.t b/t/admin/global-rules.t index a91af78029eb..aa7a0c600ea1 100644 --- a/t/admin/global-rules.t +++ b/t/admin/global-rules.t @@ -111,6 +111,8 @@ passed --- no_error_log [error] + + === TEST 3: list global rules --- config location /t { @@ -155,6 +157,8 @@ passed --- no_error_log [error] + + === TEST 4: PATCH global rules --- config location /t { diff --git a/t/plugin/basic-auth.t b/t/plugin/basic-auth.t index 1a10deb7fe2d..464bb027e3dd 100644 --- a/t/plugin/basic-auth.t +++ b/t/plugin/basic-auth.t @@ -196,3 +196,34 @@ Authorization: Basic Zm9vOmJhcg== hello world --- no_error_log [error] + + + +=== TEST 9: invalid schema, only one field `username` +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/consumers', + ngx.HTTP_PUT, + [[{ + "username": "foo", + "plugins": { + "basic-auth": { + "username": "foo" + } + } + }]] + ) + + ngx.status = code + ngx.print(body) + } + } +--- request +GET /t +--- error_code: 400 +--- response_body +{"error_msg":"invalid plugins configuration: failed to check the configuration of plugin basic-auth err: value should match only one schema, but matches none"} +--- no_error_log +[error]