Let a browser with cookies from an earlier database log in (closes #359)
check / check (push) Successful in 4m4s
check / check (push) Successful in 4m4s
A new database brings a new session key. A browser still holding the old session cookie got a 500 on a correct login: Session.Get returned the cookie's decode error and the login handler answered it with a 500. Get now treats a cookie that does not decode as absent, and logging in replaces it. gorilla/csrf already did the same for the CSRF cookie. A start that creates webhooker.db now logs "created a new, empty database" at WARN with its path, shortly before the first-boot banner, so an unexpectedly empty DATA_DIR is noticed. The codec tests now decode through the store, since Get no longer reports the codec's reason. Model: opus-5-5
This commit is contained in:
@@ -3,6 +3,8 @@ package database_test
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -83,3 +85,37 @@ func TestFirstBoot_PrintsTheAdminPasswordAsABanner(t *testing.T) {
|
||||
t, ok, "the printed password must open the seeded account",
|
||||
)
|
||||
}
|
||||
|
||||
// TestNewDatabase_IsLoggedWithItsPath is the log half of
|
||||
// https://git.eeqj.de/sneak/webhooker/issues/359. A DATA_DIR that is
|
||||
// unexpectedly empty boots exactly like a first start, so the start
|
||||
// that creates the database must say so, and where. Opening that
|
||||
// database again must not.
|
||||
func TestNewDatabase_IsLoggedWithItsPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dir := t.TempDir()
|
||||
|
||||
open := func() string {
|
||||
var out bytes.Buffer
|
||||
|
||||
db, err := database.Open(dir, slog.New(slog.NewTextHandler(&out, nil)))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.Close())
|
||||
|
||||
return out.String()
|
||||
}
|
||||
|
||||
const created = `level=WARN msg="created a new, empty database"`
|
||||
|
||||
first := open()
|
||||
second := open()
|
||||
|
||||
assert.Contains(
|
||||
t, first,
|
||||
created+" path="+filepath.Join(dir, database.MainDBFileName),
|
||||
)
|
||||
assert.NotContains(
|
||||
t, second, created, "an existing database is not new",
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user