Skip to content

Commit 9ac2bc7

Browse files
committed
fix: add guard for undefined subject
1 parent b604c6d commit 9ac2bc7

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

ucan/proof_chain.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ucanlib
22

33
import (
44
"context"
5+
"fmt"
56
"iter"
67
"slices"
78

@@ -75,6 +76,9 @@ func NewDelegationMatcher(listDelegations DelegationListerFunc) DelegationMatche
7576
// in strict sequence where the aud of the previous Delegation matches the iss
7677
// of the next Delegation.
7778
func ProofChain(ctx context.Context, matchDelegations DelegationMatcherFunc, aud did.DID, cmd ucan.Command, sub did.DID) ([]ucan.Delegation, []cid.Cid, error) {
79+
if !sub.Defined() {
80+
return nil, nil, fmt.Errorf("missing proof chain subject")
81+
}
7882
proofs, links, err := proofChain(ctx, matchDelegations, aud, cmd, sub)
7983
if err != nil {
8084
return nil, nil, err

ucan/proof_chain_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ func TestProofChain_UnrelatedCommandIgnored(t *testing.T) {
180180
require.Empty(t, links)
181181
}
182182

183+
func TestProofChain_MissingSubject(t *testing.T) {
184+
alice := testutil.Alice
185+
cmd := testutil.Must(command.Parse("/test/do"))(t)
186+
187+
matcher := ucanlib.NewDelegationMatcher((&memLister{}).List)
188+
proofs, links, err := ucanlib.ProofChain(t.Context(), matcher, alice.DID(), cmd, did.Undef)
189+
require.Error(t, err)
190+
require.Contains(t, err.Error(), "subject")
191+
require.Nil(t, proofs)
192+
require.Nil(t, links)
193+
}
194+
183195
func TestProofChain_FinderError(t *testing.T) {
184196
space := testutil.RandomSigner(t)
185197
alice := testutil.Alice

0 commit comments

Comments
 (0)