Files
AetherForge/server/internal/api/websocket_auth_test.go
drjones 9e26c4babb Broad bug hunt: auth flow, WS edge cases, and build hygiene.
Scope API auth to /api/v1, fix dashboard WebSocket 401s, session login in Calibrate, safe agent naming, reconnect races, and remove corrupt ollama/main.go.
2026-05-28 19:53:53 -07:00

54 lines
1.2 KiB
Go

package api
import (
"encoding/json"
"testing"
)
func TestAuthPayloadWorkerNameFallback(t *testing.T) {
payload := map[string]string{
"worker_name": "forged-worker-1",
"hostname": "DESKTOP-ABC",
}
data, _ := json.Marshal(payload)
var auth struct {
WorkerName string `json:"worker_name"`
Worker string `json:"worker"`
Hostname string `json:"hostname"`
}
if err := json.Unmarshal(data, &auth); err != nil {
t.Fatal(err)
}
displayName := auth.WorkerName
if displayName == "" {
displayName = auth.Worker
}
if displayName == "" {
displayName = auth.Hostname
}
if displayName != "forged-worker-1" {
t.Fatalf("expected forged worker name, got %q", displayName)
}
}
func TestShortAgentID(t *testing.T) {
if shortAgentID("abcdef12-3456") != "abcdef12" {
t.Fatalf("expected 8-char prefix")
}
if shortAgentID("ab") != "ab" {
t.Fatalf("expected short id preserved")
}
if shortAgentID("") != "agent" {
t.Fatalf("expected fallback agent label")
}
}
func TestAgentDisplayNameFallback(t *testing.T) {
name := agentDisplayName("", "", "", "12345678-abcd")
if name != "12345678" {
t.Fatalf("expected id prefix, got %q", name)
}
}