forked from jsteenb2/mess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjwt.go
35 lines (28 loc) · 773 Bytes
/
jwt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package tests
import (
"testing"
"github.com/dgrijalva/jwt-go"
"github.com/stretchr/testify/require"
)
func FakeAttendeeJWT(t *testing.T, userID string) string {
return fakeJWT(t, jwt.MapClaims{
"user_uuid": userID,
"email": "[email protected]",
"role": "attendee",
"name": "Attendee",
})
}
func FakeTrainerJWT(t *testing.T, userID string) string {
return fakeJWT(t, jwt.MapClaims{
"user_uuid": userID,
"email": "[email protected]",
"role": "trainer",
"name": "Trainer",
})
}
func fakeJWT(t *testing.T, claims jwt.MapClaims) string {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
tokenString, err := token.SignedString([]byte("mock_secret"))
require.NoError(t, err)
return tokenString
}