File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ package jws
7
7
import (
8
8
"crypto/rand"
9
9
"crypto/rsa"
10
+ "net/http"
11
+ "strings"
10
12
"testing"
11
13
)
12
14
@@ -44,3 +46,32 @@ func TestVerifyFailsOnMalformedClaim(t *testing.T) {
44
46
t .Error ("got no errors; want improperly formed JWT not to be verified" )
45
47
}
46
48
}
49
+
50
+ func BenchmarkVerify (b * testing.B ) {
51
+ cases := []struct {
52
+ desc string
53
+ token string
54
+ }{
55
+ {
56
+ desc : "full of periods" ,
57
+ token : strings .Repeat ("." , http .DefaultMaxHeaderBytes ),
58
+ }, {
59
+ desc : "two trailing periods" ,
60
+ token : strings .Repeat ("a" , http .DefaultMaxHeaderBytes - 2 ) + ".." ,
61
+ },
62
+ }
63
+ privateKey , err := rsa .GenerateKey (rand .Reader , 2048 )
64
+ if err != nil {
65
+ b .Fatal (err )
66
+ }
67
+ for _ , bc := range cases {
68
+ f := func (b * testing.B ) {
69
+ b .ReportAllocs ()
70
+ b .ResetTimer ()
71
+ for range b .N {
72
+ Verify (bc .token , & privateKey .PublicKey )
73
+ }
74
+ }
75
+ b .Run (bc .desc , f )
76
+ }
77
+ }
You can’t perform that action at this time.
0 commit comments