@@ -111,6 +111,7 @@ def test_get_policy_matching_function(self):
111111 e .get_policy (),
112112 [
113113 ["admin" , "domain.*" , "data1" , "read" ],
114+ ["user" , "domain.*" , "data3" , "read" ],
114115 ["user" , "domain.1" , "data2" , "read" ],
115116 ["user" , "domain.1" , "data2" , "write" ],
116117 ],
@@ -127,21 +128,26 @@ def test_get_policy_matching_function(self):
127128 [["alice" , "user" , "*" ]],
128129 )
129130
130- # first p record matches to domain.3
131+ # first and second p record matches to domain.3
131132 self .assertEqual (
132133 e .get_filtered_policy (1 , partial (km2_fn , "domain.3" )),
133- [["admin" , "domain.*" , "data1" , "read" ]],
134- )
135-
136- # first and second p record should be matched to (.., domain.1, read)
137- self .assertEqual (
138- e .get_filtered_policy (1 , partial (km2_fn , "domain.1" ), "" , "read" ),
139134 [
140135 ["admin" , "domain.*" , "data1" , "read" ],
141- ["user" , "domain.1 " , "data2 " , "read" ],
136+ ["user" , "domain.* " , "data3 " , "read" ],
142137 ],
143138 )
144139
140+ self .assertEqual (
141+ sorted (e .get_filtered_policy (1 , partial (km2_fn , "domain.1" ), "" , "read" )),
142+ sorted (
143+ [
144+ ["admin" , "domain.*" , "data1" , "read" ],
145+ ["user" , "domain.1" , "data2" , "read" ],
146+ ["user" , "domain.*" , "data3" , "read" ],
147+ ]
148+ ),
149+ )
150+
145151 def test_get_policy_multiple_matching_functions (self ):
146152 e = self .get_enforcer (
147153 get_examples ("rbac_with_domain_and_policy_pattern_model.conf" ),
@@ -152,6 +158,7 @@ def test_get_policy_multiple_matching_functions(self):
152158 e .get_policy (),
153159 [
154160 ["admin" , "domain.*" , "data1" , "read" ],
161+ ["user" , "domain.*" , "data3" , "read" ],
155162 ["user" , "domain.1" , "data2" , "read" ],
156163 ["user" , "domain.1" , "data2" , "write" ],
157164 ],
@@ -160,30 +167,47 @@ def test_get_policy_multiple_matching_functions(self):
160167 km2_fn = casbin .util .key_match2_func
161168
162169 self .assertEqual (
163- e .get_filtered_policy (
164- 1 , partial (km2_fn , "domain.2" ), lambda a : "data" in a
170+ sorted (
171+ e .get_filtered_policy (
172+ 1 , partial (km2_fn , "domain.2" ), lambda a : "data" in a
173+ )
174+ ),
175+ sorted (
176+ [
177+ ["admin" , "domain.*" , "data1" , "read" ],
178+ ["user" , "domain.*" , "data3" , "read" ],
179+ ]
165180 ),
166- [["admin" , "domain.*" , "data1" , "read" ]],
167181 )
168182
169183 self .assertEqual (
170- e .get_filtered_policy (
171- 1 , partial (km2_fn , "domain.1" ), lambda a : "data" in a , "read"
184+ sorted (
185+ e .get_filtered_policy (
186+ 1 , partial (km2_fn , "domain.1" ), lambda a : "data" in a , "read"
187+ )
188+ ),
189+ sorted (
190+ [
191+ ["admin" , "domain.*" , "data1" , "read" ],
192+ ["user" , "domain.1" , "data2" , "read" ],
193+ ["user" , "domain.*" , "data3" , "read" ],
194+ ]
172195 ),
173- [
174- ["admin" , "domain.*" , "data1" , "read" ],
175- ["user" , "domain.1" , "data2" , "read" ],
176- ],
177196 )
178197
179198 self .assertEqual (
180- e .get_filtered_policy (
181- 1 , partial (km2_fn , "domain.1" ), "" , "reading" .startswith
199+ sorted (
200+ e .get_filtered_policy (
201+ 1 , partial (km2_fn , "domain.1" ), "" , "reading" .startswith
202+ )
203+ ),
204+ sorted (
205+ [
206+ ["admin" , "domain.*" , "data1" , "read" ],
207+ ["user" , "domain.1" , "data2" , "read" ],
208+ ["user" , "domain.*" , "data3" , "read" ],
209+ ]
182210 ),
183- [
184- ["admin" , "domain.*" , "data1" , "read" ],
185- ["user" , "domain.1" , "data2" , "read" ],
186- ],
187211 )
188212
189213 def test_modify_policy_api (self ):
0 commit comments