forked from codeclysm/introspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jwt_test.go
34 lines (30 loc) · 1.3 KB
/
jwt_test.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
package introspector_test
import (
"fmt"
"testing"
"github.com/codeclysm/introspector"
)
func TestJWT(t *testing.T) {
cases := []struct {
Token string
Action string
Resource string
Expected bool
ExpIntrospection introspector.Introspection
}{
{"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJleGFtcGxlIiwiZXhwIjoxNDg2Mzk0Nzc5LCJqdGkiOiJmODVjNTM0Yy03M2JhLTQ3NjMtYTU4MS0yMzkxN2I5Nzc5MjUiLCJpYXQiOjE0ODYzODg3NzksImlzcyI6ImFwaS5leGFtcGxlLmNjIiwibmJmIjoxNDg2Mzg4Nzc5LCJzdWIiOiJ0ZXN0IiwidXNlciI6eyJlbWFpbCI6InRlc3RAZXhhbXBsZS5jb20iLCJpZCI6InRlc3QiLCJ1aWQiOiJ0ZXN0In19.mpRwH7Klc2P1X93N1f0Qf_W3RcNfxm97xwSLEpgSlIw", "users", "modify", false,
introspector.Introspection{Active: false, Subject: "test", ExpiresAt: 1486394779, IssuedAt: 1486388779, NotBefore: 1486388779, Issuer: "api.example.cc", Audience: "example", Extra: map[string]interface{}{"user": map[string]interface{}{"email": "[email protected]", "id": "test", "uid": "test"}, "jti": "f85c534c-73ba-4763-a581-23917b977925"}}},
}
for _, tc := range cases {
jwt := introspector.JWT{
Key: []byte("secret"),
}
t.Run(fmt.Sprintf("%s", tc.Token), func(t *testing.T) {
i, err := jwt.Introspect(tc.Token)
if err != nil {
t.Fatalf("err: %s", err.Error())
}
equal(t, i, &tc.ExpIntrospection)
})
}
}