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(WIP): Add ACP Tests With Identity
- Loading branch information
1 parent
364cf78
commit 6a1e5df
Showing
1 changed file
with
355 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,355 @@ | ||
// 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 | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestACP_CreateWithoutIdentityAndReadWithoutIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
|
||
Description: "Test acp, create without identity, and read without identity", | ||
|
||
Actions: []any{ | ||
testUtils.AddPolicy{ | ||
|
||
Creator: Actor1Signature, | ||
|
||
Policy: ` | ||
description: a test policy which marks a collection in a database as a resource | ||
actor: | ||
name: actor | ||
resources: | ||
users: | ||
permissions: | ||
read: | ||
expr: owner + reader | ||
write: | ||
expr: owner | ||
relations: | ||
owner: | ||
types: | ||
- actor | ||
reader: | ||
types: | ||
- actor | ||
admin: | ||
manages: | ||
- reader | ||
types: | ||
- actor | ||
`, | ||
|
||
ExpectedPolicyID: "53980e762616fcffbe76307995895e862f87ef3f21d509325d1dc772a770b001", | ||
}, | ||
|
||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users @policy( | ||
id: "53980e762616fcffbe76307995895e862f87ef3f21d509325d1dc772a770b001", | ||
resource: "users" | ||
) { | ||
name: String | ||
age: Int | ||
} | ||
`, | ||
}, | ||
|
||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "John", | ||
"age": 27 | ||
}`, | ||
}, | ||
|
||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
Users { | ||
_docID | ||
name | ||
age | ||
} | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
"_docID": "bae-88b63198-7d38-5714-a9ff-21ba46374fd1", | ||
"name": "John", | ||
"age": int64(27), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_CreateWithoutIdentityAndReadWithIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
|
||
Description: "Test acp, create without identity, and read with identity", | ||
|
||
Actions: []any{ | ||
testUtils.AddPolicy{ | ||
|
||
Creator: Actor1Signature, | ||
|
||
Policy: ` | ||
description: a test policy which marks a collection in a database as a resource | ||
actor: | ||
name: actor | ||
resources: | ||
users: | ||
permissions: | ||
read: | ||
expr: owner + reader | ||
write: | ||
expr: owner | ||
relations: | ||
owner: | ||
types: | ||
- actor | ||
reader: | ||
types: | ||
- actor | ||
admin: | ||
manages: | ||
- reader | ||
types: | ||
- actor | ||
`, | ||
|
||
ExpectedPolicyID: "53980e762616fcffbe76307995895e862f87ef3f21d509325d1dc772a770b001", | ||
}, | ||
|
||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users @policy( | ||
id: "53980e762616fcffbe76307995895e862f87ef3f21d509325d1dc772a770b001", | ||
resource: "users" | ||
) { | ||
name: String | ||
age: Int | ||
} | ||
`, | ||
}, | ||
|
||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "John", | ||
"age": 27 | ||
}`, | ||
}, | ||
|
||
testUtils.Request{ | ||
Identity: Actor1Signature, | ||
|
||
Request: ` | ||
query { | ||
Users { | ||
_docID | ||
name | ||
age | ||
} | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
"_docID": "bae-88b63198-7d38-5714-a9ff-21ba46374fd1", | ||
"name": "John", | ||
"age": int64(27), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_CreateWithIdentityAndReadWithoutIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
|
||
Description: "Test acp, create with identity, and read without identity", | ||
|
||
Actions: []any{ | ||
testUtils.AddPolicy{ | ||
|
||
Creator: Actor1Signature, | ||
|
||
Policy: ` | ||
description: a test policy which marks a collection in a database as a resource | ||
actor: | ||
name: actor | ||
resources: | ||
users: | ||
permissions: | ||
read: | ||
expr: owner + reader | ||
write: | ||
expr: owner | ||
relations: | ||
owner: | ||
types: | ||
- actor | ||
reader: | ||
types: | ||
- actor | ||
admin: | ||
manages: | ||
- reader | ||
types: | ||
- actor | ||
`, | ||
|
||
ExpectedPolicyID: "53980e762616fcffbe76307995895e862f87ef3f21d509325d1dc772a770b001", | ||
}, | ||
|
||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users @policy( | ||
id: "53980e762616fcffbe76307995895e862f87ef3f21d509325d1dc772a770b001", | ||
resource: "users" | ||
) { | ||
name: String | ||
age: Int | ||
} | ||
`, | ||
}, | ||
|
||
testUtils.CreateDoc{ | ||
Identity: Actor1Signature, | ||
|
||
Doc: `{ | ||
"name": "John", | ||
"age": 27 | ||
}`, | ||
}, | ||
|
||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
Users { | ||
_docID | ||
name | ||
age | ||
} | ||
} | ||
`, | ||
Results: []map[string]any{}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_CreateWithIdentityAndReadWithIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
|
||
Description: "Test acp, create with identity, and read with identity", | ||
|
||
Actions: []any{ | ||
testUtils.AddPolicy{ | ||
|
||
Creator: Actor1Signature, | ||
|
||
Policy: ` | ||
description: a test policy which marks a collection in a database as a resource | ||
actor: | ||
name: actor | ||
resources: | ||
users: | ||
permissions: | ||
read: | ||
expr: owner + reader | ||
write: | ||
expr: owner | ||
relations: | ||
owner: | ||
types: | ||
- actor | ||
reader: | ||
types: | ||
- actor | ||
admin: | ||
manages: | ||
- reader | ||
types: | ||
- actor | ||
`, | ||
|
||
ExpectedPolicyID: "53980e762616fcffbe76307995895e862f87ef3f21d509325d1dc772a770b001", | ||
}, | ||
|
||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users @policy( | ||
id: "53980e762616fcffbe76307995895e862f87ef3f21d509325d1dc772a770b001", | ||
resource: "users" | ||
) { | ||
name: String | ||
age: Int | ||
} | ||
`, | ||
}, | ||
|
||
testUtils.CreateDoc{ | ||
Identity: Actor1Signature, | ||
|
||
Doc: `{ | ||
"name": "John", | ||
"age": 27 | ||
}`, | ||
}, | ||
|
||
testUtils.Request{ | ||
Identity: Actor1Signature, | ||
|
||
Request: ` | ||
query { | ||
Users { | ||
_docID | ||
name | ||
age | ||
} | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
"_docID": "bae-88b63198-7d38-5714-a9ff-21ba46374fd1", | ||
"name": "John", | ||
"age": int64(27), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |