Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Change local_acp implementation to use acp_core #2691

Merged
merged 46 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
185ccec
refactor: replace Embedded ACP with ACP Core engine
Lodek Jun 6, 2024
bb0f676
doc: doc methods
Lodek Jun 5, 2024
1059f0a
test refactor wip
Lodek Jun 5, 2024
5aeab86
add_policy refactor
Lodek Jun 5, 2024
90cd3f1
fix: index test
Lodek Jun 5, 2024
4a555a4
fix p2p tests
Lodek Jun 5, 2024
4b233e9
fix: query tests
Lodek Jun 5, 2024
aa22100
schema test refactor
Lodek Jun 5, 2024
f108555
fix: acp integration
Lodek Jun 5, 2024
33b994c
test fixes
Lodek Jun 5, 2024
4b56a79
test fixes
Lodek Jun 6, 2024
c31efc8
doc: updated acp_local adapter docs
Lodek Jun 6, 2024
4ed1c0c
added defra policy abstraction
Lodek Jun 6, 2024
7e4982d
mod bump
Lodek Jun 6, 2024
dc907a9
fix: net peer tests
Lodek Jun 6, 2024
d5c1de1
remove helper methods from policy data types
Lodek Jun 6, 2024
a549c9d
fix: collection_description test fix
Lodek Jun 7, 2024
5af32f4
PR suggestins and toolchain update
Lodek Jun 7, 2024
edb060a
chore: update fixme docs
Lodek Jun 7, 2024
796454d
bump acp_core version
Lodek Jun 7, 2024
6682ba5
refactor identity
Lodek Jun 7, 2024
a198dd0
factor: Indetity DID generation and test fixes
Lodek Jun 7, 2024
3bcbc39
update license in file
Lodek Jun 7, 2024
cf27ec2
test: added missing tests
Lodek Jun 10, 2024
ee5fb03
refactor: identity returns error
Lodek Jun 11, 2024
dd34b38
refactor fixes
Lodek Jun 11, 2024
f5ceca9
Merge branch 'develop' into refactor/local-acp
Lodek Jun 11, 2024
d0db457
chore: go mod tidy
Lodek Jun 11, 2024
9308ad2
revert: change actor id to creator id in polcy create
Lodek Jun 11, 2024
d9cf7d6
test: FromPrivateKey, FromPublicKey
Lodek Jun 11, 2024
df10e84
fix: typo
Lodek Jun 11, 2024
67cb1c1
identity and did providers
Lodek Jun 13, 2024
71364aa
identity refactor
Lodek Jun 13, 2024
04cc0b7
ci fix
Lodek Jun 13, 2024
547e194
fix typo
Lodek Jun 13, 2024
b80aa03
provier rename
Lodek Jun 13, 2024
549c406
Revert "identity refactor"
Lodek Jun 14, 2024
6dbd782
producer refactor
Lodek Jun 14, 2024
6982d9e
cleanup
Lodek Jun 14, 2024
6205c7b
lint fix
Lodek Jun 14, 2024
568a46b
Merge branch 'develop' into refactor/local-acp
Lodek Jun 14, 2024
d28db70
revert identity provider
Lodek Jun 14, 2024
3b3bbe8
refactor: make identity err func private
Lodek Jun 14, 2024
e1135a1
revert policy marshal type location
Lodek Jun 14, 2024
10f5826
Merge branch 'develop' into refactor/local-acp
Lodek Jun 19, 2024
80beb43
chore: mod tidy
Lodek Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions acp/acp_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/sourcenetwork/acp_core/pkg/runtime"
"github.com/sourcenetwork/acp_core/pkg/types"
"github.com/sourcenetwork/immutable"
"github.com/valyala/fastjson"
)

// ACPLocal represents a local acp implementation that makes no remote calls.
Expand Down Expand Up @@ -122,9 +123,11 @@ func (l *ACPLocal) AddPolicy(
}
ctx = auth.InjectPrincipal(ctx, principal)

// Since YAML is a superset of JSON, assume Policy is YAML
// and let SourceHub figure it out.
marshalType := types.PolicyMarshalingType_SHORT_YAML
if isJSON := fastjson.Validate(policy) == nil; isJSON { // Detect JSON format.
marshalType = types.PolicyMarshalingType_SHORT_JSON
}

