@@ -177,3 +177,44 @@ def test_admin_can_reset_user_password_via_update(db_session, client, test_app):
177177 # managed_user can sign in with new password
178178 assert _signin (client , "managed_user" , "resetpass" ).status_code == 200
179179 assert _signin (client , "managed_user" , "initialpass" ).status_code == 401
180+
181+
182+ @pytest .mark .parametrize (
183+ "test_app" ,
184+ [{"AUTH_TYPE" : "DB" , "KEEP_JWT_SECRET" : "somesecret" }],
185+ indirect = True ,
186+ )
187+ def test_admin_can_update_user_role_via_update (db_session , client , test_app ):
188+ """An admin can update a local user's role via the update endpoint."""
189+ _create_db_user (db_session , "admin_user" , "adminpass" , role = "admin" )
190+ _create_db_user (db_session , "managed_user" , "managedpass" , role = "noc" )
191+
192+ signin = _signin (client , "admin_user" , "adminpass" )
193+ assert signin .status_code == 200
194+ token = signin .json ()["accessToken" ]
195+ headers = {"Authorization" : f"Bearer { token } " }
196+
197+ response = client .put (
198+ "/auth/users/managed_user" ,
199+ json = {"role" : "admin" },
200+ headers = headers ,
201+ )
202+ assert response .status_code == 200
203+ assert response .json ()["role" ] == "admin"
204+ assert _signin (client , "managed_user" , "managedpass" ).json ()["role" ] == "admin"
205+
206+ response = client .put (
207+ "/auth/users/managed_user" ,
208+ json = {"role" : "admin" },
209+ headers = headers ,
210+ )
211+ assert response .status_code == 200
212+ assert response .json ()["role" ] == "admin"
213+
214+ response = client .put (
215+ "/auth/users/missing_user" ,
216+ json = {"role" : "admin" },
217+ headers = headers ,
218+ )
219+ assert response .status_code == 404
220+ assert response .json ()["detail" ] == "User not found"
0 commit comments