use pre-parsed rsa key for rsa benchmark and make sure signing actually succeeds

This commit is contained in:
Dave Grijalva 2015-04-11 14:04:22 -07:00
parent c0c67af490
commit e430b188c0
2 changed files with 24 additions and 4 deletions

View File

@ -178,7 +178,9 @@ func benchmarkSigning(b *testing.B, method jwt.SigningMethod, key interface{}) {
t := jwt.New(method) t := jwt.New(method)
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
for pb.Next() { for pb.Next() {
t.SignedString(key) if _, err := t.SignedString(key); err != nil {
b.Fatal(err)
}
} }
}) })

View File

@ -144,13 +144,31 @@ func TestRSAKeyParsing(t *testing.T) {
} }
func BenchmarkRS256Signing(b *testing.B) { 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) { 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) { 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)
} }