Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Return a 404 for admin api user lookup if user not found (#6901)
Browse files Browse the repository at this point in the history
* commit 'd8994942f':
  Return a 404 for admin api user lookup if user not found (#6901)
  Move the warning at the top of the release changes
  • Loading branch information
anoadragon453 committed Mar 23, 2020
2 parents 279521a + d899494 commit dbf10b0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
5 changes: 2 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Synapse 1.10.0 (2020-02-12)
===========================

**WARNING to client developers**: As of this release Synapse validates `client_secret` parameters in the Client-Server API as per the spec. See [\#6766](https://github.com/matrix-org/synapse/issues/6766) for details.

Updates to the Docker image
---------------------------

Expand Down Expand Up @@ -54,9 +56,6 @@ Internal Changes
Synapse 1.10.0rc1 (2020-01-31)
==============================

**WARNING to client developers**: As of this release Synapse validates `client_secret` parameters in the Client-Server API as per the spec. See [\#6766](https://github.com/matrix-org/synapse/issues/6766) for details.


Features
--------

Expand Down
1 change: 1 addition & 0 deletions changelog.d/6901.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return a 404 instead of 200 for querying information of a non-existant user through the admin API.
5 changes: 4 additions & 1 deletion synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from six.moves import http_client

from synapse.api.constants import UserTypes
from synapse.api.errors import Codes, SynapseError
from synapse.api.errors import Codes, NotFoundError, SynapseError
from synapse.http.servlet import (
RestServlet,
assert_params_in_dict,
Expand Down Expand Up @@ -152,6 +152,9 @@ async def on_GET(self, request, user_id):

ret = await self.admin_handler.get_user(target_user)

if not ret:
raise NotFoundError("User not found")

return 200, ret

async def on_PUT(self, request, user_id):
Expand Down
16 changes: 16 additions & 0 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,22 @@ def test_requester_is_no_admin(self):
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
self.assertEqual("You are not a server admin", channel.json_body["error"])

def test_user_does_not_exist(self):
"""
Tests that a lookup for a user that does not exist returns a 404
"""
self.hs.config.registration_shared_secret = None

request, channel = self.make_request(
"GET",
"/_synapse/admin/v2/users/@unknown_person:test",
access_token=self.admin_user_tok,
)
self.render(request)

self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual("M_NOT_FOUND", channel.json_body["errcode"])

def test_requester_is_admin(self):
"""
If the user is a server admin, a new user is created.
Expand Down

0 comments on commit dbf10b0

Please sign in to comment.