This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 834e9e1  bugfix: the plugin basic-auth needs required field (#1251)
834e9e1 is described below

commit 834e9e1873e36349af742e3f51c90f4a0c75fa9a
Author: YuanSheng Wang <membp...@gmail.com>
AuthorDate: Fri Mar 13 20:05:44 2020 +0800

    bugfix: the plugin basic-auth needs required field (#1251)
    
    Fix #1244
---
 lua/apisix/plugins/basic-auth.lua |  4 ++++
 rockspec/apisix-master-0.rockspec |  2 +-
 t/admin/global-rules.t            |  4 ++++
 t/plugin/basic-auth.t             | 31 +++++++++++++++++++++++++++++++
 4 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/lua/apisix/plugins/basic-auth.lua 
b/lua/apisix/plugins/basic-auth.lua
index 7c88589..b8cd8b9 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 5ad280b..2cd3a91 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 a91af78..aa7a0c6 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 1a10deb..464bb02 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]

Reply via email to