idbeta commented on a change in pull request #1195:
URL: https://github.com/apache/apisix-dashboard/pull/1195#discussion_r551789865



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -536,3 +536,119 @@ func TestConsumer_with_createtime_updatetime(t 
*testing.T) {
                testCaseCheck(tc, t)
        }
 }
+
+func TestConsumer_with_jwt(t *testing.T) {
+       tests := []HttpTestCase{
+               {
+                       Desc:   "create consumer by PUT method",
+                       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)
+       if err != nil {
+               fmt.Printf("server not responding %s", err.Error())
+       }
+       defer resp.Body.Close()
+       assert.Equal(t, 200, resp.StatusCode)
+       respBody, _ := 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(respBody)},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "hello world",
+                       Sleep:        sleepTime,
+               },

Review comment:
       I found that the case `route_with_auth_plugin_test.go` already contains 
what you said, I added this new scenario here, so it should be easier to 
understand.




----------------------------------------------------------------
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]


Reply via email to