Use database.User.SetPassword in server tests
This commit is contained in:
parent
979fb319fe
commit
d67e59658d
@ -6,7 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
"gopkg.in/irc.v4"
|
"gopkg.in/irc.v4"
|
||||||
|
|
||||||
"git.sr.ht/~emersion/soju/database"
|
"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 {
|
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{
|
record := &database.User{
|
||||||
Username: testUsername,
|
Username: testUsername,
|
||||||
Password: string(hashed),
|
|
||||||
Enabled: true,
|
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 {
|
if err := db.StoreUser(context.Background(), record); err != nil {
|
||||||
t.Fatalf("failed to store test user: %v", err)
|
t.Fatalf("failed to store test user: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user