-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_validator_test.go
61 lines (43 loc) · 1.5 KB
/
default_validator_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package jwt
import (
"testing"
"time"
"github.com/smarty/assertions/should"
"github.com/smarty/gunit"
)
func TestDefaultValidatorFixture(t *testing.T) {
gunit.Run(new(DefaultValidatorFixture), t)
}
type DefaultValidatorFixture struct {
*gunit.Fixture
validator Validator
}
func (this *DefaultValidatorFixture) Setup() {
this.validator = NewDefaultValidator("smarty", "streets")
}
func (this *DefaultValidatorFixture) TestFutureExpirationValid() {
future := time.Now().Add(time.Hour)
claim := StandardClaims{Expiration: future.Unix(), Audience: "smarty"}
err := this.validator.Validate(claim)
this.So(err, should.BeNil)
}
func (this *DefaultValidatorFixture) TestExpirationNotConsideredBecauseInterfaceNotImplemented() {
err := this.validator.Validate(0)
this.So(err, should.BeNil)
}
func (this *DefaultValidatorFixture) TestPastExpirationInvalid() {
past := time.Now().Add(-time.Nanosecond)
claim := StandardClaims{Expiration: past.Unix(), Audience: "smarty"}
err := this.validator.Validate(claim)
this.So(err, should.Equal, TokenExpiredErr)
}
func (this *DefaultValidatorFixture) TestAudienceIsValid() {
this.assertAudience("smarty", nil)
this.assertAudience("streets", nil)
this.assertAudience("INVALID", InvalidAudienceErr)
}
func (this *DefaultValidatorFixture) assertAudience(audience string, expectedError error) {
claim := StandardClaims{Expiration: time.Now().Add(time.Hour).Unix(), Audience: audience}
err := this.validator.Validate(claim)
this.So(err, should.Equal, expectedError)
}