File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ package jws
77import (
88 "crypto/rand"
99 "crypto/rsa"
10+ "net/http"
11+ "strings"
1012 "testing"
1113)
1214
@@ -44,3 +46,32 @@ func TestVerifyFailsOnMalformedClaim(t *testing.T) {
4446 t .Error ("got no errors; want improperly formed JWT not to be verified" )
4547 }
4648}
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