feat: add SQLite storage for login attempts and sessions

Adds persistent storage using modernc.org/sqlite (pure Go). Login
attempts are deduplicated by (username, password, ip) with counts.
Sessions and session logs are tracked with UUID IDs. Includes embedded
SQL migrations, configurable retention with background pruning, and
an in-memory store for tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 17:33:45 +01:00
parent 75bac814d4
commit d655968216
21 changed files with 1131 additions and 10 deletions

View File

@@ -74,6 +74,15 @@ func TestLoadDefaults(t *testing.T) {
if cfg.LogLevel != "info" {
t.Errorf("default log_level = %q, want %q", cfg.LogLevel, "info")
}
if cfg.Storage.DBPath != "oubliette.db" {
t.Errorf("default db_path = %q, want %q", cfg.Storage.DBPath, "oubliette.db")
}
if cfg.Storage.RetentionDays != 90 {
t.Errorf("default retention_days = %d, want %d", cfg.Storage.RetentionDays, 90)
}
if cfg.Storage.RetentionIntervalDuration != time.Hour {
t.Errorf("default retention_interval = %v, want %v", cfg.Storage.RetentionIntervalDuration, time.Hour)
}
}
func TestLoadInvalidTTL(t *testing.T) {
@@ -113,6 +122,53 @@ password = "test"
}
}
func TestLoadInvalidRetentionInterval(t *testing.T) {
content := `
[storage]
retention_interval = "notaduration"
`
path := writeTemp(t, content)
_, err := Load(path)
if err == nil {
t.Fatal("expected error for invalid retention_interval")
}
}
func TestLoadInvalidRetentionDays(t *testing.T) {
content := `
[storage]
retention_days = -1
`
path := writeTemp(t, content)
_, err := Load(path)
if err == nil {
t.Fatal("expected error for negative retention_days")
}
}
func TestLoadStorageConfig(t *testing.T) {
content := `
[storage]
db_path = "/tmp/test.db"
retention_days = 30
retention_interval = "2h"
`
path := writeTemp(t, content)
cfg, err := Load(path)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if cfg.Storage.DBPath != "/tmp/test.db" {
t.Errorf("db_path = %q, want %q", cfg.Storage.DBPath, "/tmp/test.db")
}
if cfg.Storage.RetentionDays != 30 {
t.Errorf("retention_days = %d, want 30", cfg.Storage.RetentionDays)
}
if cfg.Storage.RetentionIntervalDuration != 2*time.Hour {
t.Errorf("retention_interval = %v, want 2h", cfg.Storage.RetentionIntervalDuration)
}
}
func TestLoadMissingFile(t *testing.T) {
_, err := Load("/nonexistent/path/config.toml")
if err == nil {