You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by we...@apache.org on 2020/08/24 01:27:57 UTC
[apisix] branch master updated: change: update plugin's schema
ip-restriction with `draft7` way (#2091)
This is an automated email from the ASF dual-hosted git repository.
wenming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 1aefe91 change: update plugin's schema ip-restriction with `draft7` way (#2091)
1aefe91 is described below
commit 1aefe915f1a01ff7d068cfe7013676bfece2d43e
Author: YuanSheng Wang <me...@gmail.com>
AuthorDate: Mon Aug 24 09:27:49 2020 +0800
change: update plugin's schema ip-restriction with `draft7` way (#2091)
---
apisix/plugins/ip-restriction.lua | 36 +++++++++++++++++++++++-------------
apisix/schema_def.lua | 8 ++++----
t/plugin/ip-restriction.t | 6 +++---
3 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/apisix/plugins/ip-restriction.lua b/apisix/plugins/ip-restriction.lua
index f08c9c7..2dead12 100644
--- a/apisix/plugins/ip-restriction.lua
+++ b/apisix/plugins/ip-restriction.lua
@@ -27,21 +27,31 @@ local lrucache = core.lrucache.new({
local schema = {
type = "object",
- properties = {
- whitelist = {
- type = "array",
- items = {type = "string", anyOf = core.schema.ip_def},
- minItems = 1
+ oneOf = {
+ {
+ title = "whitelist",
+ properties = {
+ whitelist = {
+ type = "array",
+ items = {anyOf = core.schema.ip_def},
+ minItems = 1
+ },
+ },
+ required = {"whitelist"},
+ additionalProperties = false,
},
- blacklist = {
- type = "array",
- items = {type = "string", anyOf = core.schema.ip_def},
- minItems = 1
+ {
+ title = "blacklist",
+ properties = {
+ blacklist = {
+ type = "array",
+ items = {anyOf = core.schema.ip_def},
+ minItems = 1
+ }
+ },
+ required = {"blacklist"},
+ additionalProperties = false,
}
- },
- oneOf = {
- {required = {"whitelist"}},
- {required = {"blacklist"}}
}
}
diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua
index 222938b..ef234c0 100644
--- a/apisix/schema_def.lua
+++ b/apisix/schema_def.lua
@@ -49,10 +49,10 @@ local ipv4_def = "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"
local ipv6_def = "([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}"
.. "([a-fA-F0-9]{0,4})?"
local ip_def = {
- {pattern = "^" .. ipv4_def .. "$"},
- {pattern = "^" .. ipv4_def .. "/[0-9]{1,2}$"},
- {pattern = "^" .. ipv6_def .. "$"},
- {pattern = "^" .. ipv6_def .. "/[0-9]{1,3}$"},
+ {title = "IPv4", type = "string", pattern = "^" .. ipv4_def .. "$"},
+ {title = "IPv4/CIDR", type = "string", pattern = "^" .. ipv4_def .. "/[0-9]{1,2}$"},
+ {title = "IPv6", type = "string", pattern = "^" .. ipv6_def .. "$"},
+ {title = "IPv6/CIDR", type = "string", pattern = "^" .. ipv6_def .. "/[0-9]{1,3}$"},
}
_M.ip_def = ip_def
diff --git a/t/plugin/ip-restriction.t b/t/plugin/ip-restriction.t
index 9403819..58b0aee 100644
--- a/t/plugin/ip-restriction.t
+++ b/t/plugin/ip-restriction.t
@@ -160,7 +160,7 @@ done
--- request
GET /t
--- response_body
-property "blacklist" validation failed: expect array to have at least 1 items
+value should match only one schema, but matches none
done
--- no_error_log
[error]
@@ -183,7 +183,7 @@ done
--- request
GET /t
--- response_body
-value should match only one schema, but matches both schemas 1 and 2
+value should match only one schema, but matches none
done
--- no_error_log
[error]
@@ -565,6 +565,6 @@ GET /hello
GET /t
--- response_body
invalid ip address: ::1/129
-property "whitelist" validation failed: failed to validate item 1: object matches none of the requireds
+value should match only one schema, but matches none
--- no_error_log
[error]