flex-auth/internal/callerauth/openrouter_test.go
tegwick ca070df32d
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Build and Publish Container Image / build-and-push (push) Successful in 1m0s
Record authenticated caller in the decision envelope.
FLEX-WP-0023-T04: provenance.caller is additive (mode required;
principal/audience/not_after when a token was reviewed). TokenReview
keeps the JWT exp. request_digest is unchanged because the caller is
not binding material.

Assistant: grok
Assistant-Session: 01a09dc1-b21e-77e1-919e-fcad2f82b267
2026-09-14 04:44:07 +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)
}
})
}
}