Skip to content

Commit

Permalink
Get dynamic jwt token for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
PradipDKshirsagar committed Jun 17, 2020
1 parent 5b80d00 commit 1157c00
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions go-backend/service/common_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ func makeHTTPCall(method, path, requestURL, body string, handlerFunc http.Handle
// path: is used to configure router path (eg: /users/{id})
// requestURL: current request path (eg: /users/1)
func makeHTTPCallWithJWTMiddleware(method, path, requestURL, body string, handlerFunc http.HandlerFunc) (recorder *httptest.ResponseRecorder) {
// create jwt token with userID
JWTToken, _ := newJWT(1)

// create a http request using the given parameters
JWTToken := "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTQ3MzYwNzcsImlhdCI6MTU5MjMxNjg3NywiaXNzIjoiam9zaHNvZnR3YXJlLmNvbSIsInN1YiI6IjIifQ._LLKR0aXg9QKBuvyPQebUgQKLQEOb80DDwxTb7fE7-A"
req, _ := http.NewRequest(method, requestURL, strings.NewReader(body))
req.Header.Set("Authorization", JWTToken)
req.Header.Set("Authorization", "Bearer " + JWTToken)

// test recorder created for capturing api responses
recorder = httptest.NewRecorder()
Expand Down

0 comments on commit 1157c00

Please sign in to comment.