Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: the plugin basic-auth needs required field #1251

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
}
}
--- 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]