Skip to content

Commit 87bc86a

Browse files
authored
Add stopgap solution for partial attestations
Add stopgap solution for partial attestations AB#8805
2 parents baaee57 + 2ec1e55 commit 87bc86a

File tree

4 files changed

+128
-6
lines changed

4 files changed

+128
-6
lines changed

datatrails-common-api/assets/v2/assets/accesspolicy.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,31 @@ func (a *AssetResponse) AccessPolicyStringValue(name, defaultValue string) (stri
3838
return value, nil
3939
}
4040

41+
// IsPubliclyAttested determines if an asset is publicly attested
42+
// if public wallet address is present *anywhere* in the policy
43+
// we assume the asset is public as there is no other way of getting
44+
// public wallet to policy other than setting public: true on an asset
45+
// previous method was to specific and did not work with partial attestation
46+
func (a *AssetResponse) IsPubliclyAttested(publicWallet string) bool {
47+
48+
for attrs := range a.AccessPolicy {
49+
data, ok := a.AccessPolicy[attrs].GetList()
50+
if !ok {
51+
continue
52+
}
53+
54+
for _, v := range data {
55+
if vv, ok := v[publicWallet]; ok {
56+
if vv == "wallet" {
57+
return true
58+
}
59+
}
60+
}
61+
}
62+
63+
return false
64+
}
65+
4166
// IsSharedForWallet determines if the value identified by `attribute` is shared
4267
// with the organisation identified by `wallet`. `policyKey` determines the kind
4368
// of share: asset attribute or event attribute and whether it is a read share

datatrails-common-api/assets/v2/assets/accesspolicy_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,102 @@ func TestAssetResponse_IsSharedForWallet_AssetAttributesMixedWildeReader(t *test
398398
}
399399
}
400400

401+
// TestAssetResponse_IsPubliclyAttested_AssetAttributesMixedWildeReader
402+
// Covers mixed read cases (wild card present in policy, all shares are read shares)
403+
func TestAssetResponse_IsPubliclyAttested_AssetAttributesMixedWildeReader(t *testing.T) {
404+
405+
type fields struct {
406+
AccessPolicy map[string]*v2attribute.Attribute
407+
}
408+
type args struct {
409+
policyKey string
410+
wallet string
411+
attribute string
412+
}
413+
414+
Wallet1 := "0xWALLET1"
415+
Wallet2 := "0xWALLET2"
416+
WalletWild := "0xWILD-WALLET"
417+
418+
TesseraPub1 := "b64-TESSERAPUB1"
419+
TesseraPub2 := "b64-TESSERAPUB2"
420+
TesseraPubWild := "b64-TESSERAPUB-WILD"
421+
tractor_colour := "tractor_colour"
422+
engine_size := "engine_size"
423+
424+
twoReadSharedAssetAttributesAndOneWildWallet := map[string]*v2attribute.Attribute{}
425+
426+
policyAddAssetAttributeReaderOrFailNow(
427+
t, twoReadSharedAssetAttributesAndOneWildWallet, tractor_colour, Wallet1, TesseraPub1)
428+
policyAddAssetAttributeReaderOrFailNow(
429+
t, twoReadSharedAssetAttributesAndOneWildWallet, engine_size, Wallet2, TesseraPub2)
430+
policyAddAssetAttributeReaderOrFailNow(
431+
t, twoReadSharedAssetAttributesAndOneWildWallet, "*", WalletWild, TesseraPubWild)
432+
433+
tests := []struct {
434+
name string
435+
fields fields
436+
args args
437+
want bool
438+
wantErr bool
439+
}{
440+
// TODO: Add test cases.
441+
{
442+
name: "Should match wildwallet in policy sharing two asset attributes",
443+
fields: fields{
444+
AccessPolicy: twoReadSharedAssetAttributesAndOneWildWallet,
445+
},
446+
args: args{
447+
wallet: WalletWild,
448+
},
449+
want: true,
450+
},
451+
{
452+
name: "Should match wildwallet in policy sharing two asset attributes",
453+
fields: fields{
454+
AccessPolicy: twoReadSharedAssetAttributesAndOneWildWallet,
455+
},
456+
args: args{
457+
wallet: WalletWild,
458+
},
459+
want: true,
460+
},
461+
462+
{
463+
name: "Should match wallet1 in policy sharing two asset attributes",
464+
fields: fields{
465+
AccessPolicy: twoReadSharedAssetAttributesAndOneWildWallet,
466+
},
467+
args: args{
468+
wallet: Wallet1,
469+
},
470+
want: true,
471+
},
472+
473+
{
474+
name: "Should match wallet2 in policy even partial share",
475+
fields: fields{
476+
AccessPolicy: twoReadSharedAssetAttributesAndOneWildWallet,
477+
},
478+
args: args{
479+
wallet: Wallet2,
480+
},
481+
want: true,
482+
},
483+
}
484+
for _, tt := range tests {
485+
t.Run(tt.name, func(t *testing.T) {
486+
a := &AssetResponse{
487+
AccessPolicy: tt.fields.AccessPolicy,
488+
}
489+
got := a.IsPubliclyAttested(tt.args.wallet)
490+
if got != tt.want {
491+
t.Errorf("AssetResponse.IsPubliclyAttested() = %v, want %v", got, tt.want)
492+
}
493+
})
494+
}
495+
}
496+
401497
func policyAddAssetAttributeReaderOrFailNow(
402498
t *testing.T,
403499
policy map[string]*v2attribute.Attribute,

getproto.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/sh
2+
cd datatrails-common-api/
3+
echo $(GOCACHE=/tmp/datatrails/go-datatrails-common-api/api go list -f {{.Dir}} $1)

taskfiles/Taskfile_apis.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,15 @@ tasks:
253253
# return for this. AND it makes iteratively generating proto changes
254254
# across repositories a lot more efficient
255255
sh: |
256-
cd datatrails-common-api
257-
echo $(GOCACHE=/tmp/datatrails/go-datatrails-common-api/api go list -f {{"{{"}}.Dir{{"}}"}} google.golang.org/protobuf/cmd/protoc-gen-go)
256+
echo $(./getproto.sh google.golang.org/protobuf/cmd/protoc-gen-go)
258257
259258
GRPC_GATEWAY_DIR:
260259
sh: |
261-
cd datatrails-common-api
262-
echo $(dirname $(GOCACHE=/tmp/datatrails/go-datatrails-common-api/api go list -f {{"{{"}}.Dir{{"}}"}} github.com/grpc-ecosystem/grpc-gateway/v2/runtime))
260+
echo $(dirname $(./getproto.sh github.com/grpc-ecosystem/grpc-gateway/v2/runtime))
261+
263262
ENVOY_VALIDATE:
264263
sh: |
265-
cd datatrails-common-api
266-
echo $(GOCACHE=/tmp/datatrails/go-datatrails-common-api/api go list -f {{"{{"}}.Dir{{"}}"}} github.com/envoyproxy/protoc-gen-validate)
264+
echo $(./getproto.sh github.com/envoyproxy/protoc-gen-validate)
267265
268266
SELF_INC: .
269267

0 commit comments

Comments
 (0)