- Add GetMetrics method to MetricsClient interface and implement cluster metrics API - Add QuotaPrecheck service for validating resource quotas before deployment - Add auth DTO with role/permission models and auth handler tests - Add instance diagnostics: mounted NFS volumes, labels, annotations in pod diagnostics - Update workspace handler with GetWorkspace endpoint and shared-user list - Fix monitoring handler to use correct service method name - Add tail_lines fallback in instance handler for snake_case query params - Update nginx config for SSE log streaming support (no buffering) - Add comprehensive test coverage: auth_service_test, auth_handler_test, auth_dto_test, metrics_client_test, quota_precheck_test - Update error messages for quota validation and instance operations - ModifyModal: fix YAML lineWidth:0, modified keys summary, delta-only submit - InstanceCard: correctly disable scale-minus when replicas <= 0 - SidebarLayout: add hover transition for sidebar items - Update todo.md and lessons.md with latest fixes
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package rest
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLoginRateLimiterBlocksAfterConfiguredFailures(t *testing.T) {
|
|
now := time.Date(2026, 5, 14, 12, 0, 0, 0, time.UTC)
|
|
limiter := newLoginRateLimiter(time.Minute, 2)
|
|
limiter.now = func() time.Time { return now }
|
|
|
|
key := "user|127.0.0.1"
|
|
if !limiter.Allow(key) {
|
|
t.Fatal("expected first attempt to be allowed")
|
|
}
|
|
limiter.RecordFailure(key)
|
|
if !limiter.Allow(key) {
|
|
t.Fatal("expected second attempt to be allowed")
|
|
}
|
|
limiter.RecordFailure(key)
|
|
if limiter.Allow(key) {
|
|
t.Fatal("expected third attempt inside the window to be blocked")
|
|
}
|
|
|
|
now = now.Add(time.Minute + time.Second)
|
|
if !limiter.Allow(key) {
|
|
t.Fatal("expected attempts to be allowed after the window expires")
|
|
}
|
|
}
|
|
|
|
func TestLoginRateLimiterResetClearsFailures(t *testing.T) {
|
|
limiter := newLoginRateLimiter(time.Minute, 1)
|
|
key := "user|127.0.0.1"
|
|
|
|
limiter.RecordFailure(key)
|
|
if limiter.Allow(key) {
|
|
t.Fatal("expected key to be blocked after one failure")
|
|
}
|
|
limiter.Reset(key)
|
|
if !limiter.Allow(key) {
|
|
t.Fatal("expected reset key to be allowed")
|
|
}
|
|
}
|