Skip to content

Commit

Permalink
feat: add test cases for rejecting request data if it contains an emp…
Browse files Browse the repository at this point in the history
…ty array (#1112)

* feat: add test cases for empty array
  • Loading branch information
nic-chen authored Dec 24, 2020
1 parent 0895900 commit d2b5772
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions api/test/e2e/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,116 @@ func TestRoute_Patch(t *testing.T) {
testCaseCheck(tc, t)
}
}

//uris methods remote_addrs
func TestRoute_With_Empty_Array(t *testing.T) {
tests := []HttpTestCase{
{
Desc: "create route with empty hosts and host",
Object: ManagerApiExpect(t),
Path: "/apisix/admin/routes/r1",
Method: http.MethodPut,
Body: `{
"uri": "/hello",
"hosts": [],
"host": "test.com",
"upstream": {
"nodes": {
"172.16.238.20:1980": 1
},
"type": "roundrobin"
}
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusBadRequest,
ExpectBody: `{"code":10000,"message":"schema validate failed: (root): Must validate one and only one schema (oneOf)\n(root): Must validate all the schemas (allOf)\nhosts: Array must have at least 1 items"}`,
},
{
Desc: "make sure the route not created",
Object: APISIXExpect(t),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{"Host": "test.com"},
ExpectStatus: http.StatusNotFound,
ExpectBody: `{"error_msg":"404 Route Not Found"}`,
},
{
Desc: "create route with empty hosts",
Object: ManagerApiExpect(t),
Path: "/apisix/admin/routes/r1",
Method: http.MethodPut,
Body: `{
"uri": "/hello",
"hosts": [],
"upstream": {
"nodes": {
"172.16.238.20:1980": 1
},
"type": "roundrobin"
}
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusBadRequest,
ExpectBody: `{"code":10000,"message":"schema validate failed: hosts: Array must have at least 1 items"}`,
},
{
Desc: "make sure the route not created",
Object: APISIXExpect(t),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusNotFound,
ExpectBody: `{"error_msg":"404 Route Not Found"}`,
},
{
Desc: "create route with empty uris and uri",
Object: ManagerApiExpect(t),
Path: "/apisix/admin/routes/r1",
Method: http.MethodPut,
Body: `{
"uri": "/hello",
"uris": [],
"upstream": {
"nodes": {
"172.16.238.20:1980": 1
},
"type": "roundrobin"
}
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusBadRequest,
ExpectBody: `{"code":10000,"message":"schema validate failed: (root): Must validate one and only one schema (oneOf)\n(root): Must validate all the schemas (allOf)\nuris: Array must have at least 1 items"}`,
},
{
Desc: "create route with empty remote_addrs and remote_addr",
Object: ManagerApiExpect(t),
Path: "/apisix/admin/routes/r1",
Method: http.MethodPut,
Body: `{
"uri": "/hello",
"remote_addrs": [],
"remote_addr": "0.0.0.0",
"upstream": {
"nodes": {
"172.16.238.20:1980": 1
},
"type": "roundrobin"
}
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusBadRequest,
ExpectBody: `{"code":10000,"message":"schema validate failed: (root): Must validate one and only one schema (oneOf)\n(root): Must validate all the schemas (allOf)\nremote_addrs: Array must have at least 1 items"}`,
},
{
Desc: "make sure the route not created",
Object: APISIXExpect(t),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusNotFound,
ExpectBody: `{"error_msg":"404 Route Not Found"}`,
},
}

for _, tc := range tests {
testCaseCheck(tc, t)
}
}

0 comments on commit d2b5772

Please sign in to comment.