Skip to content

Commit 69d3196

Browse files
author
Brandon Westcott
authored
Merge pull request #475 from quorumcontrol/bug/grafted-through-intermediary
handle DIDs in the resolved auth
2 parents b3c5904 + 3eec1e3 commit 69d3196

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

sdk/gossip/types/graftedownership.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,19 @@ func (gro *GraftedOwnership) resolveOwnersRecursively(ctx context.Context, graft
257257
owners = append(owners, auth)
258258
case []interface{}:
259259
for _, uncastAddr := range auth {
260-
if addr, ok := uncastAddr.(string); ok {
260+
switch addr := uncastAddr.(type) {
261+
case string:
261262
owners = append(owners, addr)
262-
} else {
263+
case *dag.Dag:
264+
newOwners, err := gro.handleDag(ctx, addr, seen)
265+
if err != nil {
266+
return nil, err
267+
}
268+
owners = append(owners, newOwners...)
269+
default:
263270
return nil, fmt.Errorf("unknown auth type for %+v: %T", uncastAddr, uncastAddr)
264271
}
272+
265273
}
266274
default:
267275
return nil, fmt.Errorf("unknown auth type for %+v: %T", auth, auth)
@@ -291,4 +299,3 @@ func (gro *GraftedOwnership) ResolveOwners(ctx context.Context) (Addrs, error) {
291299
seen := make([]chaintree.Path, 0)
292300
return gro.resolveOwnersRecursively(ctx, gro.graftedDag, seen)
293301
}
294-

sdk/gossip/types/graftedownership_test.go

+38-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func newChaintreeWithNodes(t *testing.T, ctx context.Context, name string, treeN
5959
root := sw.WrapObject(map[string]interface{}{
6060
"chain": chain.Cid(),
6161
"tree": tree.Cid(),
62-
"id": "did:tupelo:"+name,
62+
"id": "did:tupelo:" + name,
6363
})
6464

6565
store := nodestore.MustMemoryStore(ctx)
@@ -88,7 +88,7 @@ func newChaintreeOwnedBy(t *testing.T, ctx context.Context, name string, owners
8888
})
8989
}
9090

91-
func newDagGetter(t *testing.T, ctx context.Context, chaintrees... *chaintree.ChainTree) *TestDagGetter {
91+
func newDagGetter(t *testing.T, ctx context.Context, chaintrees ...*chaintree.ChainTree) *TestDagGetter {
9292
dagGetter := &TestDagGetter{
9393
chaintrees: make(map[string]*chaintree.ChainTree),
9494
}
@@ -275,7 +275,7 @@ func TestResolveOwnersArbitraryPath(t *testing.T) {
275275
did, err := ct1.Id(ctx)
276276
require.Nil(t, err)
277277

278-
ct2 := newChaintreeOwnedBy(t, ctx, "dos", []string{did+"/tree/data/otherChaintreeOwners", "otheraddr"})
278+
ct2 := newChaintreeOwnedBy(t, ctx, "dos", []string{did + "/tree/data/otherChaintreeOwners", "otheraddr"})
279279
did, err = ct2.Id(ctx)
280280
require.Nil(t, err)
281281

@@ -297,6 +297,41 @@ func TestResolveOwnersArbitraryPath(t *testing.T) {
297297
assert.Contains(t, owners, "otheraddr")
298298
}
299299

300+
// TestResolveOwnersThroughIntermediary sets up a test where an organization
301+
// has many users (listed in its ChainTree as DIDs) and then an asset is owned by
302+
// the path to the organization's list of users (and the organization itself).
303+
func TestResolveOwnersThroughIntermediary(t *testing.T) {
304+
ctx, cancel := context.WithCancel(context.Background())
305+
defer cancel()
306+
307+
userTree := newChaintree(t, ctx, "user")
308+
did, err := userTree.Id(ctx)
309+
require.Nil(t, err)
310+
311+
organizationTree := newChaintreeWithNodes(t, ctx, "org", map[string]interface{}{
312+
"data": map[string]interface{}{
313+
"users": []string{did},
314+
},
315+
})
316+
orgDid, err := organizationTree.Id(ctx)
317+
require.Nil(t, err)
318+
319+
assetTree := newChaintreeOwnedBy(t, ctx, "asset", []string{orgDid + "/tree/data/users", orgDid})
320+
dg := newDagGetter(t, ctx, userTree, organizationTree, assetTree)
321+
322+
originDag := assetTree.Dag
323+
324+
gro, err := NewGraftedOwnership(originDag, dg)
325+
require.Nil(t, err)
326+
327+
owners, err := gro.ResolveOwners(ctx)
328+
require.Nil(t, err)
329+
330+
assert.Equal(t, 2, len(owners))
331+
assert.Contains(t, owners, "user")
332+
assert.Contains(t, owners, "org")
333+
}
334+
300335
func TestResolveOwnersLoop(t *testing.T) {
301336
ctx, cancel := context.WithCancel(context.Background())
302337
defer cancel()

0 commit comments

Comments
 (0)