forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR(TEST): Test Permissioned Schema Reject/Accept
- Loading branch information
1 parent
3307d8e
commit cb7a815
Showing
19 changed files
with
3,419 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
## More Information on what each directory tests. | ||
## More Information on ACP test directories. | ||
|
||
|
||
1) `./add_policy` | ||
1) `./defradb/tests/integration/acp/add_policy` | ||
- This directory tests ONLY the `Adding of a Policy` through DefraDB. | ||
- Does NOT assert the schema. | ||
- Does NOT test DPI validation. | ||
|
||
2) `./defradb/tests/integration/acp/schema/add_dpi` | ||
- This directory tests the loading/adding of a schema that has `@policy(id, resource)` | ||
specified (i.e. permissioned schema). The tests ensure that only a schema linking to | ||
a valid DPI policy is accepted. Naturally these tests will also be `Adding a Policy` | ||
through DefraDB like in (1) before actually adding the schema. If a schema has a | ||
policy specified that doesn't exist (or wasn't added yet), that schema WILL/MUST | ||
be rejected in these tests. | ||
- The tests assert the schema after to ensure rejection/acceptance. | ||
- Tests DPI validation. |
214 changes: 214 additions & 0 deletions
214
tests/integration/acp/schema/add_dpi/accept_basic_dpi_fmts_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package test_acp_schema_add_dpi | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
schemaUtils "github.com/sourcenetwork/defradb/tests/integration/schema" | ||
) | ||
|
||
func TestACP_AddDPISchema_BasicYAML_SchemaAccepted(t *testing.T) { | ||
policyIDOfValidDPI := "dfe202ffb4f0fe9b46157c313213a3839e08a6f0a7c3aba55e4724cb49ffde8a" | ||
|
||
test := testUtils.TestCase{ | ||
Description: "Test acp, specify basic policy that was added in YAML format, accept schema", | ||
|
||
Actions: []any{ | ||
testUtils.AddPolicy{ | ||
IsYAML: true, | ||
|
||
Creator: actor1Signature, | ||
|
||
Policy: ` | ||
description: a basic policy that satisfies minimum DPI requirements | ||
actor: | ||
name: actor | ||
resources: | ||
users: | ||
permissions: | ||
read: | ||
expr: owner | ||
write: | ||
expr: owner | ||
relations: | ||
owner: | ||
types: | ||
- actor | ||
`, | ||
|
||
ExpectedPolicyID: policyIDOfValidDPI, | ||
}, | ||
|
||
testUtils.SchemaUpdate{ | ||
Schema: fmt.Sprintf(` | ||
type Users @policy( | ||
id: "%s", | ||
resource: "users" | ||
) { | ||
name: String | ||
age: Int | ||
} | ||
`, | ||
policyIDOfValidDPI, | ||
), | ||
}, | ||
|
||
testUtils.IntrospectionRequest{ | ||
Request: ` | ||
query { | ||
__type (name: "Users") { | ||
name | ||
fields { | ||
name | ||
type { | ||
name | ||
kind | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
ExpectedData: map[string]any{ | ||
"__type": map[string]any{ | ||
"name": "Users", // NOTE: "Users" MUST exist | ||
"fields": schemaUtils.DefaultFields.Append( | ||
schemaUtils.Field{ | ||
"name": "name", | ||
"type": map[string]any{ | ||
"kind": "SCALAR", | ||
"name": "String", | ||
}, | ||
}, | ||
).Append( | ||
schemaUtils.Field{ | ||
"name": "age", | ||
"type": map[string]any{ | ||
"kind": "SCALAR", | ||
"name": "Int", | ||
}, | ||
}, | ||
).Tidy(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_AddDPISchema_BasicJSON_SchemaAccepted(t *testing.T) { | ||
policyIDOfValidDPI := "dfe202ffb4f0fe9b46157c313213a3839e08a6f0a7c3aba55e4724cb49ffde8a" | ||
|
||
test := testUtils.TestCase{ | ||
Description: "Test acp, specify basic policy that was added in JSON format, accept schema", | ||
|
||
Actions: []any{ | ||
testUtils.AddPolicy{ | ||
IsYAML: false, | ||
|
||
Creator: actor1Signature, | ||
|
||
Policy: ` | ||
{ | ||
"description": "a basic policy that satisfies minimum DPI requirements", | ||
"resources": { | ||
"users": { | ||
"permissions": { | ||
"read": { | ||
"expr": "owner" | ||
}, | ||
"write": { | ||
"expr": "owner" | ||
} | ||
}, | ||
"relations": { | ||
"owner": { | ||
"types": [ | ||
"actor" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"actor": { | ||
"name": "actor" | ||
} | ||
} | ||
`, | ||
|
||
ExpectedPolicyID: policyIDOfValidDPI, | ||
}, | ||
|
||
testUtils.SchemaUpdate{ | ||
Schema: fmt.Sprintf(` | ||
type Users @policy( | ||
id: "%s", | ||
resource: "users" | ||
) { | ||
name: String | ||
age: Int | ||
} | ||
`, | ||
policyIDOfValidDPI, | ||
), | ||
}, | ||
|
||
testUtils.IntrospectionRequest{ | ||
Request: ` | ||
query { | ||
__type (name: "Users") { | ||
name | ||
fields { | ||
name | ||
type { | ||
name | ||
kind | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
ExpectedData: map[string]any{ | ||
"__type": map[string]any{ | ||
"name": "Users", // NOTE: "Users" MUST exist | ||
"fields": schemaUtils.DefaultFields.Append( | ||
schemaUtils.Field{ | ||
"name": "name", | ||
"type": map[string]any{ | ||
"kind": "SCALAR", | ||
"name": "String", | ||
}, | ||
}, | ||
).Append( | ||
schemaUtils.Field{ | ||
"name": "age", | ||
"type": map[string]any{ | ||
"kind": "SCALAR", | ||
"name": "Int", | ||
}, | ||
}, | ||
).Tidy(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |
Oops, something went wrong.