Use database.User.SetPassword in server tests

This commit is contained in:
Simon Ser 2023-01-30 11:20:27 +01:00
parent 979fb319fe
commit d67e59658d

View File

@ -6,7 +6,6 @@ import (
"os"
"testing"
"golang.org/x/crypto/bcrypt"
"gopkg.in/irc.v4"
"git.sr.ht/~emersion/soju/database"
@ -46,16 +45,13 @@ func createTempPostgresDB(t *testing.T) database.Database {
}
func createTestUser(t *testing.T, db database.Database) *database.User {
hashed, err := bcrypt.GenerateFromPassword([]byte(testPassword), bcrypt.DefaultCost)
if err != nil {
t.Fatalf("failed to generate bcrypt hash: %v", err)
}
record := &database.User{
Username: testUsername,
Password: string(hashed),
Enabled: true,
}
if err := record.SetPassword(testPassword); err != nil {
t.Fatalf("failed to generate bcrypt hash: %v", err)
}
if err := db.StoreUser(context.Background(), record); err != nil {
t.Fatalf("failed to store test user: %v", err)
}