Skip to content

Commit 071d178

Browse files
author
Tit Petric
committed
internal/policy: add restricted_types behaviour test
1 parent 2deca99 commit 071d178

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

internal/policy/Taskfile.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
---
22
version: "3"
33

4-
includes:
5-
services:
6-
taskfile: ../../docker/services/Taskfile.yml
7-
dir: ../../docker/services
8-
94
vars:
105
run: .
116

127
tasks:
138
default:
149
desc: "Run tests"
15-
deps: [ services:up ]
1610
requires:
1711
vars: [run]
1812
cmds:
19-
- defer: { task: services:down }
2013
- goimports -w .
2114
- go fmt ./...
2215
- task: test

internal/policy/apply_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,17 @@ func testPrepareApplyPolicies(tb testing.TB) (*policy.Service, []testApplyPolici
777777
sessMatch: func(t *testing.T, s *user.SessionState) {
778778
t.Helper()
779779

780+
// It should get intersection of allowed/restricted types.
780781
want := map[string]user.AccessDefinition{
781-
"a": { // It should get intersection of restricted types.
782+
"a": {
782783
AllowedTypes: []graphql.Type{
783784
{Name: "Country", Fields: []string{"code"}},
784785
{Name: "Person", Fields: []string{"name"}},
785786
},
787+
RestrictedTypes: []graphql.Type{
788+
{Name: "Dog", Fields: []string{"name", "breed"}},
789+
{Name: "Cat", Fields: []string{"name"}},
790+
},
786791
Limit: user.APILimit{},
787792
},
788793
}

internal/policy/testdata/policies.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@
4949
"height"
5050
]
5151
}
52+
],
53+
"restricted_types": [
54+
{
55+
"name": "Dog",
56+
"fields": [
57+
"name",
58+
"breed",
59+
"country"
60+
]
61+
},
62+
{
63+
"name": "Cat",
64+
"fields": [
65+
"name",
66+
"country"
67+
]
68+
}
5269
]
5370
}
5471
},
@@ -73,6 +90,21 @@
7390
"mass"
7491
]
7592
}
93+
],
94+
"restricted_types": [
95+
{
96+
"name": "Dog",
97+
"fields": [
98+
"name",
99+
"breed"
100+
]
101+
},
102+
{
103+
"name": "Cat",
104+
"fields": [
105+
"name"
106+
]
107+
}
76108
]
77109
}
78110
},

0 commit comments

Comments
 (0)