feat(19.7-01): in-process dispatch marker and compiled handler lookup
- bouncer.Dispatch, WithDispatch, Dispatched: context-only pre-resolved
principal marker honoured by Registry.Middleware for listed guard names
- cabana.ResolveBackend honours a backend-kind marker; additive
ResolveBackendToken, ScopeLimitFor and BackendPrincipal resolvers
- surf.Router.Handler and compileHandlers: one compiled chain per route,
shared by BuildRouter validation and compile
- smoke tests TestDispatchSmoke, TestDispatchedSmoke, TestDispatchMarkerSmoke
- READMEs and docs/services/{authentication,routing}.md updated
This commit is contained in:
40
modules/bouncer/dispatch_smoke_test.go
Normal file
40
modules/bouncer/dispatch_smoke_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package bouncer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestDispatchedSmoke covers the reader of the in-process dispatch marker
|
||||
// (phase 19.7 D-17): only a marker with a principal that lists the exact guard
|
||||
// name is honoured.
|
||||
func TestDispatchedSmoke(t *testing.T) {
|
||||
if _, ok := Dispatched(context.Background(), "api_token"); ok {
|
||||
t.Fatal("plain context reports a dispatch")
|
||||
}
|
||||
if _, ok := Dispatched(nil, "api_token"); ok {
|
||||
t.Fatal("nil context reports a dispatch")
|
||||
}
|
||||
noPrincipal := WithDispatch(context.Background(), &Dispatch{Guards: []string{"api_token"}})
|
||||
if _, ok := Dispatched(noPrincipal, "api_token"); ok {
|
||||
t.Fatal("marker without a principal reports a dispatch")
|
||||
}
|
||||
marker := &Dispatch{Guards: []string{"api_token"}, Principal: &Principal{ID: 42}, Credential: "cred"}
|
||||
ctx := WithDispatch(context.Background(), marker)
|
||||
if _, ok := Dispatched(ctx, "backend"); ok {
|
||||
t.Fatal("unlisted guard reports a dispatch")
|
||||
}
|
||||
if _, ok := Dispatched(ctx, ""); ok {
|
||||
t.Fatal("empty guard name reports a dispatch")
|
||||
}
|
||||
if _, ok := Dispatched(ctx, "api_token*"); ok {
|
||||
t.Fatal("wildcard guard name reports a dispatch")
|
||||
}
|
||||
got, ok := Dispatched(ctx, "api_token")
|
||||
if !ok || got != marker || got.Principal.ID != 42 || got.Credential != "cred" {
|
||||
t.Fatalf("Dispatched = %+v, %v", got, ok)
|
||||
}
|
||||
if ctx := WithDispatch(nil, marker); ctx == nil {
|
||||
t.Fatal("WithDispatch(nil) returned nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user