@@ -317,6 +317,24 @@ async def identity_callback(identity: Optional[str]) -> UserDetails:
317317 assert r .msg == "Test"
318318
319319
320+ async def test_update_many_resource_finegrained_permission ( # type: ignore[no-any-unimported]
321+ create_admin_client : _CreateClient , login : _Login ) -> None :
322+ async def identity_callback (identity : Optional [str ]) -> UserDetails :
323+ assert identity == "admin"
324+ return {"permissions" : {"admin.*" , "~admin.dummy2.msg.edit" }}
325+
326+ admin_client = await create_admin_client (identity_callback )
327+
328+ assert admin_client .app
329+ url = admin_client .app ["admin" ].router ["dummy2_update_many" ].url_for ()
330+ h = await login (admin_client )
331+ p = {"ids" : "[1]" , "data" : json .dumps ({"msg" : "ABC" })}
332+ async with admin_client .put (url , params = p , headers = h ) as resp :
333+ assert resp .status == 403
334+ # TODO(aiohttp-security05)
335+ # expected = "403: User does not have 'admin.dummy2.msg.edit' permission"
336+
337+
320338async def test_delete_resource_filtered_permission (create_admin_client : _CreateClient , # type: ignore[no-any-unimported] # noqa: B950
321339 login : _Login ) -> None :
322340 async def identity_callback (identity : Optional [str ]) -> UserDetails :
@@ -543,6 +561,50 @@ async def identity_callback(identity: Optional[str]) -> UserDetails:
543561 assert resp .status == 200
544562
545563
564+ async def test_permission_filter_update_many ( # type: ignore[no-any-unimported]
565+ create_admin_client : _CreateClient , login : _Login
566+ ) -> None :
567+ async def identity_callback (identity : Optional [str ]) -> UserDetails :
568+ return {"permissions" : ("admin.*" , 'admin.dummy2.*|msg="Test"' )}
569+
570+ admin_client = await create_admin_client (identity_callback )
571+
572+ assert admin_client .app
573+ url = admin_client .app ["admin" ].router ["dummy2_update_many" ].url_for ()
574+ h = await login (admin_client )
575+ p = {"ids" : "[3]" , "data" : json .dumps ({"msg" : "Test" })}
576+ async with admin_client .put (url , params = p , headers = h ) as resp :
577+ assert resp .status == 403
578+ p = {"ids" : "[1]" , "data" : json .dumps ({"msg" : "Foo" })}
579+ async with admin_client .put (url , params = p , headers = h ) as resp :
580+ assert resp .status == 403
581+ p = {"ids" : "[1, 2]" , "data" : json .dumps ({"msg" : "Test" })}
582+ async with admin_client .put (url , params = p , headers = h ) as resp :
583+ assert resp .status == 200
584+
585+
586+ async def test_permission_filter_update_many2 ( # type: ignore[no-any-unimported]
587+ create_admin_client : _CreateClient , login : _Login
588+ ) -> None :
589+ async def identity_callback (identity : Optional [str ]) -> UserDetails :
590+ return {"permissions" : ("admin.*" , 'admin.dummy2.edit|msg="Test"' )}
591+
592+ admin_client = await create_admin_client (identity_callback )
593+
594+ assert admin_client .app
595+ url = admin_client .app ["admin" ].router ["dummy2_update_many" ].url_for ()
596+ h = await login (admin_client )
597+ p = {"ids" : "[3]" , "data" : json .dumps ({"msg" : "Test" })}
598+ async with admin_client .put (url , params = p , headers = h ) as resp :
599+ assert resp .status == 403
600+ p = {"ids" : "[1]" , "data" : json .dumps ({"msg" : "Foo" })}
601+ async with admin_client .put (url , params = p , headers = h ) as resp :
602+ assert resp .status == 403
603+ p = {"ids" : "[1, 2]" , "data" : json .dumps ({"msg" : "Test" })}
604+ async with admin_client .put (url , params = p , headers = h ) as resp :
605+ assert resp .status == 200
606+
607+
546608async def test_permission_filter_delete (create_admin_client : _CreateClient , # type: ignore[no-any-unimported] # noqa: B950
547609 login : _Login ) -> None :
548610 async def identity_callback (identity : Optional [str ]) -> UserDetails :
@@ -823,3 +885,43 @@ async def identity_callback(identity: Optional[str]) -> UserDetails:
823885 assert r is None
824886 r = await sess .get (admin_client .app ["model2" ], 5 )
825887 assert r .msg == "Test"
888+
889+
890+ async def test_permission_filter_field_update_many ( # type: ignore[no-any-unimported]
891+ create_admin_client : _CreateClient , login : _Login
892+ ) -> None :
893+ async def identity_callback (identity : Optional [str ]) -> UserDetails :
894+ return {"permissions" : ("admin.*" , "admin.dummy2.msg.*|id=1|id=2" )}
895+
896+ admin_client = await create_admin_client (identity_callback )
897+
898+ assert admin_client .app
899+ url = admin_client .app ["admin" ].router ["dummy2_update_many" ].url_for ()
900+ h = await login (admin_client )
901+ p = {"ids" : "[3]" , "data" : json .dumps ({"msg" : "Spam" })}
902+ async with admin_client .put (url , params = p , headers = h ) as resp :
903+ assert resp .status == 403
904+ p = {"ids" : "[1, 2]" , "data" : json .dumps ({"msg" : "Spam" })}
905+ async with admin_client .put (url , params = p , headers = h ) as resp :
906+ assert resp .status == 200
907+ assert await resp .json () == {"data" : [1 , 2 ]}
908+
909+
910+ async def test_permission_filter_field_update_many2 ( # type: ignore[no-any-unimported]
911+ create_admin_client : _CreateClient , login : _Login
912+ ) -> None :
913+ async def identity_callback (identity : Optional [str ]) -> UserDetails :
914+ return {"permissions" : ("admin.*" , "admin.dummy2.msg.edit|id=1|id=2" )}
915+
916+ admin_client = await create_admin_client (identity_callback )
917+
918+ assert admin_client .app
919+ url = admin_client .app ["admin" ].router ["dummy2_update_many" ].url_for ()
920+ h = await login (admin_client )
921+ p = {"ids" : "[3]" , "data" : json .dumps ({"msg" : "Spam" })}
922+ async with admin_client .put (url , params = p , headers = h ) as resp :
923+ assert resp .status == 403
924+ p = {"ids" : "[1, 2]" , "data" : json .dumps ({"msg" : "Spam" })}
925+ async with admin_client .put (url , params = p , headers = h ) as resp :
926+ assert resp .status == 200
927+ assert await resp .json () == {"data" : [1 , 2 ]}
0 commit comments