Update application UI and functionality
This commit is contained in:
@@ -112,10 +112,13 @@ func (s *Service) Login(ctx context.Context, username, password, captchaID, capt
|
||||
return "", "", false, nil
|
||||
}
|
||||
user, ok, err := s.store.VerifyAdminPassword(ctx, username, password)
|
||||
if err != nil || !ok {
|
||||
s.recordLoginFailure(attemptKey)
|
||||
if err != nil {
|
||||
return "", "", false, err
|
||||
}
|
||||
if !ok {
|
||||
s.recordLoginFailure(attemptKey)
|
||||
return "", "", false, nil
|
||||
}
|
||||
sessionID := randomToken(32)
|
||||
csrf := randomToken(32)
|
||||
s.mu.Lock()
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user