-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: delete POST method in /apisix/admin/consumer (#852)
- Loading branch information
Showing
4 changed files
with
235 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package e2e | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestConsumer_Create_And_Get(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "check consumer is not exist", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers/consumer_1", | ||
Method: http.MethodGet, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusNotFound, | ||
ExpectBody: "data not found", | ||
}, | ||
{ | ||
caseDesc: "check consumer is not exist", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers/consumer_2", | ||
Method: http.MethodGet, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusNotFound, | ||
ExpectBody: "data not found", | ||
}, | ||
{ | ||
caseDesc: "create consumer by POST", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers", | ||
Method: http.MethodPost, | ||
Body: `{ | ||
"username": "consumer_1", | ||
"plugins": { | ||
"limit-count": { | ||
"count": 2, | ||
"time_window": 60, | ||
"rejected_code": 503, | ||
"key": "remote_addr" | ||
} | ||
}, | ||
"desc": "test description" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusNotFound, | ||
ExpectBody: "404 page not found", | ||
}, | ||
{ | ||
caseDesc: "create consumer by PUT", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers", | ||
Method: http.MethodPut, | ||
Body: `{ | ||
"username": "consumer_2", | ||
"plugins": { | ||
"limit-count": { | ||
"count": 2, | ||
"time_window": 60, | ||
"rejected_code": 503, | ||
"key": "remote_addr" | ||
} | ||
}, | ||
"desc": "test description" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "\"code\":0", | ||
Sleep: sleepTime, | ||
}, | ||
{ | ||
caseDesc: "get consumer", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers/consumer_2", | ||
Method: http.MethodGet, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "\"username\":\"consumer_2\"", | ||
}, | ||
{ | ||
caseDesc: "create consumer without username", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers", | ||
Method: http.MethodPut, | ||
Body: `{ | ||
"plugins": { | ||
"limit-count": { | ||
"count": 2, | ||
"time_window": 60, | ||
"rejected_code": 503, | ||
"key": "remote_addr" | ||
} | ||
}, | ||
"desc": "test description" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusBadRequest, | ||
ExpectBody: "\"code\":10000", | ||
}, | ||
{ | ||
caseDesc: "delete consumer", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers/consumer_2", | ||
Method: http.MethodDelete, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "\"code\":0", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} | ||
|
||
func TestConsumer_Update_And_Get(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "create consumer by PUT", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers", | ||
Method: http.MethodPut, | ||
Body: `{ | ||
"username": "consumer_3", | ||
"plugins": { | ||
"limit-count": { | ||
"count": 2, | ||
"time_window": 60, | ||
"rejected_code": 503, | ||
"key": "remote_addr" | ||
} | ||
}, | ||
"desc": "test description" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "\"code\":0", | ||
Sleep: sleepTime, | ||
}, | ||
{ | ||
caseDesc: "update consumer by PUT", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers/consumer_3", | ||
Method: http.MethodPut, | ||
Body: `{ | ||
"username": "consumer_3", | ||
"plugins": { | ||
"limit-count": { | ||
"count": 2, | ||
"time_window": 60, | ||
"rejected_code": 504, | ||
"key": "remote_addr" | ||
} | ||
}, | ||
"desc": "test description" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "\"code\":0", | ||
Sleep: sleepTime, | ||
}, | ||
{ | ||
caseDesc: "get consumer", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers/consumer_3", | ||
Method: http.MethodGet, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "\"rejected_code\":504", | ||
}, | ||
{ | ||
caseDesc: "delete consumer", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers/consumer_3", | ||
Method: http.MethodDelete, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "\"code\":0", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} |