package api import ( "os" "testing" "golang.org/x/crypto/bcrypt" ) // serverPasswordCost is the cost the server hashes stored passwords at, // taken before TestMain lowers it. var serverPasswordCost = passwordCost // The tests hash passwords at bcrypt's lowest cost: what they check is which // password is stored and who is signed out, not how slow a guess is. func TestMain(m *testing.M) { passwordCost = bcrypt.MinCost os.Exit(m.Run()) } // Lowering the cost for the tests must not hide a weaker one in the server. func TestPasswordCost_StoredPasswordsUseAtLeastBcryptsDefault(t *testing.T) { if serverPasswordCost < bcrypt.DefaultCost { t.Errorf("passwords are stored at bcrypt cost %d, want at least %d", serverPasswordCost, bcrypt.DefaultCost) } }