Update application UI and functionality

This commit is contained in:
2026-07-26 16:20:36 +08:00
parent b9aff58f32
commit 97ea6fb7aa
48 changed files with 2790 additions and 628 deletions
@@ -2,6 +2,7 @@ package auth
import (
"context"
"errors"
"net/http"
"net/http/httptest"
"path/filepath"
@@ -124,6 +125,46 @@ func TestLoginLocksAfterRepeatedFailures(t *testing.T) {
}
}
func TestLoginDatabaseCancellationDoesNotCountAsCredentialFailure(t *testing.T) {
root := t.TempDir()
store, err := db.Open(&config.Config{
StorageDir: root,
Database: config.DatabaseConfig{
Provider: "sqlite",
SQLitePath: filepath.Join(root, "cancel-login.sqlite"),
FailoverEnabled: true,
HealthIntervalSec: 3600,
},
})
if err != nil {
t.Fatal(err)
}
defer store.Close()
if err := store.EnsureDefaultAdmin(context.Background()); err != nil {
t.Fatal(err)
}
service := NewService(store)
captcha, err := service.NewCaptcha()
if err != nil {
t.Fatal(err)
}
service.mu.Lock()
answer := service.captchas[captcha.ID].answer
service.mu.Unlock()
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, _, ok, err := service.Login(ctx, "admin", "admin", captcha.ID, answer, "127.0.0.1")
if !errors.Is(err, context.Canceled) || ok {
t.Fatalf("canceled login returned ok=%v err=%v", ok, err)
}
service.mu.Lock()
_, exists := service.loginAttempts[loginAttemptKey("admin", "127.0.0.1")]
service.mu.Unlock()
if exists {
t.Fatal("database cancellation was counted as a credential failure")
}
}
func TestSessionCookieUsesSecureForForwardedHTTPS(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/api/admin/auth/login", nil)
req.Header.Set("X-Forwarded-Proto", "https")