apisix-dashboard icon indicating copy to clipboard operation
apisix-dashboard copied to clipboard

[refactor][bug] bind params to struct error should response error with 400 status

Open nic-chen opened this issue 6 years ago • 7 comments

now it response normal.

here is an example:

$ curl http://127.0.0.1:8080/apisix/admin/services/1  -X PUT -i -d '
{
    "upstream": {
        "nodes": {
            "127.0.0.1:8080": 1
        },
        "type": "roundrobin"
    },
    "labels": {
        "env": ["production", "release"]
    },
    "desc": "new service"
}'

nic-chen avatar Oct 20 '20 08:10 nic-chen

@ShiningRush please take a look~

nic-chen avatar Oct 20 '20 15:10 nic-chen

ping @ShiningRush

juzhiyuan avatar Oct 22 '20 02:10 juzhiyuan

I'm still considering the solution, if there are any results, I will sync here

ShiningRush avatar Oct 22 '20 04:10 ShiningRush

if this is not urgent, feel free to move it to milestone 2.1.

juzhiyuan avatar Oct 22 '20 04:10 juzhiyuan

error format ofenv

{
    caseDesc: "create consumers with invalid format of label value",
    Object:   MangerApiExpect(t),
    Path:     "/apisix/admin/consumers",
    Method:   http.MethodPost,
    Body: `{
        "username":"case_10",
        "desc": "new consumer",
        "labels": {
            "env": ["production", "release"]
        }
    }`,
    Headers:      map[string]string{"Authorization": token},
    ExpectStatus: http.StatusBadRequest,
},

miss , in json

{
			Object:   MangerApiExpect(t),
			Method:   http.MethodPut,
			Path:     "/apisix/admin/routes/r1",
			Body: `{
					"uris": ["/hello","/status"]
					"upstream": {
						"type": "roundrobin",
						"nodes": [{
							"host": "172.16.238.20",
							"port": 1980,
							"weight": 1
						}]
					}
				}`,
			Headers:      map[string]string{"Authorization": token},
			ExpectStatus: http. StatusBadRequest,
			Sleep:        sleepTime,
		}

bad methods

{
			 caseDesc: "add route with invalid uri",
			 Object:   MangerApiExpect(t),
			 Method:   http.MethodPut,
			 Path:     "/apisix/admin/routes/r1",
			 Body: `{
					 "uri": "/hello",
					 "methods": [99999999999999999],
					 "upstream": {
						 "type": "roundrobin",
						 "nodes": [{
							 "host": "172.16.238.20",
							 "port": 1980,
							 "weight": 1
						 }]
					 }
				 }`,
			 Headers:      map[string]string{"Authorization": token},
			 ExpectStatus: http. StatusBadRequest,
		 },

bad priority

{
			 caseDesc: "add route with invalid data type priority",
			 Object:   MangerApiExpect(t),
			 Method:   http.MethodPut,
			 Path:     "/apisix/admin/routes/r1",
			 Body: `{
					  "uri": "/hello",
					  "priority": "dfssdfs",
					  "upstream": {
						  "type": "roundrobin",
						  "nodes": [{
							  "host": "172.16.238.20",
							  "port": 1980,
							  "weight": 1
						  }]
					  }
				  }`,
			 Headers:      map[string]string{"Authorization": token},
			 ExpectStatus: http.StatusBadRequest,
		 },

it return 200 now.

idbeta avatar Nov 26 '20 02:11 idbeta

I think JSON Schema can check this case

membphis avatar Nov 26 '20 03:11 membphis

I think JSON Schema can check this case

It has returned before the json schema verification

nic-chen avatar Nov 27 '20 05:11 nic-chen