chore: smoke tmpdir hygiene, seed pw floor, README

This commit is contained in:
2026-09-07 12:44:47 +08:00
parent 93638ed647
commit e0783e5e6a
4 changed files with 55 additions and 6 deletions
+4
View File
@@ -15,6 +15,10 @@ func Admin(ctx context.Context, s *store.Store, user, pass string) error {
if user == "" || pass == "" {
return nil
}
if len(pass) < 8 { // 与 API 建户口令下限一致
log.Printf("seed admin skipped: ADMIN_PASSWORD must be >= 8 chars")
return nil
}
n, err := s.CountUsers(ctx)
if err != nil || n > 0 {
return err
+8 -2
View File
@@ -21,10 +21,16 @@ func TestSeedOnlyWhenEmpty(t *testing.T) {
}
s := store.New(p)
p.Exec(ctx, "DELETE FROM reading_progress; DELETE FROM books; DELETE FROM libraries; DELETE FROM users")
if err := Admin(ctx, s, "admin", "pw12345"); err != nil {
if err := Admin(ctx, s, "shorty", "pw123"); err != nil { // <8 位 → 跳过 + log,不报错(空库时验证确实没建)
t.Fatal("short pw must no-op, got", err)
}
if _, err := s.GetUserByName(ctx, "shorty"); err == nil {
t.Fatal("short pw must not create user")
}
if err := Admin(ctx, s, "admin", "pw123456"); err != nil {
t.Fatal(err)
}
if err := Admin(ctx, s, "admin2", "pw12345"); err != nil { // 已有用户 → no-op
if err := Admin(ctx, s, "admin2", "pw123456"); err != nil { // 已有用户 → no-op
t.Fatal(err)
}
n, _ := s.CountUsers(ctx)