You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/02 10:13:04 UTC
[GitHub] [apisix-dashboard] gxthrj commented on a change in pull request #952: fix: hack to fix the checking of `remote_addrs`
gxthrj commented on a change in pull request #952:
URL: https://github.com/apache/apisix-dashboard/pull/952#discussion_r534047655
##########
File path: api/internal/core/store/validate_test.go
##########
@@ -247,5 +247,134 @@ func TestAPISIXJsonSchemaValidator_checkUpstream(t *testing.T) {
err = validator.Validate(route5)
assert.NotNil(t, err)
assert.EqualError(t, err, "schema validate failed: (root): Does not match pattern '^((uri|server_name|server_addr|request_uri|remote_port|remote_addr|query_string|host|hostname)|arg_[0-9a-zA-z_-]+)$'")
+}
+
+func TestAPISIXJsonSchemaValidator_Route_checkRemoteAddr(t *testing.T) {
+ tests := []struct {
+ caseDesc string
+ giveContent string
+ wantNewErr error
+ wantValidateErr error
+ }{
+ {
+ caseDesc: "correct remote_addr",
+ giveContent: `{
+ "id": "1",
+ "uri": "/*",
+ "upstream": {
+ "nodes": [{
+ "host": "127.0.0.1",
+ "port": 8080,
+ "weight": 1
+ }],
+ "type": "roundrobin"
+ },
+ "remote_addr": "127.0.0.1"
+ }`,
+ },
+ {
+ caseDesc: "correct remote_addr (CIDR)",
+ giveContent: `{
+ "id": "1",
+ "uri": "/*",
+ "upstream": {
+ "nodes": [{
+ "host": "127.0.0.1",
+ "port": 8080,
+ "weight": 1
+ }],
+ "type": "roundrobin"
+ },
+ "remote_addr": "192.168.1.0/24"
+ }`,
+ },
+ {
+ caseDesc: "invalid remote_addr",
+ giveContent: `{
+ "id": "1",
+ "uri": "/*",
+ "upstream": {
+ "nodes": [{
+ "host": "127.0.0.1",
+ "port": 8080,
+ "weight": 1
+ }],
+ "type": "roundrobin"
+ },
+ "remote_addr": "127.0.0."
+ }`,
+ wantValidateErr: fmt.Errorf("schema validate failed: remote_addr: Must validate at least one schema (anyOf)\nremote_addr: Does not match pattern '^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'"),
+ },
+ {
+ caseDesc: "correct remote_addrs",
+ giveContent: `{
+ "id": "1",
+ "uri": "/*",
+ "upstream": {
+ "nodes": [{
+ "host": "127.0.0.1",
+ "port": 8080,
+ "weight": 1
+ }],
+ "type": "roundrobin"
+ },
+ "remote_addrs": ["127.0.0.1", "192.0.0.0/8", "::1", "fe80::1/64"]
+ }`,
+ },
Review comment:
There is no assert, is it default ok?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org