membphis commented on a change in pull request #830: URL: https://github.com/apache/apisix-dashboard/pull/830#discussion_r530754064
########## File path: api/test/e2e/consumer_test.go ########## @@ -0,0 +1,424 @@ +/* + * 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 ( + "io/ioutil" + "net/http" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/tidwall/gjson" +) + +//case 1: add consumer with username Review comment: remove useless code ########## File path: api/test/e2e/consumer_test.go ########## @@ -0,0 +1,424 @@ +/* + * 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 ( + "io/ioutil" + "net/http" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/tidwall/gjson" +) + +//case 1: add consumer with username +func TestConsumer_add_consumer_with_username(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create route", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "plugins": { + "key-auth": {} + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "172.16.238.20:1980": 1 + } + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + ExpectStatus: http.StatusUnauthorized, + ExpectBody: "Missing API key found in request", + Sleep: sleepTime, //sleep x millisecond before verify route + }, + { + caseDesc: "create consumer", + Object: MangerApiExpect(t), + Path: "/apisix/admin/consumers", + Method: http.MethodPut, + Body: `{ + "username": "case", + "plugins": { + "key-auth": { + "key": "auth-one" + } + }, + "desc": "test description" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", Review comment: desc: hit route with correct `key` ########## File path: api/test/e2e/consumer_test.go ########## @@ -0,0 +1,424 @@ +/* + * 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 ( + "io/ioutil" + "net/http" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/tidwall/gjson" +) + +//case 1: add consumer with username +func TestConsumer_add_consumer_with_username(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create route", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "plugins": { + "key-auth": {} + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "172.16.238.20:1980": 1 + } + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + ExpectStatus: http.StatusUnauthorized, + ExpectBody: "Missing API key found in request", + Sleep: sleepTime, //sleep x millisecond before verify route + }, + { + caseDesc: "create consumer", + Object: MangerApiExpect(t), + Path: "/apisix/admin/consumers", + Method: http.MethodPut, + Body: `{ + "username": "case", + "plugins": { + "key-auth": { + "key": "auth-one" + } + }, + "desc": "test description" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"apikey": "auth-one"}, + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + Sleep: sleepTime, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"apikey": "auth-new"}, + ExpectStatus: http.StatusUnauthorized, + ExpectBody: "Invalid API key in request", + Sleep: sleepTime, + }, Review comment: need to delete the `consumer` and check it in dataplane ########## File path: api/test/e2e/consumer_test.go ########## @@ -0,0 +1,424 @@ +/* + * 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 ( + "io/ioutil" + "net/http" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/tidwall/gjson" +) + +//case 1: add consumer with username +func TestConsumer_add_consumer_with_username(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create route", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "plugins": { + "key-auth": {} + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "172.16.238.20:1980": 1 + } + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + ExpectStatus: http.StatusUnauthorized, + ExpectBody: "Missing API key found in request", + Sleep: sleepTime, //sleep x millisecond before verify route + }, + { + caseDesc: "create consumer", + Object: MangerApiExpect(t), + Path: "/apisix/admin/consumers", + Method: http.MethodPut, + Body: `{ + "username": "case", + "plugins": { + "key-auth": { + "key": "auth-one" + } + }, + "desc": "test description" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"apikey": "auth-one"}, + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + Sleep: sleepTime, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"apikey": "auth-new"}, + ExpectStatus: http.StatusUnauthorized, + ExpectBody: "Invalid API key in request", + Sleep: sleepTime, + }, + } + + for _, tc := range tests { + testCaseCheck(tc) + } +} + +//case 2: add consumer without username +func TestConsumer_add_consumer_without_username(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create consumer", + Object: MangerApiExpect(t), + Path: "/apisix/admin/consumers", + Method: http.MethodPut, + Body: `{ + "plugins": { + "key-auth": { + "key": "auth-new" + } + }, + "desc": "test description" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusBadRequest, + }, + { + caseDesc: "verify route", Review comment: I think we need to create the `route` first ########## File path: api/test/e2e/consumer_test.go ########## @@ -0,0 +1,424 @@ +/* + * 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 ( + "io/ioutil" + "net/http" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/tidwall/gjson" +) + +//case 1: add consumer with username +func TestConsumer_add_consumer_with_username(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create route", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "plugins": { + "key-auth": {} + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "172.16.238.20:1980": 1 + } + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + ExpectStatus: http.StatusUnauthorized, + ExpectBody: "Missing API key found in request", + Sleep: sleepTime, //sleep x millisecond before verify route + }, + { + caseDesc: "create consumer", + Object: MangerApiExpect(t), + Path: "/apisix/admin/consumers", + Method: http.MethodPut, + Body: `{ + "username": "case", + "plugins": { + "key-auth": { + "key": "auth-one" + } + }, + "desc": "test description" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"apikey": "auth-one"}, + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + Sleep: sleepTime, + }, + { + caseDesc: "verify route", Review comment: desc: hit route with incorrect `key` ########## File path: api/test/e2e/consumer_test.go ########## @@ -0,0 +1,424 @@ +/* + * 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 ( + "io/ioutil" + "net/http" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/tidwall/gjson" +) + +//case 1: add consumer with username +func TestConsumer_add_consumer_with_username(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create route", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello", + "plugins": { + "key-auth": {} + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "172.16.238.20:1980": 1 + } + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + ExpectStatus: http.StatusUnauthorized, + ExpectBody: "Missing API key found in request", + Sleep: sleepTime, //sleep x millisecond before verify route + }, + { + caseDesc: "create consumer", + Object: MangerApiExpect(t), + Path: "/apisix/admin/consumers", + Method: http.MethodPut, + Body: `{ + "username": "case", + "plugins": { + "key-auth": { + "key": "auth-one" + } + }, + "desc": "test description" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"apikey": "auth-one"}, + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + Sleep: sleepTime, + }, + { + caseDesc: "verify route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello", + Headers: map[string]string{"apikey": "auth-new"}, + ExpectStatus: http.StatusUnauthorized, + ExpectBody: "Invalid API key in request", + Sleep: sleepTime, + }, + } + + for _, tc := range tests { + testCaseCheck(tc) + } +} + +//case 2: add consumer without username +func TestConsumer_add_consumer_without_username(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create consumer", Review comment: bad title. `create consumer without user name` ########## File path: api/test/e2e/consumer_test.go ########## @@ -0,0 +1,424 @@ +/* + * 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 ( + "io/ioutil" + "net/http" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/tidwall/gjson" +) + +//case 1: add consumer with username Review comment: and pls remove other similar points ---------------------------------------------------------------- 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: [email protected]
