@@ -25,6 +25,7 @@ def enforcer(app_fixture):
2525 s .add (CasbinRule (ptype = "p" , v0 = "data2_admin" , v1 = "/item" , v2 = "GET" ))
2626 s .add (CasbinRule (ptype = "g" , v0 = "alice" , v1 = "data2_admin" ))
2727 s .add (CasbinRule (ptype = "g" , v0 = "users" , v1 = "data2_admin" ))
28+ s .add (CasbinRule (ptype = "g" , v0 = "group with space" , v1 = "data2_admin" ))
2829 s .commit ()
2930 s .close ()
3031
@@ -57,10 +58,12 @@ def update_callback(self):
5758 ("X-User" , "bob" , "POST" , 401 , None ),
5859 ("X-User" , "bob" , "DELETE" , 401 , None ),
5960 ("X-Idp-Groups" , "admin" , "GET" , 401 , "X-User" ),
60- ("X-Idp-Groups" , "users" , "GET" , 200 , None ),
61+ ("X-Idp-Groups" , "group with space, users" , "GET" , 200 , None ),
6162 ("X-Idp-Groups" , "noexist,testnoexist,users" , "GET" , 200 , None ),
6263 # ("X-Idp-Groups", "noexist testnoexist users", "GET", 200, None),
6364 ("X-Idp-Groups" , "noexist, testnoexist, users" , "GET" , 200 , None ),
65+ ("X-Idp-Groups" , "group with space" , "GET" , 200 , None ),
66+ ("X-Idp-Groups" , "somegroup, group with space" , "GET" , 200 , None ),
6467 ("Authorization" , "Basic Ym9iOnBhc3N3b3Jk" , "GET" , 200 , "Authorization" ),
6568 ("Authorization" , "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZGVudGl0eSI6ImJvYiJ9."
6669 "LM-CqxAM2MtT2uT3AO69rZ3WJ81nnyMQicizh4oqBwk" , "GET" , 200 , None ),
@@ -146,6 +149,21 @@ def item():
146149 assert rv .status_code == status
147150
148151
152+ @pytest .mark .parametrize (
153+ "header_string, expected_list" ,
154+ [
155+ ("noexist,testnoexist,users " , ["noexist" , "testnoexist" , "users" ]),
156+ ("noexist testnoexist users" , ["noexist" , "testnoexist" , "users" ]),
157+ ("noexist, testnoexist, users" , ["noexist" , "testnoexist" , "users" ]),
158+ ("somegroup, group with space" , ["somegroup" , "group with space" ]),
159+ ("group with space" , ["group with space" ])
160+ ]
161+ )
162+ def test_sanitize_group_headers (header_string , expected_list ):
163+ header_list = CasbinEnforcer .sanitize_group_headers (header_string )
164+ assert header_list == expected_list
165+
166+
149167def test_manager (app_fixture , enforcer ):
150168 @app_fixture .route ("/manager" , methods = ["POST" ])
151169 @enforcer .manager
@@ -214,7 +232,8 @@ def owner_loader():
214232 ("noexist, testnoexist, users" , ["noexist" , "testnoexist" , "users" ]),
215233 ("noexist, testnoexist, users" , ["noexist" , "testnoexist" , "users" ]),
216234 ("somegroup, group with space" , ["somegroup" , "group with space" ]),
217- ("group with space" , ["group with space" ])
235+ ("group with space" , ["group with space" ]),
236+ ("group 'with, space" , ["group 'with" , "space" ])
218237 ]
219238)
220239def test_sanitize_group_headers (header_string , expected_list ):
@@ -229,6 +248,13 @@ def test_sanitize_group_headers(header_string, expected_list):
229248 ("noexist testnoexist users" , ["noexist" , "testnoexist" , "users" ]),
230249 ("noexist, testnoexist, users" , ["noexist," , "testnoexist," , "users" ]),
231250 ("somegroup, group with space" , ["somegroup," , "group" , "with" , "space" ]),
251+ ('"agroup" "delimited by" "spaces"' , ["agroup" , "delimited by" , "spaces" ]),
252+ ("'agroup' 'delimited by' 'spaces'" , ["agroup" , "delimited by" , "spaces" ]),
253+ ("group'with space" , ["group'with" , "space" ]),
254+ ("group' with space" , ["group'" , "with" , "space" ]),
255+ ("'group with' space" , ["'group" , "with'" , "space" ]), # quotes must be used on all groups, not only in 1
256+ ('"group with space"' , ["group with space" ]),
257+ ("'group with space'" , ["group with space" ]),
232258 ("group with space" , ["group" , "with" , "space" ])
233259 ]
234260)
0 commit comments