-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generator_test.go
57 lines (46 loc) · 1.27 KB
/
Generator_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
package hmac
import (
"testing"
)
func Test_Generate(t *testing.T) {
now := "1389349028"
uri := "/home"
algo := "sha512"
key := "A super secret key!!"
SetUri(uri)
SetTimestamp(now)
SetAlgorithm(algo)
SetKey(key)
Generate(Encode)
//this value will need to be recalculated if the encode method is modified
hmacValue := "3f74e1d499ae2aea80cbbb86aa3923bfda19417e45149fb7ad474ce5143048f2dd594868d82796a9e90f2052c852850558874125b2924ffdf9a54b65f7e676ef"
if Hash.Hmac == "" {
t.Errorf("The HMAC was not generated (%v)", Hash.Hmac)
}
if Hash.Hmac != hmacValue {
t.Errorf("The HMAC generated does not match what was expected (%v)", Hash.Hmac)
}
if Hash.Timestamp != now {
t.Errorf("The timestamp appears to have been changed, expecting: %s received: (%v)", now, Hash.Timestamp)
}
if Hash.Uri != uri {
t.Errorf("The URI appears to have been changed, expecting: %s received: (%v)", uri, Hash.Uri)
}
}
func Benchmark_Generate(b *testing.B) {
now := "1389349028"
uri := "/home"
algo := "sha512"
key := "A super secret key!!"
SetUri(uri)
SetTimestamp(now)
SetAlgorithm(algo)
SetKey(key)
b.ResetTimer()
for i := 0; i < b.N; i++ {
Generate(mock_encoder)
}
}
func mock_encoder(uri string, timestamp string) string {
return "abcdefghijklmnopqrstuvwxyz1234567890"
}