This is an automated email from the ASF dual-hosted git repository.

kvn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new caab4f7  test: add consumer with key-auth ( E2E ) (#876)
caab4f7 is described below

commit caab4f7feb42e49344b943ad8f0d70a72d106e45
Author: idbeta <[email protected]>
AuthorDate: Thu Nov 26 17:38:24 2020 +0800

    test: add consumer with key-auth ( E2E ) (#876)
    
    * test: add consumer with username
    
    * chore: revert useless change
    
    * test: add hit route (consumer deleted)
    
    * chore: remove useless line
    
    * chore: update nodes style
    
    * chore: add ExpectBody
    
    * chore: add info for debug
    
    * chore: remove debug code
    
    * chore: modify function name
    
    * test: add case about delete not exist consumer
---
 api/test/e2e/consumer_test.go | 133 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)

diff --git a/api/test/e2e/consumer_test.go b/api/test/e2e/consumer_test.go
new file mode 100644
index 0000000..0c87f7d
--- /dev/null
+++ b/api/test/e2e/consumer_test.go
@@ -0,0 +1,133 @@
+/*
+ * 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_with_key_auth(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": [{
+                                               "host": "172.16.238.20",
+                                               "port": 1980,
+                                               "weight": 1
+                                       }]
+                                }
+                        }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       caseDesc:     "hit route without apikey",
+                       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": "jack",
+                                "plugins": {
+                                        "key-auth": {
+                                                "key": "auth-one"
+                                        }
+                                },
+                                "desc": "test description"
+                        }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       caseDesc:     "hit route with correct apikey",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       Headers:      map[string]string{"apikey": "auth-one"},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "hello world",
+                       Sleep:        sleepTime,
+               },
+               {
+                       caseDesc:     "hit route with incorrect apikey",
+                       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,
+               },
+               {
+                       caseDesc:     "delete consumer",
+                       Object:       MangerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/consumers/jack",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       caseDesc:     "delete consumer (as delete not exist 
consumer)",
+                       Object:       MangerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/consumers/jack",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusNotFound,
+               },
+               {
+                       caseDesc:     "hit route (consumer deleted)",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       Headers:      map[string]string{"apikey": "auth-one"},
+                       ExpectStatus: http.StatusUnauthorized,
+                       ExpectBody:   "Missing related consumer",
+                       Sleep:        sleepTime,
+               },
+               {
+                       caseDesc:     "delete route",
+                       Object:       MangerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/routes/r1",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc)
+       }
+}

Reply via email to