From e430b188c03effea9a80c53f0c2d4a1220f270fd Mon Sep 17 00:00:00 2001 From: Dave Grijalva Date: Sat, 11 Apr 2015 14:04:22 -0700 Subject: [PATCH] use pre-parsed rsa key for rsa benchmark and make sure signing actually succeeds --- jwt_test.go | 4 +++- rsa_test.go | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/jwt_test.go b/jwt_test.go index 583b19b..9108ded 100644 --- a/jwt_test.go +++ b/jwt_test.go @@ -178,7 +178,9 @@ func benchmarkSigning(b *testing.B, method jwt.SigningMethod, key interface{}) { t := jwt.New(method) b.RunParallel(func(pb *testing.PB) { for pb.Next() { - t.SignedString(key) + if _, err := t.SignedString(key); err != nil { + b.Fatal(err) + } } }) diff --git a/rsa_test.go b/rsa_test.go index 7479910..13ba1fc 100644 --- a/rsa_test.go +++ b/rsa_test.go @@ -144,13 +144,31 @@ func TestRSAKeyParsing(t *testing.T) { } func BenchmarkRS256Signing(b *testing.B) { - benchmarkSigning(b, jwt.SigningMethodRS256, hmacTestKey) + key, _ := ioutil.ReadFile("test/sample_key") + parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key) + if err != nil { + b.Fatal(err) + } + + benchmarkSigning(b, jwt.SigningMethodRS256, parsedKey) } func BenchmarkRS384Signing(b *testing.B) { - benchmarkSigning(b, jwt.SigningMethodRS384, hmacTestKey) + key, _ := ioutil.ReadFile("test/sample_key") + parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key) + if err != nil { + b.Fatal(err) + } + + benchmarkSigning(b, jwt.SigningMethodRS384, parsedKey) } func BenchmarkRS512Signing(b *testing.B) { - benchmarkSigning(b, jwt.SigningMethodRS512, hmacTestKey) + key, _ := ioutil.ReadFile("test/sample_key") + parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key) + if err != nil { + b.Fatal(err) + } + + benchmarkSigning(b, jwt.SigningMethodRS512, parsedKey) }