mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-19 10:51:34 +08:00
Prevent API access with deleted key
This commit is contained in:
@@ -275,7 +275,7 @@ class UserManager(base.ModelManager, deletable.PurgableManagerMixin):
|
||||
return schema.BootstrapAdminUser()
|
||||
sa_session = sa_session or self.app.model.session
|
||||
try:
|
||||
provided_key = sa_session.query(self.app.model.APIKeys).filter(self.app.model.APIKeys.key == api_key).one()
|
||||
provided_key = sa_session.query(self.app.model.APIKeys).filter_by(key=api_key, deleted=False).one()
|
||||
except NoResultFound:
|
||||
raise exceptions.AuthenticationFailed("Provided API key is not valid.")
|
||||
if provided_key.user.deleted:
|
||||
|
||||
@@ -158,9 +158,9 @@ class TestUsersApi(ApiTestCase):
|
||||
# Delete user API key
|
||||
response = self._delete(f"users/{user_id}/api_key")
|
||||
self._assert_status_code_is(response, 204)
|
||||
# No API key anymore, so the detailed request returns no content 204
|
||||
# No API key anymore, so the detailed request returns unauthorized
|
||||
response = self._get(f"users/{user_id}/api_key/detailed")
|
||||
self._assert_status_code_is(response, 204)
|
||||
self._assert_status_code_is(response, 401)
|
||||
# create new as admin
|
||||
response = self._post(f"users/{user_id}/api_key", admin=True)
|
||||
self._assert_status_code_is_ok(response)
|
||||
|
||||
Reference in New Issue
Block a user