createPolicy := types.CreatePolicyRequest{
Policy: policy,
MarshalType: marshalType,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/acp/add_policy/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestACP_AddPolicy_BasicYAML_ValidPolicyID(t *testing.T) {

`,

ExpectedPolicyID: "aa664afaf8dff947ba85f4d464662d595af6c1e2466bd11fd6b82ea95b547ea3",
ExpectedPolicyID: "66f3e364004a181e9b129f65dea317322d2285226e926d7e8cdfd644954e4262",
},
},
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestACP_AddPolicy_BasicJSON_ValidPolicyID(t *testing.T) {
}
`,

ExpectedPolicyID: "aa664afaf8dff947ba85f4d464662d595af6c1e2466bd11fd6b82ea95b547ea3",
ExpectedPolicyID: "66f3e364004a181e9b129f65dea317322d2285226e926d7e8cdfd644954e4262",
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestACP_AddPolicy_ExtraPermissionsAndExtraRelations_ValidPolicyID(t *testin
Identity: actor1Identity,

Policy: `
name: a policy
name: test
description: a policy

actor:
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestACP_AddPolicy_ExtraPermissionsAndExtraRelations_ValidPolicyID(t *testin
- actor
`,

ExpectedPolicyID: "f29c97dca930c9e93f7ef9e2139c63939c573af96c95af5cb9392861a0111b13",
ExpectedPolicyID: "af2a2eaa2d6701262ea60665487c87e3d41ab727194e1ea18ec16348149a02cc",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/acp/add_policy/with_extra_perms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestACP_AddPolicy_ExtraPermissions_ValidPolicyID(t *testing.T) {
name: actor
`,

ExpectedPolicyID: "af6795fa4fce1c2b4f9c1252c1cdd758708a45e4fc3097406c008d78c820ee80",
ExpectedPolicyID: "a756ba5a7fe25e3fc36a4f113016a49b718b09028c917199ae68f478addc048c",
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestACP_AddPolicy_ExtraRelations_ValidPolicyID(t *testing.T) {
- actor
`,

ExpectedPolicyID: "922636974ecbc3c335143e45917832f219dfe4a168a523e7314616b94e7f9ebc",
ExpectedPolicyID: "bdfe4d449b8a42b1daf247e37b5a62ee139ff5b79fa15a970d5d7ae32c08d1e5",
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ func TestACP_AddPolicy_InvalidCreatorIdentityWithValidPolicy_Error(t *testing.T)

`,

ExpectedError: "policy creator can not be empty",
ExpectedError: "cannot generate did if address is not prefixed",
},
},
}

//TODO-ACP: https://github.com/sourcenetwork/defradb/issues/2357
testUtils.AssertPanic(t, func() { testUtils.ExecuteTestCase(t, test) })
testUtils.ExecuteTestCase(t, test)
}

func TestACP_AddPolicy_InvalidCreatorIdentityWithEmptyPolicy_Error(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestACP_AddPolicy_WithRelationManagingOtherRelation_ValidPolicyID(t *testin
- actor
`,

ExpectedPolicyID: "a42e109f1542da3fef5f8414621a09aa4805bf1ac9ff32ad9940bd2c488ee6cd",
ExpectedPolicyID: "725caeee6c5043f019e7dc3bb6a627520c235f063e862696c67ac89b5c1fc840",
},
},
}
Expand Down
22 changes: 11 additions & 11 deletions tests/integration/acp/add_policy/with_multi_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestACP_AddPolicy_AddMultipleDifferentPolicies_ValidPolicyIDs(t *testing.T)

`,

ExpectedPolicyID: "aa664afaf8dff947ba85f4d464662d595af6c1e2466bd11fd6b82ea95b547ea3",
ExpectedPolicyID: "2eb8b503c9fc0b7c1f7b04d68a6faa0f82a299db0ae02fed68f9897612439cb6",
},

testUtils.AddPolicy{
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestACP_AddPolicy_AddMultipleDifferentPolicies_ValidPolicyIDs(t *testing.T)
- actor
`,

ExpectedPolicyID: "a42e109f1542da3fef5f8414621a09aa4805bf1ac9ff32ad9940bd2c488ee6cd",
ExpectedPolicyID: "6b766a9aafabf0bf65102f73b7cd81963b65e1fd87ce763f386cc685147325ee",
},
},
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestACP_AddPolicy_AddMultipleDifferentPoliciesInDifferentFmts_ValidPolicyID
}
`,

ExpectedPolicyID: "aa664afaf8dff947ba85f4d464662d595af6c1e2466bd11fd6b82ea95b547ea3",
ExpectedPolicyID: "66f3e364004a181e9b129f65dea317322d2285226e926d7e8cdfd644954e4262",
},

testUtils.AddPolicy{
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestACP_AddPolicy_AddMultipleDifferentPoliciesInDifferentFmts_ValidPolicyID
- actor
`,

