mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-12 18:03:45 +00:00
feat: add credential-safe multiplayer observability
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package observability
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestEncodeCorrelatesStagesAndRedactsNestedCredentials(t *testing.T) {
|
||||
payload, err := Encode(Event{Event: "assignment_ready", QueueID: "queue-1", ProposalID: "proposal-1", MatchID: "match-1", ServerID: "server-1", Stage: "assignment-ready", OccurredAt: time.Unix(1000, 0), Fields: map[string]any{"auth_ticket": "do-not-log", "nested": map[string]any{"relay_ticket": "also-secret", "attempt": 2}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(payload, &decoded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, key := range []string{"queue_id", "proposal_id", "match_id", "server_id", "stage"} {
|
||||
if decoded[key] == nil {
|
||||
t.Fatalf("missing correlation field %q: %s", key, payload)
|
||||
}
|
||||
}
|
||||
if decoded["auth_ticket"] != "[REDACTED]" || decoded["nested"].(map[string]any)["relay_ticket"] != "[REDACTED]" {
|
||||
t.Fatalf("credential not redacted: %s", payload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeRejectsUnnamedEvents(t *testing.T) {
|
||||
if _, err := Encode(Event{}); err == nil {
|
||||
t.Fatal("unnamed event accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user