Closes six review findings against .4.6 (PR #775): - daemon.StateStoreGrantIssuer + staterpc.TaskGrants: containers get a per-task credential authorized only for their own Update/Transition/ InsertEvent, never the daemon's administrative token. Issued before Acquire, revoked on Release; fails closed if no issuer is wired. - StreamCaptures/StreamUndispatchedCaptures: new streaming RPCs so a batch of large capture bodies can't exceed gRPC's 4MiB unary cap. The original unary RPCs are kept, unmodified (deprecated) rather than reshaped, so buf breaking stays green for an in-flight rolling deploy. - Update rejects a nil Task with InvalidArgument instead of panicking in the store layer. - RequireHostGateway only forces on for embedded NATS, so an externally reachable NATS/State Store no longer requires a local Docker bridge. - Client-side token resolution now matches the server's (target_token, then STATE_STORE_TOKEN secret/env). - task dev now runs archie-state-store (dev:state-store) alongside archied/archie-gateway/vite; deployments/dev.toml points them at it.
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package staterpc
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/binding"
|
|
"github.com/samcharles93/archie-core/internal/store"
|
|
)
|
|
|
|
func TestCaptureListsExceedUnaryMessageLimit(t *testing.T) {
|
|
local := store.OpenTest(t)
|
|
body := strings.Repeat("x", 256<<10)
|
|
for range 20 {
|
|
if _, err := local.InsertCapture(t.Context(), store.CapturedEvent{Source: "large", Body: body, Authenticated: true}, 0, 0); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
// ListUndispatchedCaptures only returns sources with an armed binding
|
|
// (internal/store/bindings.go), so "large" needs one taken through the
|
|
// public draft -> pending_approval -> armed lifecycle.
|
|
id, err := local.InsertBinding(t.Context(), binding.Binding{
|
|
Name: "large binding", Matcher: binding.Matcher{Source: "large"},
|
|
MappingID: 1, Workflow: "implement", Secret: "0123456789abcdef0123456789abcdef",
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := local.UpdateBinding(t.Context(), binding.Binding{
|
|
ID: id, Name: "large binding", Matcher: binding.Matcher{Source: "large"},
|
|
MappingID: 1, Workflow: "implement", Secret: "0123456789abcdef0123456789abcdef",
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := local.ApproveBinding(t.Context(), id); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
remote := remoteContract(t, local)
|
|
for _, undispatched := range []bool{false, true} {
|
|
var captures []store.CapturedEvent
|
|
var err error
|
|
if undispatched {
|
|
captures, err = remote.ListUndispatchedCaptures(t.Context(), []string{"large"}, 20)
|
|
} else {
|
|
captures, err = remote.ListCaptures(t.Context(), 20)
|
|
}
|
|
if err != nil {
|
|
t.Errorf("undispatched=%v: %v", undispatched, err)
|
|
continue
|
|
}
|
|
if len(captures) != 20 {
|
|
t.Fatalf("undispatched=%v: got %d captures, want 20", undispatched, len(captures))
|
|
}
|
|
for _, capture := range captures {
|
|
if capture.Body != body {
|
|
t.Fatal("capture body truncated")
|
|
}
|
|
}
|
|
}
|
|
}
|