access-engine/internal/decision/attribute_context_test.go
tegwick f758381cea
All checks were successful
CI Smoke / host-smoke (push) Successful in 1s
CI Smoke / container-smoke (push) Successful in 6s
Build and Publish Container Image / build-and-push (push) Successful in 1m23s
FLEX-WP-0036: Go module is github.com/netkingdom/access-engine; T02 consumer inventory
- module path renamed (no external importers); golangci local-prefixes
- ACCESS_ENGINE_RUN_TOPAZ_INTEGRATION replaces FLEX_AUTH_RUN_TOPAZ_INTEGRATION
- README title and identity paragraph reflect the landed renames
- docs/runtime-rename-inventory.md: per-consumer references by kind and order
- chart name, image package and /opt paths deliberately left for T05

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: opus
Assistant-Process: 735967@bnt-lap001
Assistant-Session: 5971967f-77f8-4ced-9e02-c6ef67040ffc
2026-10-10 15:29:00 +02:00

87 lines
2.9 KiB
Go

package decision_test
import (
"context"
"path/filepath"
"testing"
"time"
"github.com/netkingdom/access-engine/internal/decision"
"github.com/netkingdom/access-engine/internal/policy"
"github.com/netkingdom/access-engine/internal/registry"
"github.com/netkingdom/access-engine/pkg/api"
)
func TestAttributeContextCarriedWithoutViewHash(t *testing.T) {
root := filepath.Join("..", "..")
pkg, err := policy.LoadAndValidateFile(context.Background(), filepath.Join(root, "examples", "informed-decision-sitting", "policy.md"))
if err != nil {
t.Fatalf("LoadAndValidateFile: %v", err)
}
store, err := registry.LoadFile(filepath.Join(root, "examples", "informed-decision-sitting", "registry.json"))
if err != nil {
t.Fatal(err)
}
engine, err := decision.NewEngine(store, pkg)
if err != nil {
t.Fatal(err)
}
request := api.CheckRequest{
ID: "attribute-context",
Tenant: "tenant:platform",
Subject: api.SubjectRef{
ID: "synthetic-attribute-reviewer",
Type: "human",
Tenant: "tenant:platform",
Attributes: map[string]any{
"principal_type_source": "authentication-derived",
"tenant_source": "registration-supplied",
"groups": []any{"net-kingdom-admins"},
"assurance": map[string]any{
"level": "aal2", "mfa": true, "source": "key-cape",
"methods": []any{"pwd", "otp"}, "at": time.Now().Unix(),
},
},
},
Action: "accept",
Resource: api.ResourceRef{
ID: "memo:intake-new-memo", Type: "decision-memo",
System: "informed-decision", Tenant: "tenant:platform",
},
Context: map[string]any{
"review_group": "net-kingdom-admins",
"memo_class": "credential-lane",
"intake_submitter": "state-hub",
"approval_requester": "informed-decision",
"approval_human_control": true,
"memo_version": 1,
"approval_id": "706f4205-aaa7-44f6-be30-d0f57664d69c",
"approval_binding_digest": "sha256:c8a1a9c8fb22616e3aacfb877ba7974feb5eedaed491f856a6c90719c502ebe4",
},
PolicyVersion: "v8",
}
got, err := engine.Check(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if got.Effect != api.DecisionEffectDeny || got.Reason != "unknown_class" {
t.Fatalf("effect = %s %s; shipped sets must refuse the class", got.Effect, got.Reason)
}
if got.Binding == nil {
t.Fatal("binding missing")
}
for _, key := range []string{
"review_group", "memo_class", "intake_submitter", "approval_requester",
"approval_human_control", "memo_version", "approval_id", "approval_binding_digest",
} {
if _, ok := got.Binding.Context[key]; !ok {
t.Fatalf("binding context missing %s", key)
}
}
if _, ok := got.Binding.Context["view_hash"]; ok {
t.Fatal("view_hash entered the decision binding")
}
if got.Binding.Context["approval_requester"] != "informed-decision" || got.Binding.Context["approval_human_control"] != true {
t.Fatalf("binding context = %#v", got.Binding.Context)
}
}