-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook_test.go
62 lines (49 loc) · 1.29 KB
/
hook_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
package hook
import (
"encoding/hex"
"testing"
"time"
"github.com/TykTechnologies/tyk-protobuf/bindings/go"
)
func BenchmarkSha256_Sha256Sum(b *testing.B) {
b.ReportAllocs()
s := Sha256{}
now := time.Now().Unix()
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
_ = s.Sha256Sum("foobarbaz", now)
}
}
func BenchmarkSha256_ValidateSignature(b *testing.B) {
b.ReportAllocs()
sharedSecret := "foobarbaz"
authToken := "4321knj8fqgm5ffq64tdzifato6fb5p5rkqze933ehivqelctivti8qs0xnzmpq3"
s := Sha256{}
s.Init(sharedSecret, 600, "Authorization", "X-Signature")
signatureAttempt := s.Sha256Sum(authToken, time.Now().Unix())
coprocessObj := coprocess.Object{
Request: &coprocess.MiniRequestObject{
Headers: map[string]string{
"Authorization": authToken,
"X-Signature": hex.EncodeToString(signatureAttempt),
},
},
Session: &coprocess.SessionState{
Metadata: map[string]string{
"secret": sharedSecret,
},
},
}
//requestJsBytes, _ := json.MarshalIndent(coprocessObj, "", "")
//println(string(requestJsBytes))
for n := 0; n < b.N; n++ {
t := Sha256{}
t.Init(sharedSecret, 600, "Authorization", "X-Signature")
//s.Init(sharedSecret, 600, )
_, err := s.ValidateSignature(&coprocessObj)
if err != nil {
b.Log(err.Error())
b.FailNow()
}
}
}