network/pkg/node/backoff_test.go
anonpenguin 917b0e5acd Enforce API key/JWT authentication and namespace gating in client
- Require API key or JWT by default for client connections - Auto-derive
namespace from JWT claim or API key format `ak_<rand>:<namespace>` -
Deny calls if per-call namespace override mismatches resolved namespace
- Guard Storage, PubSub, Database, and NetworkInfo operations with
access checks - Add context helpers for consistent namespace override
handling - Update docs and add end-to-end and unit tests for
authentication logic
2025-08-20 23:01:51 +03:00

28 lines
666 B
Go

package node
import (
"testing"
"time"
)
func TestCalculateNextBackoff(t *testing.T) {
if got := calculateNextBackoff(10 * time.Second); got <= 10*time.Second || got > 15*time.Second {
t.Fatalf("unexpected next: %v", got)
}
if got := calculateNextBackoff(10 * time.Minute); got != 10*time.Minute {
t.Fatalf("cap not applied: %v", got)
}
}
func TestAddJitter(t *testing.T) {
base := 10 * time.Second
min := base - time.Duration(0.2*float64(base))
max := base + time.Duration(0.2*float64(base))
for i := 0; i < 100; i++ {
got := addJitter(base)
if got < time.Second || got < min || got > max {
t.Fatalf("jitter out of range: %v", got)
}
}
}