mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 06:19:08 +00:00
- 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
28 lines
666 B
Go
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)
|
|
}
|
|
}
|
|
}
|