Skip to content

Commit bd36f69

Browse files
author
Julien Cretel
committed
jws: benchmark Verify
1 parent 0042180 commit bd36f69

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

jws/jws_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package jws
77
import (
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+
}

0 commit comments

Comments
 (0)