1212 AuthorizationCheck as ConsumerAuthorizationCheck ,
1313)
1414from stytch .shared .rbac_local import (
15+ RBACConsumerPermissionError ,
1516 RBACPermissionError ,
1617 TenancyError ,
1718 perform_authorization_check ,
1819 perform_consumer_scope_authorization_check ,
19- perform_consumer_scope_authorization_check_local ,
2020 perform_scope_authorization_check ,
2121)
2222
@@ -218,7 +218,7 @@ def test_perform_scope_authorization_check(self) -> None:
218218
219219 def test_perform_consumer_scope_authorization_check (self ) -> None :
220220 with self .subTest ("has matching action but not resource" ):
221- with self .assertRaises (RBACPermissionError ):
221+ with self .assertRaises (RBACConsumerPermissionError ):
222222 # Arrange
223223 scopes = [self .write_scope .scope ]
224224 req = ConsumerAuthorizationCheck (
@@ -229,7 +229,7 @@ def test_perform_consumer_scope_authorization_check(self) -> None:
229229 perform_consumer_scope_authorization_check (self .policy , scopes , req )
230230
231231 with self .subTest ("has matching resource but not action" ):
232- with self .assertRaises (RBACPermissionError ):
232+ with self .assertRaises (RBACConsumerPermissionError ):
233233 # Arrange
234234 scopes = [self .read_scope .scope ]
235235 req = ConsumerAuthorizationCheck (
@@ -262,7 +262,7 @@ def test_perform_consumer_scope_authorization_check(self) -> None:
262262 # Assertion is that no exception is raised
263263
264264 with self .subTest ("no matching scope" ):
265- with self .assertRaises (RBACPermissionError ):
265+ with self .assertRaises (RBACConsumerPermissionError ):
266266 # Arrange
267267 scopes = ["nonexistent:scope" ]
268268 req = ConsumerAuthorizationCheck (
@@ -273,7 +273,7 @@ def test_perform_consumer_scope_authorization_check(self) -> None:
273273 perform_consumer_scope_authorization_check (self .policy , scopes , req )
274274
275275 with self .subTest ("empty scopes list" ):
276- with self .assertRaises (RBACPermissionError ):
276+ with self .assertRaises (RBACConsumerPermissionError ):
277277 # Arrange
278278 scopes = []
279279 req = ConsumerAuthorizationCheck (
@@ -293,113 +293,3 @@ def test_perform_consumer_scope_authorization_check(self) -> None:
293293 # Act
294294 perform_consumer_scope_authorization_check (self .policy , scopes , req )
295295 # Assertion is that no exception is raised
296-
297- def test_perform_consumer_scope_authorization_check_local (self ) -> None :
298- with self .subTest ("has matching action but not resource" ):
299- with self .assertRaises (RBACPermissionError ):
300- # Arrange
301- scopes = [self .write_scope .scope ]
302- req = ConsumerAuthorizationCheck (
303- resource_id = "baz" ,
304- action = "write" ,
305- )
306- # Act
307- perform_consumer_scope_authorization_check_local (
308- self .policy , scopes , req
309- )
310-
311- with self .subTest ("has matching resource but not action" ):
312- with self .assertRaises (RBACPermissionError ):
313- # Arrange
314- scopes = [self .read_scope .scope ]
315- req = ConsumerAuthorizationCheck (
316- resource_id = "foo" ,
317- action = "write" ,
318- )
319- # Act
320- perform_consumer_scope_authorization_check_local (
321- self .policy , scopes , req
322- )
323-
324- with self .subTest ("has matching resource and specific action" ):
325- # Arrange
326- scopes = [self .write_scope .scope ]
327- req = ConsumerAuthorizationCheck (
328- resource_id = "foo" ,
329- action = "write" ,
330- )
331- # Act
332- perform_consumer_scope_authorization_check_local (self .policy , scopes , req )
333- # Assertion is that no exception is raised
334-
335- with self .subTest ("has matching resource and star action" ):
336- # Arrange
337- scopes = [self .wildcard_scope .scope ]
338- req = ConsumerAuthorizationCheck (
339- resource_id = "foo" ,
340- action = "write" ,
341- )
342- # Act
343- perform_consumer_scope_authorization_check_local (self .policy , scopes , req )
344- # Assertion is that no exception is raised
345-
346- with self .subTest ("no matching scope" ):
347- with self .assertRaises (RBACPermissionError ):
348- # Arrange
349- scopes = ["nonexistent:scope" ]
350- req = ConsumerAuthorizationCheck (
351- resource_id = "foo" ,
352- action = "read" ,
353- )
354- # Act
355- perform_consumer_scope_authorization_check_local (
356- self .policy , scopes , req
357- )
358-
359- with self .subTest ("empty scopes list" ):
360- with self .assertRaises (RBACPermissionError ):
361- # Arrange
362- scopes = []
363- req = ConsumerAuthorizationCheck (
364- resource_id = "foo" ,
365- action = "read" ,
366- )
367- # Act
368- perform_consumer_scope_authorization_check_local (
369- self .policy , scopes , req
370- )
371-
372- with self .subTest ("multiple scopes with one matching" ):
373- # Arrange
374- scopes = ["nonexistent:scope" , self .read_scope .scope , "another:scope" ]
375- req = ConsumerAuthorizationCheck (
376- resource_id = "foo" ,
377- action = "read" ,
378- )
379- # Act
380- perform_consumer_scope_authorization_check_local (self .policy , scopes , req )
381- # Assertion is that no exception is raised
382-
383- with self .subTest ("bar resource with write scope" ):
384- # Arrange
385- scopes = [
386- self .write_scope .scope
387- ] # Use the write scope which includes bar resource
388- req = ConsumerAuthorizationCheck (
389- resource_id = "bar" ,
390- action = "write" ,
391- )
392- # Act
393- perform_consumer_scope_authorization_check_local (self .policy , scopes , req )
394- # Assertion is that no exception is raised
395-
396- with self .subTest ("wildcard scope with delete action" ):
397- # Arrange
398- scopes = [self .wildcard_scope .scope ] # Use the wildcard scope
399- req = ConsumerAuthorizationCheck (
400- resource_id = "foo" ,
401- action = "delete" ,
402- )
403- # Act
404- perform_consumer_scope_authorization_check_local (self .policy , scopes , req )
405- # Assertion is that no exception is raised
0 commit comments