- Tests hash passwords at bcrypt.MinCost, set through the PasswordCost field of db.Params. - Test IRC servers check the queue only on broker notification; one test keeps the 100 ms fallback poll. - The stop-timeout test shortens the timeout through a test-only setter. - service and handlers tests build config.Config directly instead of through config.New, so they run in parallel: service had run serially, and handlers started its servers one at a time. - Repeated race trials run as parallel subtests. - Fixed sleeps become waits on the broker. - A new test covers the relay's failed queue read, which only the 100 ms poll had reached. Model: opus-5-5
This commit is contained in:
1 parent
bc8aa6bb96
commit
d39e0f2bb5
12 files changed
+362
-209
No files matched your search
+1
-1
@@ -22,7 +22,7 @@ func (database *Database) SetPassword(
|
||||
password string,
|
||||
) error {
|
||||
hash, err := bcrypt.GenerateFromPassword(
|
||||
[]byte(password), bcrypt.DefaultCost,
|
||||
[]byte(password), database.passwordCost,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("hash password: %w", err)
|
||||
|
||||
+18
-5
@@ -15,6 +15,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"sneak.berlin/go/neoirc/internal/config"
|
||||
"sneak.berlin/go/neoirc/internal/logger"
|
||||
|
||||
@@ -39,13 +40,19 @@ type Params struct {
|
||||
|
||||
Logger *logger.Logger
|
||||
Config *config.Config
|
||||
|
||||
// PasswordCost is the bcrypt cost at which SetPassword hashes
|
||||
// a password. The server leaves it unset, which means
|
||||
// bcrypt.DefaultCost. Tests set a lower cost to save time.
|
||||
PasswordCost int `optional:"true"`
|
||||
}
|
||||
|
||||
// Database manages the SQLite connection and migrations.
|
||||
type Database struct {
|
||||
conn *sql.DB
|
||||
log *slog.Logger
|
||||
params *Params
|
||||
conn *sql.DB
|
||||
log *slog.Logger
|
||||
params *Params
|
||||
passwordCost int
|
||||
}
|
||||
|
||||
// New creates a new Database and registers lifecycle hooks.
|
||||
@@ -53,9 +60,15 @@ func New(
|
||||
lifecycle fx.Lifecycle,
|
||||
params Params,
|
||||
) (*Database, error) {
|
||||
passwordCost := params.PasswordCost
|
||||
if passwordCost == 0 {
|
||||
passwordCost = bcrypt.DefaultCost
|
||||
}
|
||||
|
||||
database := &Database{ //nolint:exhaustruct // conn set in OnStart
|
||||
params: ¶ms,
|
||||
log: params.Logger.Get(),
|
||||
params: ¶ms,
|
||||
log: params.Logger.Get(),
|
||||
passwordCost: passwordCost,
|
||||
}
|
||||
|
||||
database.log.Info("Database instantiated")
|
||||
|
||||
@@ -8,10 +8,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"sneak.berlin/go/neoirc/internal/dbtest"
|
||||
)
|
||||
|
||||
// NewTestDatabase creates an in-memory database for testing.
|
||||
// NewTestDatabase creates an in-memory database for testing. It
|
||||
// hashes passwords at bcrypt.MinCost.
|
||||
func NewTestDatabase(tb testing.TB) (*Database, error) {
|
||||
tb.Helper()
|
||||
|
||||
@@ -23,8 +25,9 @@ func NewTestDatabase(tb testing.TB) (*Database, error) {
|
||||
}
|
||||
|
||||
database := &Database{ //nolint:exhaustruct // test helper, params not needed
|
||||
conn: conn,
|
||||
log: slog.Default(),
|
||||
conn: conn,
|
||||
log: slog.Default(),
|
||||
passwordCost: bcrypt.MinCost,
|
||||
}
|
||||
|
||||
err = database.runMigrations(context.Background())
|
||||
|
||||
Reference in new issue
Block a user