1
1
package hook
2
2
3
3
import (
4
+ "encoding/hex"
4
5
"testing"
5
6
"time"
7
+
8
+ "github.com/TykTechnologies/tyk-protobuf/bindings/go"
6
9
)
7
10
8
11
func BenchmarkSha256_Sha256Sum (b * testing.B ) {
@@ -17,3 +20,43 @@ func BenchmarkSha256_Sha256Sum(b *testing.B) {
17
20
_ = s .Sha256Sum ("foobarbaz" , now )
18
21
}
19
22
}
23
+
24
+ func BenchmarkSha256_ValidateSignature (b * testing.B ) {
25
+
26
+ b .ReportAllocs ()
27
+
28
+ sharedSecret := "foobarbaz"
29
+ authToken := "4321knj8fqgm5ffq64tdzifato6fb5p5rkqze933ehivqelctivti8qs0xnzmpq3"
30
+
31
+ s := Sha256 {}
32
+ s .Init (sharedSecret , 600 , "Authorization" , "X-Signature" )
33
+ signatureAttempt := s .Sha256Sum (authToken , time .Now ().Unix ())
34
+
35
+ coprocessObj := coprocess.Object {
36
+ Request : & coprocess.MiniRequestObject {
37
+ Headers : map [string ]string {
38
+ "Authorization" : authToken ,
39
+ "X-Signature" : hex .EncodeToString (signatureAttempt ),
40
+ },
41
+ },
42
+ Session : & coprocess.SessionState {
43
+ Metadata : map [string ]string {
44
+ "secret" : sharedSecret ,
45
+ },
46
+ },
47
+ }
48
+
49
+ //requestJsBytes, _ := json.MarshalIndent(coprocessObj, "", "")
50
+ //println(string(requestJsBytes))
51
+
52
+ for n := 0 ; n < b .N ; n ++ {
53
+ t := Sha256 {}
54
+ t .Init (sharedSecret , 600 , "Authorization" , "X-Signature" )
55
+ //s.Init(sharedSecret, 600, )
56
+ _ , err := s .ValidateSignature (& coprocessObj )
57
+ if err != nil {
58
+ b .Log (err .Error ())
59
+ b .FailNow ()
60
+ }
61
+ }
62
+ }
0 commit comments