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

chenjunxu 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 3fcb580  test: backend e2e test for route with jwt (no algorithm) 
(#1195)
3fcb580 is described below

commit 3fcb5803dfeb06ff0045f860386d420243d8804e
Author: idbeta <idb...@gmail.com>
AuthorDate: Wed Jan 13 13:19:54 2021 +0800

    test: backend e2e test for route with jwt (no algorithm) (#1195)
    
    * test: backend e2e test for create consumer with jwt
    
    * chore: add sleeptime
    
    * fixed: test route with jwt-auth plugin
    
    * move the new case to route_with_auth_plugin_test.go
    
    * chore: modify case desc
    
    * chore: modify jwt token name
    
    * modify method for get the token of jwt
    
    * modify file name
    
    Co-authored-by: nic-chen <33000667+nic-c...@users.noreply.github.com>
    Co-authored-by: YuanSheng Wang <membp...@gmail.com>
    Co-authored-by: 琚致远 <juzhiy...@apache.org>
---
 ...lugin_test.go => route_with_plugin_jwt_test.go} | 114 ++++++++++++++++++++-
 1 file changed, 113 insertions(+), 1 deletion(-)

diff --git a/api/test/e2e/route_with_auth_plugin_test.go 
b/api/test/e2e/route_with_plugin_jwt_test.go
similarity index 62%
rename from api/test/e2e/route_with_auth_plugin_test.go
rename to api/test/e2e/route_with_plugin_jwt_test.go
index ef5e290..9ceec91 100644
--- a/api/test/e2e/route_with_auth_plugin_test.go
+++ b/api/test/e2e/route_with_plugin_jwt_test.go
@@ -17,6 +17,7 @@
 package e2e
 
 import (
+       "io/ioutil"
        "net/http"
        "testing"
        "time"
@@ -24,7 +25,7 @@ import (
        "github.com/stretchr/testify/assert"
 )
 
-func TestRoute_With_Auth_Plugin(t *testing.T) {
+func TestRoute_With_Jwt_Plugin(t *testing.T) {
        tests := []HttpTestCase{
                {
                        Desc:         "make sure the route is not created ",
@@ -173,4 +174,115 @@ func TestRoute_With_Auth_Plugin(t *testing.T) {
                testCaseCheck(tc, t)
        }
 
+       tests = []HttpTestCase{
+               {
+                       Desc:   "create consumer with jwt (no algorithm)",
+                       Object: ManagerApiExpect(t),
+                       Path:   "/apisix/admin/consumers",
+                       Method: http.MethodPut,
+                       Body: `{
+                               "username":"consumer_1",
+                               "desc": "test description",
+                               "plugins":{
+                                       "jwt-auth":{
+                                               "exp":86400,
+                                               "key":"user-key",
+                                               "secret":"my-secret-key"
+                                       }
+                               }
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"code\":0",
+               },
+               {
+                       Desc:         "get the consumer",
+                       Object:       ManagerApiExpect(t),
+                       Path:         "/apisix/admin/consumers/consumer_1",
+                       Method:       http.MethodGet,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"username\":\"consumer_1\"",
+                       Sleep:        sleepTime,
+               },
+               {
+                       Desc:   "create the route",
+                       Object: ManagerApiExpect(t),
+                       Method: http.MethodPut,
+                       Path:   "/apisix/admin/routes/r1",
+                       Body: `{
+                               "uri": "/hello",
+                               "plugins": {
+                                       "jwt-auth": {}
+                               },
+                               "upstream": {
+                                       "type": "roundrobin",
+                                       "nodes": [{
+                                               "host": "172.16.238.20",
+                                               "port": 1980,
+                                               "weight": 1
+                                       }]
+                               }
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc, t)
+       }
+
+       // get the token of jwt
+       basepath := "http://127.0.0.1:9080";
+       request, _ := http.NewRequest("GET", 
basepath+"/apisix/plugin/jwt/sign?key=user-key", nil)
+       request.Header.Add("Authorization", token)
+       resp, err := http.DefaultClient.Do(request)
+       assert.Nil(t, err)
+       defer resp.Body.Close()
+       assert.Equal(t, 200, resp.StatusCode)
+       jwttoken, _ := ioutil.ReadAll(resp.Body)
+
+       tests = []HttpTestCase{
+               {
+                       Desc:         "hit route with jwt token",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       Headers:      map[string]string{"Authorization": 
string(jwttoken)},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "hello world",
+                       Sleep:        sleepTime,
+               },
+               {
+                       Desc:         "delete consumer",
+                       Object:       ManagerApiExpect(t),
+                       Path:         "/apisix/admin/consumers/consumer_1",
+                       Method:       http.MethodDelete,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"code\":0",
+               },
+               {
+                       Desc:         "after delete consumer verify it again",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/apisix/admin/consumers/jack",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusNotFound,
+                       Sleep:        sleepTime,
+               },
+               {
+                       Desc:         "delete the route",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/routes/r1",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc, t)
+       }
 }

Reply via email to