Files
coder/coderd/userpassword/hashing_bench_test.go
Kyle Carberry b948f2dab5 fix: Use environment variables for agent authentication (#1238)
* fix: Update GIT_COMMITTER_NAME to use username

This was a mistake when adding the committer fields 🤦.

* fix: Use environment variables for agent authentication

Using files led to situations where running "coder server --dev" would
break `gitssh`. This is applicable in a production environment too. Users
should be able to log into another Coder deployment from their workspace.

Users can still set "CODER_URL" if they'd like with agent env vars!
2022-04-30 16:40:30 +00:00

72 lines
1.1 KiB
Go

package userpassword_test
import (
"crypto/sha256"
"testing"
"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/pbkdf2"
"github.com/coder/coder/cryptorand"
)
var (
salt = []byte(must(cryptorand.String(16)))
secret = []byte(must(cryptorand.String(24)))
resBcrypt []byte
resPbkdf2 []byte
)
func BenchmarkBcryptMinCost(b *testing.B) {
var r []byte
b.ReportAllocs()
for i := 0; i < b.N; i++ {
r, _ = bcrypt.GenerateFromPassword(secret, bcrypt.MinCost)
}
resBcrypt = r
}
func BenchmarkPbkdf2MinCost(b *testing.B) {
var r []byte
b.ReportAllocs()
for i := 0; i < b.N; i++ {
r = pbkdf2.Key(secret, salt, 1024, 64, sha256.New)
}
resPbkdf2 = r
}
func BenchmarkBcryptDefaultCost(b *testing.B) {
var r []byte
b.ReportAllocs()
for i := 0; i < b.N; i++ {
r, _ = bcrypt.GenerateFromPassword(secret, bcrypt.DefaultCost)
}
resBcrypt = r
}
func BenchmarkPbkdf2(b *testing.B) {
var r []byte
b.ReportAllocs()
for i := 0; i < b.N; i++ {
r = pbkdf2.Key(secret, salt, 65536, 64, sha256.New)
}
resPbkdf2 = r
}
func must(s string, err error) string {
if err != nil {
panic(err)
}
return s
}