test(daemon): a task start parks transient when the policy chain is unavailable

This commit is contained in:
sam committed 2026-10-25 16:23:16 +11:00
1 parent cc7bc90ff3
commit e2aa573c6c
1 file changed
+24 -10
+24 -10
View File
@@ -20,12 +20,14 @@ import (
type identityStore struct {
storecontract.TaskStore
parked bool
class taskstate.ParkClass
}
func (*identityStore) Update(context.Context, *workflow.Task) error { return nil }
func (s *identityStore) ParkTask(context.Context, int64, string, string, taskstate.ParkClass, taskstate.Blocker) error {
func (s *identityStore) ParkTask(_ context.Context, _ int64, _, _ string, class taskstate.ParkClass, _ taskstate.Blocker) error {
s.parked = true
s.class = class
return nil
}
@@ -71,6 +73,13 @@ func (r runAllowed) Authorize(p access.Principal, _ access.Action, _ access.Reso
func (runAllowed) Reload(context.Context) error { return nil }
// unavailableChain is a chain that cannot be read: nothing is evaluated.
type unavailableChain struct{ runAllowed }
func (unavailableChain) Authorize(access.Principal, access.Action, access.Resource, access.Context) access.Decision {
return access.Unavailable()
}
type enablementOf workflowtask.WorkflowEnablement
func (e enablementOf) WorkflowEnablement(context.Context) (workflowtask.WorkflowEnablement, error) {
@@ -97,20 +106,22 @@ func TestWorkflowIdentity(t *testing.T) {
name string
yaml string
starter string
allowed runAllowed
allowed access.Authorizer
wantIdentity string
wantParked bool
wantClass taskstate.ParkClass
wantDenied []identity.IdentityID
disabled bool
}{
{"allowed dispatch runs as the workflow's identity", deploy, "", runAllowed{"root": true, "id-deployer": true}, "id-deployer", false, nil, false},
{"refused invocation is parked", deploy, "", runAllowed{"id-deployer": true}, "", true, []identity.IdentityID{"root"}, false},
{"refused execution is parked", deploy, "", runAllowed{"root": true}, "", true, []identity.IdentityID{"id-deployer"}, false},
{"called workflow runs as its own identity, not its caller's", callee, "id-deployer", runAllowed{"id-deployer": true, "id-bot": true}, "id-bot", false, nil, false},
{"caller refused the called workflow is parked", callee, "id-deployer", runAllowed{"id-bot": true}, "", true, []identity.IdentityID{"id-deployer"}, false},
{"no declared identity is refused", "id: deploy\n", "id-bot", runAllowed{"root": true, "id-bot": true}, "", true, nil, false},
{"unconfigured identity is parked", "id: deploy\nidentity: ghost\n", "", runAllowed{"root": true}, "", true, nil, false},
{"disabled workflow is parked", deploy, "id-bot", runAllowed{"id-bot": true, "id-deployer": true}, "", true, nil, true},
{"allowed dispatch runs as the workflow's identity", deploy, "", runAllowed{"root": true, "id-deployer": true}, "id-deployer", false, "", nil, false},
{"refused invocation is parked", deploy, "", runAllowed{"id-deployer": true}, "", true, taskstate.ParkNeedsHuman, []identity.IdentityID{"root"}, false},
{"refused execution is parked", deploy, "", runAllowed{"root": true}, "", true, taskstate.ParkNeedsHuman, []identity.IdentityID{"id-deployer"}, false},
{"a chain that cannot be read parks transient, not as a denial", deploy, "", unavailableChain{}, "", true, taskstate.ParkTransient, nil, false},
{"called workflow runs as its own identity, not its caller's", callee, "id-deployer", runAllowed{"id-deployer": true, "id-bot": true}, "id-bot", false, "", nil, false},
{"caller refused the called workflow is parked", callee, "id-deployer", runAllowed{"id-bot": true}, "", true, taskstate.ParkNeedsHuman, []identity.IdentityID{"id-deployer"}, false},
{"no declared identity is refused", "id: deploy\n", "id-bot", runAllowed{"root": true, "id-bot": true}, "", true, taskstate.ParkNeedsHuman, nil, false},
{"unconfigured identity is parked", "id: deploy\nidentity: ghost\n", "", runAllowed{"root": true}, "", true, taskstate.ParkNeedsHuman, nil, false},
{"disabled workflow is parked", deploy, "id-bot", runAllowed{"id-bot": true, "id-deployer": true}, "", true, taskstate.ParkNeedsHuman, nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -132,6 +143,9 @@ func TestWorkflowIdentity(t *testing.T) {
if ok == tt.wantParked || store.parked != tt.wantParked || (ok && task.Identity != tt.wantIdentity) {
t.Fatalf("ok %v parked %v identity %q, want parked %v identity %q", ok, store.parked, task.Identity, tt.wantParked, tt.wantIdentity)
}
if store.parked && store.class != tt.wantClass {
t.Fatalf("parked %q, want %q", store.class, tt.wantClass)
}
if !reflect.DeepEqual([]identity.IdentityID(denied), tt.wantDenied) {
t.Fatalf("denied %v, want %v", denied, tt.wantDenied)
}