-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbewit_test.go
77 lines (62 loc) · 1.73 KB
/
bewit_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package hawk
import (
"testing"
"time"
)
type stubbedClock struct{}
func (c *stubbedClock) Now(offset time.Duration) int64 {
return 1365711458
}
func TestBewitConfig_GetBewit(t *testing.T) {
c := &Credential{
ID: "123456",
Key: "2983d45yun89q",
Alg: SHA256,
}
b1 := NewBewitConfig(c, (24 * time.Hour * 365 * 100))
b1.Ext = "some-app-data"
actual1 := b1.GetBewit("http://example.com/resource/4?a=1&b=2", &stubbedClock{})
expect1 := "MTIzNDU2XDQ1MTkzMTE0NThcYkkwanFlS1prUHE0V1hRMmkxK0NrQ2lOanZEc3BSVkNGajlmbElqMXphWT1cc29tZS1hcHAtZGF0YQ"
if actual1 != expect1 {
t.Errorf("invalid bewit: %s", actual1)
}
}
func TestBewitConfig_GetBewit2(t *testing.T) {
c := &Credential{
ID: "123456",
Key: "2983d45yun89q",
Alg: SHA256,
}
b1 := NewBewitConfig(c, (24 * time.Hour * 365 * 100))
b1.Ext = "some-app-data"
// url parameter is null-string
actual2 := b1.GetBewit("", &stubbedClock{})
if actual2 != "" {
t.Error("expect null-string, but got ", actual2)
}
b3 := &BewitConfig{
Credential: nil,
Ttl: 24 * time.Hour * 365 * 100,
Ext: "some-app-data",
}
// credential is nil
actual3 := b3.GetBewit("http://example.com/resource/4?a=1&b=2", &stubbedClock{})
if actual3 != "" {
t.Error("expect null-string, but got ", actual2)
}
b4 := &BewitConfig{
Credential: &Credential{},
Ttl: 24 * time.Hour * 365 * 100,
Ext: "some-app-data",
}
// Credential members are nil
actual4 := b4.GetBewit("http://example.com/resource/4?a=1&b=2", &stubbedClock{})
if actual4 != "" {
t.Error("expect null-string, but got ", actual2)
}
// Clock is nil
actual5 := b1.GetBewit("http://example.com/resource/4?a=1&b=2", nil)
if actual5 == "" {
t.Error("expect result is not null, but got null value")
}
}