forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreject_missing_dpi_test.go
147 lines (122 loc) · 3.14 KB
/
reject_missing_dpi_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// 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"
)
func TestACP_AddDPISchema_WhereNoPolicyWasAdded_SchemaRejected(t *testing.T) {
nonExistingPolicyID := "66f3e364004a181e9b129f65dea317322d2285226e926d7e8cdfd644954e4262"
test := testUtils.TestCase{
Description: "Test acp, add dpi schema, but no policy was added, reject schema",
Actions: []any{
testUtils.SchemaUpdate{
Schema: fmt.Sprintf(`
type Users @policy(
id: "%s",
resource: "users"
) {
name: String
age: Int
}
`,
nonExistingPolicyID,
),
ExpectedError: "policyID specified does not exist with acp",
},
testUtils.IntrospectionRequest{
Request: `
query {
__type (name: "Users") {
name
fields {
name
type {
name
kind
}
}
}
}
`,
ExpectedData: map[string]any{
"__type": nil, // NOTE: No "Users" should exist.
},
},
},
}
testUtils.ExecuteTestCase(t, test)
}
func TestACP_AddDPISchema_WhereAPolicyWasAddedButLinkedPolicyWasNotAdded_SchemaRejected(t *testing.T) {
incorrectPolicyID := "66f3e364004a181e9b129f65dea317322d2285226e926d7e8cdfd644954e4262"
test := testUtils.TestCase{
Description: "Test acp, add dpi schema, but specify incorrect policy ID, reject schema",
Actions: []any{
testUtils.AddPolicy{
Identity: testUtils.ClientIdentity(1),
Policy: `
name: test
description: A Valid Defra Policy Interface (DPI)
actor:
name: actor
resources:
users:
permissions:
read:
expr: owner + reader
write:
expr: owner
relations:
owner:
types:
- actor
reader:
types:
- actor
`,
},
testUtils.SchemaUpdate{
Schema: fmt.Sprintf(`
type Users @policy(
id: "%s",
resource: "users"
) {
name: String
age: Int
}
`,
incorrectPolicyID,
),
ExpectedError: "policyID specified does not exist with acp",
},
testUtils.IntrospectionRequest{
Request: `
query {
__type (name: "Users") {
name
fields {
name
type {
name
kind
}
}
}
}
`,
ExpectedData: map[string]any{
"__type": nil, // NOTE: No "Users" should exist.
},
},
},
}
testUtils.ExecuteTestCase(t, test)
}