Skip to content

Commit

Permalink
bugfix: the plugin basic-auth needs required field (apache#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
membphis authored and SaberMaster committed Jun 30, 2020
1 parent 6905e9f commit 74b04c6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lua/apisix/plugins/basic-auth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ local schema = {
username = { type = "string" },
password = { type = "string" },
},
oneOf = {
{required = {"username", "password"}},
{required = {}}
}
}

local plugin_name = "basic-auth"
Expand Down
2 changes: 1 addition & 1 deletion rockspec/apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
4 changes: 4 additions & 0 deletions t/admin/global-rules.t
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ passed
--- no_error_log
[error]
=== TEST 3: list global rules
--- config
location /t {
Expand Down Expand Up @@ -155,6 +157,8 @@ passed
--- no_error_log
[error]
=== TEST 4: PATCH global rules
--- config
location /t {
Expand Down
31 changes: 31 additions & 0 deletions t/plugin/basic-auth.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 74b04c6

Please sign in to comment.