flex-auth/internal/callerauth/openrouter_test.go
tegwick 41f359f2dc
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 3s
Build and Publish Container Image / build-and-push (push) Successful in 1m8s
Resolve OpenRouter native contract and promote secrets-engine PDP
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a09cbb-87c6-7900-a145-4ce53ba9f1a6
2026-09-14 00:54:56 +02:00

43 lines
1.7 KiB
Go

package callerauth
import (
"context"
"errors"
"testing"
)
// IR-WP-0004 / WARDEN-WP-0039: a caller binding is representation,
// not delegated authority over another system's credentials.
func TestOpenRouterNativeCallerBoundary(t *testing.T) {
bindings := map[string]string{
"ops-warden": "system:serviceaccount:ops-warden:ops-warden",
"secrets-engine": "system:serviceaccount:secrets-engine:secrets-engine",
}
for _, tc := range []struct {
name, caller string
systems []string
denied bool
}{
{"native lifecycle caller", bindings["secrets-engine"], []string{"secrets-engine"}, false},
{"warden own system", bindings["ops-warden"], []string{"ops-warden"}, false},
{"warden cannot represent custody owner", bindings["ops-warden"], []string{"railiance-platform"}, true},
{"warden cannot impersonate native engine", bindings["ops-warden"], []string{"secrets-engine"}, true},
{"radar is recipient not lifecycle caller", "system:serviceaccount:intelligence-radar:intelligence-radar", []string{"secrets-engine"}, true},
{"native caller cannot represent custody owner", bindings["secrets-engine"], []string{"railiance-platform"}, true},
{"batch must bind every owner", bindings["ops-warden"], []string{"ops-warden", "railiance-platform"}, true},
} {
t.Run(tc.name, func(t *testing.T) {
auth, err := New(ModeEnforce, fakeReviewer{identity: Identity{Username: tc.caller, Audiences: []string{"flex-auth"}}}, "flex-auth", bindings, nil)
if err != nil {
t.Fatal(err)
}
err = auth.Authorize(context.Background(), "Bearer synthetic-caller", tc.systems)
if tc.denied && !errors.Is(err, ErrForbidden) {
t.Fatalf("want forbidden, got %v", err)
}
if !tc.denied && err != nil {
t.Fatal(err)
}
})
}
}