Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions internal/node/labels_gate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,17 @@ func TestLabelGateTellsUnreachableFromDenied(t *testing.T) {
// authorizerFactLimitRules are mesh policy rules that derive more facts
// from role(node) than the authorizer admits, so any check that adds them
// stops at datalog.ErrWorldRunLimitMaxFacts before it reaches a verdict.
func authorizerFactLimitRules(t *testing.T) []biscuit.Rule {
t.Helper()
texts := make([]string, 0, 1100)
// Each is limit_fact_<i>(true) <- role("mesh:role:node"), built directly:
// the parser builds a new grammar for every rule, which for 1100 rules
// takes most of a test's deadline under the race detector.
func authorizerFactLimitRules() []biscuit.Rule {
role := biscuit.Predicate{Name: "role", IDs: []biscuit.Term{biscuit.String(api.RoleNode)}}
rules := make([]biscuit.Rule, 0, 1100)
for i := range 1100 {
texts = append(texts, fmt.Sprintf("limit_fact_%d(true) <- role(%q)", i, api.RoleNode))
}
rules, err := api.ParseDatalogRules(texts)
if err != nil {
t.Fatalf("ParseDatalogRules: %v", err)
rules = append(rules, biscuit.Rule{
Head: biscuit.Predicate{Name: fmt.Sprintf("limit_fact_%d", i), IDs: []biscuit.Term{biscuit.Bool(true)}},
Body: []biscuit.Predicate{role},
})
}
return rules
}
Expand Down Expand Up @@ -398,7 +400,7 @@ func TestLabelGateTellsAuthorizerLimitFromDenied(t *testing.T) {
t.Errorf("timeout: got %d %q, want 504", status, text)
}

full := &AgentMeshNode{trustedKeys: trusted, BiscuitTimeout: 500 * time.Millisecond, MeshPolicyRules: authorizerFactLimitRules(t)}
full := &AgentMeshNode{trustedKeys: trusted, BiscuitTimeout: 500 * time.Millisecond, MeshPolicyRules: authorizerFactLimitRules()}
err = full.checkProvider(granted, providerPeer, nil, "mcp://calc")
if !errors.Is(err, datalog.ErrWorldRunLimitMaxFacts) || errors.Is(err, ErrProviderNotGranted) {
t.Fatalf("checkProvider over the facts limit = %v, want an error wrapping %v and not %v", err, datalog.ErrWorldRunLimitMaxFacts, ErrProviderNotGranted)
Expand Down
2 changes: 1 addition & 1 deletion internal/node/mcp_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func TestCallMCPTool_ProviderNotGrantedIsNotRetried(t *testing.T) {
// grant, and it is not retried either: the same credential and policy
// reach the limit again.
nodeA.MeshPolicyMu.Lock()
nodeA.MeshPolicyRules = authorizerFactLimitRules(t)
nodeA.MeshPolicyRules = authorizerFactLimitRules()
nodeA.MeshPolicyMu.Unlock()
_, err = nodeA.CallMCPTool(ctx, nodeB.Host.ID(), "mcp://code-reviewer/review_pr", map[string]any{}, nil)
if !errors.Is(err, datalog.ErrWorldRunLimitMaxFacts) || errors.Is(err, ErrProviderNotGranted) {
Expand Down
Loading