ExpectedPolicyID: "a42e109f1542da3fef5f8414621a09aa4805bf1ac9ff32ad9940bd2c488ee6cd",
ExpectedPolicyID: "7bcb558ef8dac6b744a11ea144a61a756ea38475554097ac04612037c36ffe52",
},
},
}
Expand Down Expand Up @@ -203,15 +203,15 @@ func TestACP_AddPolicy_AddDuplicatePolicyByOtherCreator_ValidPolicyIDs(t *testin

Policy: policyUsedByBoth,

ExpectedPolicyID: "aa664afaf8dff947ba85f4d464662d595af6c1e2466bd11fd6b82ea95b547ea3",
ExpectedPolicyID: "66f3e364004a181e9b129f65dea317322d2285226e926d7e8cdfd644954e4262",
},

testUtils.AddPolicy{
Identity: actor2Identity,

Policy: policyUsedByBoth,

ExpectedPolicyID: "5cff96a89799f7974906138fb794f670d35ac5df9985621da44f9f3529af1c0b",
ExpectedPolicyID: "ec02815cb630850678bda5e2d75cfacebc96f5610e32a602f7bfc414e21474ad",
},
},
}
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestACP_AddPolicy_AddMultipleDuplicatePolicies_Error(t *testing.T) {

`,

ExpectedPolicyID: "aa664afaf8dff947ba85f4d464662d595af6c1e2466bd11fd6b82ea95b547ea3",
ExpectedPolicyID: "66f3e364004a181e9b129f65dea317322d2285226e926d7e8cdfd644954e4262",
},

testUtils.AddPolicy{
Expand Down Expand Up @@ -278,15 +278,15 @@ func TestACP_AddPolicy_AddMultipleDuplicatePolicies_Error(t *testing.T) {

`,

ExpectedError: "policy aa664afaf8dff947ba85f4d464662d595af6c1e2466bd11fd6b82ea95b547ea3: policy exists",
ExpectedPolicyID: "ec02815cb630850678bda5e2d75cfacebc96f5610e32a602f7bfc414e21474ad",
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestACP_AddPolicy_AddMultipleDuplicatePoliciesDifferentFmts_Error(t *testing.T) {
func TestACP_AddPolicy_AddMultipleDuplicatePoliciesDifferentFmts_ProducesDifferentIDs(t *testing.T) {
Lodek marked this conversation as resolved.
Show resolved Hide resolved
test := testUtils.TestCase{

Description: "Test acp, add duplicate policies different formats, error",
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestACP_AddPolicy_AddMultipleDuplicatePoliciesDifferentFmts_Error(t *testin
- actor
`,

ExpectedPolicyID: "aa664afaf8dff947ba85f4d464662d595af6c1e2466bd11fd6b82ea95b547ea3",
ExpectedPolicyID: "66f3e364004a181e9b129f65dea317322d2285226e926d7e8cdfd644954e4262",
},

testUtils.AddPolicy{
Expand Down Expand Up @@ -351,7 +351,7 @@ func TestACP_AddPolicy_AddMultipleDuplicatePoliciesDifferentFmts_Error(t *testin
}
`,

ExpectedError: "policy aa664afaf8dff947ba85f4d464662d595af6c1e2466bd11fd6b82ea95b547ea3: policy exists",
ExpectedPolicyID: "ec02815cb630850678bda5e2d75cfacebc96f5610e32a602f7bfc414e21474ad",
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestACP_AddPolicy_MultipleResources_ValidID(t *testing.T) {
- actor
`,

ExpectedPolicyID: "390239e42550ea5945b9185576b79694f7000a7ce3b301d60afe35572c958cd7",
ExpectedPolicyID: "a9e1a113ccc2609d7f99a42531017f0fbc9b736640ec8ffc7f09a1e29583ca45",
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/acp/add_policy/with_no_perms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestACP_AddPolicy_NoPermissionsOnlyOwner_ValidID(t *testing.T) {

`,

ExpectedPolicyID: "39b436f0c28e7ce5ed7e1c592bb578590d62ccfacef0df565ac97520c880c017",
ExpectedPolicyID: "db6e4d3efc58f8a7bfe8f35c73c39630f1ad3e6fad7ffeb22563d1284bd176dc",
},
},
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestACP_AddPolicy_NoPermissionsMultiRelations_ValidID(t *testing.T) {

`,

ExpectedPolicyID: "07da6260811df769d551e89e02364b3e939cb585696c1a69b626bb8ecdd378f9",
ExpectedPolicyID: "106a38bfb702608e26feda961d9fffd74141ef34eccc17b3de2c15dd7620da46",
},
},
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestACP_AddPolicy_NoPermissionsLabelOnlyOwner_ValidID(t *testing.T) {

`,

ExpectedPolicyID: "39b436f0c28e7ce5ed7e1c592bb578590d62ccfacef0df565ac97520c880c017",
ExpectedPolicyID: "db6e4d3efc58f8a7bfe8f35c73c39630f1ad3e6fad7ffeb22563d1284bd176dc",
},
},
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestACP_AddPolicy_NoPermissionsLabelMultiRelations_ValidID(t *testing.T) {

`,

ExpectedPolicyID: "07da6260811df769d551e89e02364b3e939cb585696c1a69b626bb8ecdd378f9",
ExpectedPolicyID: "106a38bfb702608e26feda961d9fffd74141ef34eccc17b3de2c15dd7620da46",
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/acp/add_policy/with_no_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestACP_AddPolicy_NoResource_ValidID(t *testing.T) {
resources:
`,

ExpectedPolicyID: "e16824022121b55f2b2babbd2ab82960a8837767197e20acf9c577cbb4539991",
ExpectedPolicyID: "e3ffe8e802e4612dc41d7a638cd77dc16d51eb1db0d18682eec75b05234e6ee2",
},
},
}
Expand All @@ -64,7 +64,7 @@ func TestACP_AddPolicy_NoResourceLabel_ValidID(t *testing.T) {
name: actor
`,

ExpectedPolicyID: "e16824022121b55f2b2babbd2ab82960a8837767197e20acf9c577cbb4539991",
ExpectedPolicyID: "e3ffe8e802e4612dc41d7a638cd77dc16d51eb1db0d18682eec75b05234e6ee2",
},
},
}
Expand All @@ -74,7 +74,7 @@ func TestACP_AddPolicy_NoResourceLabel_ValidID(t *testing.T) {

// Eventhough empty resources make no sense from a DefraDB (DPI) perspective,
// it is still a valid sourcehub policy for now.
Lodek marked this conversation as resolved.
Show resolved Hide resolved
func TestACP_AddPolicy_PolicyWithOnlySpace_ValidID(t *testing.T) {
func TestACP_AddPolicy_PolicyWithOnlySpace_NameIsRequired(t *testing.T) {
test := testUtils.TestCase{

Description: "Test acp, adding a policy that has only space",
Expand All @@ -85,7 +85,7 @@ func TestACP_AddPolicy_PolicyWithOnlySpace_ValidID(t *testing.T) {

Policy: " ",

ExpectedPolicyID: "e16824022121b55f2b2babbd2ab82960a8837767197e20acf9c577cbb4539991",
ExpectedError: "name is required",
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/acp/add_policy/with_perm_expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestACP_AddPolicy_PermissionExprWithOwnerInTheEndWithMinus_ValidID(t *testi
- actor
`,

ExpectedPolicyID: "fcb989d8bad149e3c4b22f8a69969760187b29ea1c796a3f9d2e16e32f493590",
ExpectedPolicyID: "2b10641de73790b95452f496a37ad53a8d8a0703803f35f6961457af912947c0",
},
},
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestACP_AddPolicy_PermissionExprWithOwnerInTheEndWithMinusNoSpace_ValidID(t
- actor
`,

ExpectedPolicyID: "50d8fbaf70a08c2c0e2bf0355a353a8bb06cc4d6e2f3ddbf71d91f9ef5aa49af",
ExpectedPolicyID: "b6b305214247a08903e01466a1bfd01516206458d2725506797300b285e63690",
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestACP_AddPolicy_PermissionlessOwnerWrite_ValidID(t *testing.T) {
- actor
`,

ExpectedPolicyID: "f7e7b84108ba67bcdeb211ff740eee13b2b6770106dcf0d0436a3a33d8a2f9f0",
ExpectedPolicyID: "9328e41c1969c6269bfd82162b45831ccec8df9fc8d57902620ad43baaa0d77d",
},
},
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestACP_AddPolicy_PermissionlessOwnerRead_ValidID(t *testing.T) {
- actor
`,

ExpectedPolicyID: "22c3eee3b3d216c01244a47a6aa241a08b767b3ef0a9edfbd30b3575a6bd94f4",
ExpectedPolicyID: "74f3c0996d5b1669b9efda5ef45f93a925df9f770e2dcd53f352b5f0693a2b0f",
},
},
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestACP_AddPolicy_PermissionlessOwnerReadWrite_ValidID(t *testing.T) {
- actor
`,

ExpectedPolicyID: "f7e7b84108ba67bcdeb211ff740eee13b2b6770106dcf0d0436a3a33d8a2f9f0",
ExpectedPolicyID: "9328e41c1969c6269bfd82162b45831ccec8df9fc8d57902620ad43baaa0d77d",
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestACP_AddPolicy_UnusedRelation_ValidID(t *testing.T) {

`,

ExpectedPolicyID: "a6d42bfedff5db1feca0313793e4f9540851e3feaefffaebc98a1ee5bb140e45",
ExpectedPolicyID: "ab1102f656ed1f2b037a3c9586611c701243f2086fa64211bd7baff7271c2030",
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/acp/index/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func TestACP_IndexCreateWithSeparateRequest_OnCollectionWithPolicy_NoError(t *te
testUtils.AddPolicy{
Identity: acpUtils.Actor1Identity,
Policy: userPolicy,
ExpectedPolicyID: "a42e109f1542da3fef5f8414621a09aa4805bf1ac9ff32ad9940bd2c488ee6cd",
ExpectedPolicyID: "7bcb558ef8dac6b744a11ea144a61a756ea38475554097ac04612037c36ffe52",
},

testUtils.SchemaUpdate{
Schema: `
type Users @policy(
id: "a42e109f1542da3fef5f8414621a09aa4805bf1ac9ff32ad9940bd2c488ee6cd",
id: "7bcb558ef8dac6b744a11ea144a61a756ea38475554097ac04612037c36ffe52",
resource: "users"
) {
name: String
Expand Down Expand Up @@ -71,13 +71,13 @@ func TestACP_IndexCreateWithDirective_OnCollectionWithPolicy_NoError(t *testing.
testUtils.AddPolicy{
Identity: acpUtils.Actor1Identity,
Policy: userPolicy,
ExpectedPolicyID: "a42e109f1542da3fef5f8414621a09aa4805bf1ac9ff32ad9940bd2c488ee6cd",
ExpectedPolicyID: "7bcb558ef8dac6b744a11ea144a61a756ea38475554097ac04612037c36ffe52",
},

testUtils.SchemaUpdate{
Schema: `
type Users @policy(
id: "a42e109f1542da3fef5f8414621a09aa4805bf1ac9ff32ad9940bd2c488ee6cd",
id: "7bcb558ef8dac6b744a11ea144a61a756ea38475554097ac04612037c36ffe52",
resource: "users"
) {
name: String @index
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/acp/index/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

package test_acp_index

// policy id: "a42e109f1542da3fef5f8414621a09aa4805bf1ac9ff32ad9940bd2c488ee6cd"
// policy id: "7bcb558ef8dac6b744a11ea144a61a756ea38475554097ac04612037c36ffe52"
Lodek marked this conversation as resolved.
Show resolved Hide resolved
const userPolicy = `
description: a test policy which marks a collection in a database as a resource

Expand Down
Loading