-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispatch_test.go
More file actions
717 lines (653 loc) · 21 KB
/
Copy pathdispatch_test.go
File metadata and controls
717 lines (653 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
package codemode
import (
"context"
"errors"
"math"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/meigma/codemode/authz"
authzmocks "github.com/meigma/codemode/authz/mocks"
"github.com/meigma/codemode/internal/binding"
"github.com/meigma/codemode/internal/catalog"
"github.com/meigma/codemode/internal/execution"
"github.com/meigma/codemode/internal/worker"
)
// dispatchInput is the representative dispatcher test input.
type dispatchInput struct {
// Value is one required capability argument.
Value string `json:"value"`
}
// dispatchOutput is the representative dispatcher test output.
type dispatchOutput struct {
// Value is one handler result field.
Value string `json:"value"`
}
// widenedDispatchInput is the eight-form dispatcher test input.
type widenedDispatchInput struct {
// Org is the required string argument.
Org string `json:"org"`
// Count is the required signed integer argument.
Count int64 `json:"count"`
// Active is the required Boolean argument.
Active bool `json:"active"`
// Score is the required finite floating-point argument.
Score float64 `json:"score"`
// Label is the optional string argument.
Label *string `json:"label,omitempty"`
// Limit is the optional signed integer argument.
Limit *int64 `json:"limit,omitempty"`
// Enabled is the optional Boolean argument.
Enabled *bool `json:"enabled"`
// Weight is the optional finite floating-point argument.
Weight *float64 `json:"weight,omitempty"`
}
// dispatchOutcome carries one asynchronous dispatcher result.
type dispatchOutcome struct {
// value is the converted native result.
value any
// err is the classified dispatcher failure.
err error
}
// TestDispatchBindsAuthorizesThenInvokes proves parent re-binding precedes policy and handlers.
func TestDispatchBindsAuthorizesThenInvokes(t *testing.T) {
authorizer := authzmocks.NewMockAuthorizer(t)
events := make([]string, 0, 2)
label := "beta"
limit := int64(25)
enabled := true
weight := 2.5
canonical := map[string]any{
"org": "meigma",
"count": int64(3),
"active": true,
"score": 1.5,
"label": "beta",
"limit": int64(25),
"enabled": true,
"weight": 2.5,
}
authorizer.EXPECT().Authorize(mock.Anything, mock.MatchedBy(func(input authz.AuthorizationInput) bool {
return input.Subject.ID == "subject-1" &&
input.CapabilityID == "cap.lookup" &&
input.CapabilityName == "records.lookup" &&
assert.ObjectsAreEqual(canonical, input.Arguments)
})).Run(func(context.Context, authz.AuthorizationInput) {
events = append(events, "authorize")
}).Return(nil).Once()
subject := newWidenedDispatchSubject(
t,
authorizer,
func(_ context.Context, _ authz.Subject, input any) (any, error) {
events = append(events, "handler")
typed, ok := input.(widenedDispatchInput)
if !ok {
return nil, catalog.ErrInputTypeMismatch
}
assert.Equal(t, widenedDispatchInput{
Org: "meigma",
Count: 3,
Active: true,
Score: 1.5,
Label: &label,
Limit: &limit,
Enabled: &enabled,
Weight: &weight,
}, typed)
return dispatchOutput{Value: typed.Org}, nil
},
)
result, err := subject.dispatch.dispatch(
t.Context(),
authz.Subject{ID: "subject-1"},
"cap.lookup",
map[string]any{
"org": "meigma",
"count": int64(3),
"active": true,
"score": 1.5,
"label": "beta",
"limit": int64(25),
"enabled": true,
"weight": 2.5,
}, 64*1024)
require.NoError(t, err)
assert.Equal(t, []string{"authorize", "handler"}, events)
assert.Equal(t, map[string]any{"value": "meigma"}, result)
}
// TestDispatchTranslatesEveryBindValueFailureInternally proves decoded maps never reach policy.
func TestDispatchTranslatesEveryBindValueFailureInternally(t *testing.T) {
tests := []struct {
// name identifies the rejected decoded map.
name string
// arguments is the decoded child map presented to dispatch.
arguments map[string]any
// widened selects the eight-form input contract.
widened bool
}{
{name: "missing required", arguments: map[string]any{}},
{name: "unknown", arguments: map[string]any{"value": "alpha", "other": "extra"}},
{name: "mistyped required string", arguments: map[string]any{"value": int64(1)}},
{name: "widened missing required integer", widened: true, arguments: map[string]any{
"org": "meigma",
"active": true,
"score": 1.5,
}},
{name: "widened float where int is required", widened: true, arguments: map[string]any{
"org": "meigma",
"count": float64(3),
"active": true,
"score": 1.5,
}},
{name: "widened NaN float", widened: true, arguments: map[string]any{
"org": "meigma",
"count": int64(3),
"active": true,
"score": math.NaN(),
}},
{name: "widened infinity float", widened: true, arguments: map[string]any{
"org": "meigma",
"count": int64(3),
"active": true,
"score": math.Inf(1),
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
authorizer := authzmocks.NewMockAuthorizer(t)
var handlerCalls atomic.Int64
invoke := func(context.Context, authz.Subject, any) (any, error) {
handlerCalls.Add(1)
return dispatchOutput{}, nil
}
var subject *dispatchSubject
if tt.widened {
subject = newWidenedDispatchSubject(t, authorizer, invoke)
} else {
subject = newDispatchSubject(t, authorizer, invoke)
}
_, err := subject.dispatch.dispatch(
t.Context(),
authz.Subject{ID: "subject-1"},
"cap.lookup",
tt.arguments, 64*1024)
require.ErrorIs(t, err, worker.ErrProtocol)
require.NotErrorIs(t, err, execution.ErrInvalidArguments)
assert.Zero(t, handlerCalls.Load())
})
}
}
// TestDispatchRejectsUnknownIDsBeforeAuthorization proves disabled and unknown IDs stay internal.
func TestDispatchRejectsUnknownIDsBeforeAuthorization(t *testing.T) {
authorizer := authzmocks.NewMockAuthorizer(t)
var handlerCalls atomic.Int64
subject := newDispatchSubject(t, authorizer, func(context.Context, authz.Subject, any) (any, error) {
handlerCalls.Add(1)
return dispatchOutput{}, nil
})
_, err := subject.dispatch.dispatch(
t.Context(),
authz.Subject{ID: "subject-1"},
"cap.missing",
map[string]any{"value": "alpha"}, 64*1024)
require.ErrorIs(t, err, worker.ErrProtocol)
assert.Zero(t, handlerCalls.Load())
}
// TestDispatchClassifiesPolicyAndHandlerFailures proves policy and handler failures map to native classifications.
func TestDispatchClassifiesPolicyAndHandlerFailures(t *testing.T) {
tests := []struct {
// name identifies the classified failure.
name string
// configure installs one generated mock expectation.
configure func(*authzmocks.MockAuthorizer)
// invoke is the native handler under test.
invoke catalog.Invoker
// target is the expected dispatcher classification.
target error
}{
{
name: "recognized denial",
configure: func(authorizer *authzmocks.MockAuthorizer) {
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Return(authz.ErrDenied).Once()
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
return dispatchOutput{}, nil
},
target: execution.ErrPermissionDenied,
},
{
name: "policy error",
configure: func(authorizer *authzmocks.MockAuthorizer) {
authorizer.EXPECT().
Authorize(mock.Anything, mock.Anything).
Return(errors.New("trusted policy detail")).
Once()
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
return dispatchOutput{}, nil
},
target: execution.ErrPolicyFailure,
},
{
name: "policy panic",
configure: func(authorizer *authzmocks.MockAuthorizer) {
authorizer.EXPECT().
Authorize(mock.Anything, mock.Anything).
Run(func(context.Context, authz.AuthorizationInput) {
panic("trusted panic detail")
}).
Return(nil).
Once()
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
return dispatchOutput{}, nil
},
target: execution.ErrPolicyFailure,
},
{
name: "handler error",
configure: func(authorizer *authzmocks.MockAuthorizer) {
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Return(nil).Once()
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
return dispatchOutput{}, errors.New("trusted handler detail")
},
target: execution.ErrCapabilityFailure,
},
{
name: "handler panic",
configure: func(authorizer *authzmocks.MockAuthorizer) {
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Return(nil).Once()
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
panic("trusted handler panic")
},
target: execution.ErrInternal,
},
{
name: "input type mismatch",
configure: func(authorizer *authzmocks.MockAuthorizer) {
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Return(nil).Once()
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
return nil, catalog.ErrInputTypeMismatch
},
target: execution.ErrInternal,
},
{
name: "output type drift",
configure: func(authorizer *authzmocks.MockAuthorizer) {
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Return(nil).Once()
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
return struct {
// Name is an intentionally incompatible output field.
Name string
}{Name: "alpha"}, nil
},
target: execution.ErrCapabilityFailure,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
authorizer := authzmocks.NewMockAuthorizer(t)
tt.configure(authorizer)
subject := newDispatchSubject(t, authorizer, tt.invoke)
_, err := subject.dispatch.dispatch(
t.Context(),
authz.Subject{ID: "subject-1"},
"cap.lookup",
map[string]any{"value": "alpha"}, 64*1024)
require.ErrorIs(t, err, tt.target)
})
}
}
// TestDispatchReturnsFreshCanonicalMaps proves decoded child maps never become authorization input.
func TestDispatchReturnsFreshCanonicalMaps(t *testing.T) {
authorizer := authzmocks.NewMockAuthorizer(t)
decoded := map[string]any{
"org": "meigma",
"count": int64(3),
"active": true,
"score": 1.5,
"limit": int64(25),
}
var authorized map[string]any
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Run(
func(_ context.Context, input authz.AuthorizationInput) {
authorized = input.Arguments
input.Arguments["org"] = "mutated-policy"
decoded["org"] = "mutated-decoded"
},
).Return(nil).Once()
var received widenedDispatchInput
subject := newWidenedDispatchSubject(
t,
authorizer,
func(_ context.Context, _ authz.Subject, input any) (any, error) {
typed, ok := input.(widenedDispatchInput)
if !ok {
return nil, catalog.ErrInputTypeMismatch
}
received = typed
return dispatchOutput{Value: typed.Org}, nil
},
)
result, err := subject.dispatch.dispatch(
t.Context(),
authz.Subject{ID: "subject-1"},
"cap.lookup",
decoded, 64*1024)
require.NoError(t, err)
require.NotNil(t, authorized)
assert.Equal(t, "mutated-policy", authorized["org"])
assert.Equal(t, "mutated-decoded", decoded["org"])
assert.Equal(t, "meigma", received.Org)
assert.Equal(t, int64(3), received.Count)
require.NotNil(t, received.Limit)
assert.Equal(t, int64(25), *received.Limit)
assert.Nil(t, received.Label)
assert.Equal(t, map[string]any{"value": "meigma"}, result)
}
// TestDispatchCancellationAfterAllowPreventsInvoke proves a stale allow cannot reach the handler.
func TestDispatchCancellationAfterAllowPreventsInvoke(t *testing.T) {
tests := []struct {
// name identifies the cancellation source.
name string
// newContext creates the dispatch context, cleanup, and cancellation trigger.
newContext func(*testing.T) (context.Context, context.CancelFunc, func())
// targets are the required dispatcher error classifications.
targets []error
}{
{
name: "request cancellation",
newContext: func(t *testing.T) (context.Context, context.CancelFunc, func()) {
ctx, cancel := context.WithCancel(t.Context())
return ctx, cancel, cancel
},
targets: []error{context.Canceled},
},
{
name: "elapsed deadline",
newContext: func(t *testing.T) (context.Context, context.CancelFunc, func()) {
ctx, cancel := context.WithTimeout(t.Context(), 20*time.Millisecond)
return ctx, cancel, func() {
<-ctx.Done()
}
},
targets: []error{execution.ErrResourceLimit, context.DeadlineExceeded},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, cancel, trigger := tt.newContext(t)
defer cancel()
authorizationStarted := make(chan struct{})
releaseAuthorization := make(chan struct{})
authorizer := authzmocks.NewMockAuthorizer(t)
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Run(
func(context.Context, authz.AuthorizationInput) {
close(authorizationStarted)
<-releaseAuthorization
},
).Return(nil).Once()
var handlerCalls atomic.Int64
subject := newDispatchSubject(t, authorizer, func(context.Context, authz.Subject, any) (any, error) {
handlerCalls.Add(1)
return dispatchOutput{}, nil
})
result := make(chan dispatchOutcome, 1)
go func() {
value, err := subject.dispatch.dispatch(
ctx,
authz.Subject{ID: "subject-1"},
"cap.lookup",
map[string]any{"value": "alpha"}, 64*1024)
result <- dispatchOutcome{value: value, err: err}
}()
<-authorizationStarted
trigger()
close(releaseAuthorization)
outcome := <-result
assert.Nil(t, outcome.value)
for _, target := range tt.targets {
require.ErrorIs(t, outcome.err, target)
}
assert.Zero(t, handlerCalls.Load())
})
}
}
// TestDispatchClassifiesParentOutputLimits proves converted handler values are bounded before transport.
func TestDispatchClassifiesParentOutputLimits(t *testing.T) {
tests := []struct {
// name identifies the exhausted parent output budget.
name string
// configure makes one output budget reject the representative result.
configure func(*dispatcher)
}{
{
name: "depth",
configure: func(dispatch *dispatcher) {
dispatch.maxValueDepth = 1
},
},
{
name: "materialization",
configure: func(dispatch *dispatcher) {
dispatch.maxValueBytes = 1
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
authorizer := authzmocks.NewMockAuthorizer(t)
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Return(nil).Once()
subject := newDispatchSubject(
t,
authorizer,
func(context.Context, authz.Subject, any) (any, error) {
return dispatchOutput{Value: "alpha"}, nil
},
)
tt.configure(subject.dispatch)
_, err := subject.dispatch.dispatch(
t.Context(),
authz.Subject{ID: "subject-1"},
"cap.lookup",
map[string]any{"value": "alpha"}, 64*1024)
require.ErrorIs(t, err, execution.ErrResourceLimit)
})
}
}
// TestDispatchCancellationDuringHandlerReturnsPromptly proves late trusted Go work cannot hold dispatch.
func TestDispatchCancellationDuringHandlerReturnsPromptly(t *testing.T) {
authorizer := authzmocks.NewMockAuthorizer(t)
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Return(nil).Once()
handlerStarted := make(chan struct{})
releaseHandler := make(chan struct{})
subject := newDispatchSubject(
t,
authorizer,
func(context.Context, authz.Subject, any) (any, error) {
close(handlerStarted)
<-releaseHandler
return dispatchOutput{Value: "late"}, nil
},
)
ctx, cancel := context.WithCancel(t.Context())
result := make(chan dispatchOutcome, 1)
go func() {
value, err := subject.dispatch.dispatch(
ctx,
authz.Subject{ID: "subject-1"},
"cap.lookup",
map[string]any{"value": "alpha"}, 64*1024)
result <- dispatchOutcome{value: value, err: err}
}()
<-handlerStarted
cancel()
select {
case outcome := <-result:
assert.Nil(t, outcome.value)
require.ErrorIs(t, outcome.err, context.Canceled)
case <-time.After(time.Second):
t.Fatal("dispatch waited for a canceled handler")
}
close(releaseHandler)
}
// dispatchSubject carries one catalog-backed dispatcher under test.
type dispatchSubject struct {
// dispatch is the unexported native-call owner.
dispatch *dispatcher
}
// newDispatchSubject builds one catalog and dispatcher around a function-fake handler.
func newDispatchSubject(t *testing.T, authorizer authz.Authorizer, invoke catalog.Invoker) *dispatchSubject {
t.Helper()
plan, err := binding.CompileFor[dispatchInput, dispatchOutput]()
require.NoError(t, err)
capabilityCatalog, err := catalog.Build([]catalog.Registration{{
ID: "cap.lookup",
Name: "records.lookup",
Summary: "Return one record.",
Description: "Returns the supplied record value.",
Plan: plan,
Invoke: invoke,
}}, catalog.Options{
MaxSearchQueryBytes: 256,
MaxSearchResults: 20,
})
require.NoError(t, err)
return &dispatchSubject{
dispatch: newDispatcher(capabilityCatalog, authorizer, 16, 64*1024),
}
}
// newWidenedDispatchSubject builds a dispatcher around the eight-form input contract.
func newWidenedDispatchSubject(t *testing.T, authorizer authz.Authorizer, invoke catalog.Invoker) *dispatchSubject {
t.Helper()
plan, err := binding.CompileFor[widenedDispatchInput, dispatchOutput]()
require.NoError(t, err)
capabilityCatalog, err := catalog.Build([]catalog.Registration{{
ID: "cap.lookup",
Name: "records.lookup",
Summary: "Return one record.",
Description: "Returns the supplied record value.",
Plan: plan,
Invoke: invoke,
}}, catalog.Options{
MaxSearchQueryBytes: 256,
MaxSearchResults: 20,
})
require.NoError(t, err)
return &dispatchSubject{
dispatch: newDispatcher(capabilityCatalog, authorizer, 16, 64*1024),
}
}
// overflowDispatchOutput covers unsigned values above MaxInt64.
type overflowDispatchOutput struct {
// Count is an unsigned 64-bit integer.
Count uint64 `json:"count"`
}
// nanDispatchOutput covers non-finite floating-point results.
type nanDispatchOutput struct {
// Score is a finite floating-point field.
Score float64 `json:"score"`
}
// TestDispatchClassifiesInvalidCompositeOutputs proves invalid runtime values stay capability failures.
func TestDispatchClassifiesInvalidCompositeOutputs(t *testing.T) {
tests := []struct {
// name identifies the invalid handler output.
name string
// plan compiles the handler contract.
plan func(*testing.T) *binding.Plan
// invoke returns an invalid registered output.
invoke catalog.Invoker
}{
{
name: "unsigned overflow",
plan: func(t *testing.T) *binding.Plan {
t.Helper()
plan, err := binding.CompileFor[dispatchInput, overflowDispatchOutput]()
require.NoError(t, err)
return plan
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
return overflowDispatchOutput{Count: uint64(1) << 63}, nil
},
},
{
name: "NaN",
plan: func(t *testing.T) *binding.Plan {
t.Helper()
plan, err := binding.CompileFor[dispatchInput, nanDispatchOutput]()
require.NoError(t, err)
return plan
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
return nanDispatchOutput{Score: math.NaN()}, nil
},
},
{
name: "infinity",
plan: func(t *testing.T) *binding.Plan {
t.Helper()
plan, err := binding.CompileFor[dispatchInput, nanDispatchOutput]()
require.NoError(t, err)
return plan
},
invoke: func(context.Context, authz.Subject, any) (any, error) {
return nanDispatchOutput{Score: math.Inf(1)}, nil
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
authorizer := authzmocks.NewMockAuthorizer(t)
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Return(nil).Once()
capabilityCatalog, err := catalog.Build([]catalog.Registration{{
ID: "cap.lookup",
Name: "records.lookup",
Summary: "Return one record.",
Description: "Returns the supplied record value.",
Plan: tt.plan(t),
Invoke: tt.invoke,
}}, catalog.Options{
MaxSearchQueryBytes: 256,
MaxSearchResults: 20,
})
require.NoError(t, err)
subject := &dispatchSubject{dispatch: newDispatcher(capabilityCatalog, authorizer, 16, 64*1024)}
_, err = subject.dispatch.dispatch(
t.Context(),
authz.Subject{ID: "subject-1"},
"cap.lookup",
map[string]any{"value": "alpha"},
64*1024,
)
require.ErrorIs(t, err, execution.ErrCapabilityFailure)
require.NotErrorIs(t, err, execution.ErrResourceLimit)
})
}
}
// TestDispatchMapsValueLimitToResourceFailure proves remaining-byte conversion limits are resource failures.
func TestDispatchMapsValueLimitToResourceFailure(t *testing.T) {
authorizer := authzmocks.NewMockAuthorizer(t)
authorizer.EXPECT().Authorize(mock.Anything, mock.Anything).Return(nil).Once()
subject := newDispatchSubject(
t,
authorizer,
func(context.Context, authz.Subject, any) (any, error) {
return dispatchOutput{Value: "alpha"}, nil
},
)
_, err := subject.dispatch.dispatch(
t.Context(),
authz.Subject{ID: "subject-1"},
"cap.lookup",
map[string]any{"value": "alpha"},
1,
)
require.ErrorIs(t, err, execution.ErrResourceLimit)
}