-
Notifications
You must be signed in to change notification settings - Fork 12
/
jwt_test.go
44 lines (36 loc) · 857 Bytes
/
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
35
36
37
38
39
40
41
42
43
44
package jwtbeego_test
import (
"testing"
"time"
"github.com/juusechec/jwt-beego"
)
var (
tokenStringGlobal string
)
// TestGetToken is the testing function por jwtbeego
func TestGetToken(t *testing.T) {
et := jwtbeego.EasyToken{
Username: "username",
Expires: time.Now().Unix() + 3600, //Segundos
}
tokenString, err := et.GetToken()
tokenStringGlobal = tokenString
if tokenString == "" {
t.Errorf("Token String empty.")
}
if err != nil {
t.Errorf("Error while verifying GetToken: %v", err)
}
}
// TestValidateToken is the testing function por jwtbeego
func TestValidateToken(t *testing.T) {
tokenString := tokenStringGlobal //c.Ctx.Input.Query("username")
et := jwtbeego.EasyToken{}
valido, issuer, err := et.ValidateToken(tokenString)
if !valido {
t.Errorf(err.Error())
}
if issuer == "" {
t.Errorf("no issuer")
}
}