Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOGL-8933/8892 Forbidden case handling added in GET user profile API for non-admin users except control user #1460

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions python/fledge/services/core/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ async def get_user(request):
user_name = request.query['username'].lower()
if user_id or user_name:
try:
if not request.is_auth_optional:
if int(request.user["role_id"]) not in [1, 5]:
if ((user_id is not None and int(request.user["id"]) != user_id)
or (user_name is not None and request.user["uname"] != user_name)):
raise web.HTTPForbidden
user = await User.Objects.get(user_id, user_name)
u = OrderedDict()
u['userId'] = user.pop('id')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ def test_login(self, fledge_url, wait_time):
# health
("GET", "/fledge/health/storage", 200), ("GET", "/fledge/health/logging", 200),
# user & roles
("GET", "/fledge/user", 403), ("GET", "/fledge/user?id=3", 200),
("GET", "/fledge/user", 403), ("GET", "/fledge/user?id=3", 200), ("GET", "/fledge/user?id=2", 403),
("GET", "/fledge/user?username={}".format(VIEW_USERNAME), 200),
("GET", "/fledge/user?username={}".format(CONTROL_USERNAME), 403),
("GET", "/fledge/user?id={}&username={}".format(3, VIEW_USERNAME), 200),
("GET", "/fledge/user?username={}&id={}".format(VIEW_USERNAME, 3), 200),
("GET", "/fledge/user?username=admin&id=1", 403),
("PUT", "/fledge/user", 500), ("PUT", "/fledge/user/1/password", 403), ("PUT", "/fledge/user/3/password", 500),
("GET", "/fledge/user/role", 403),
# auth
Expand Down Expand Up @@ -272,9 +274,10 @@ def test_login(self, fledge_url, wait_time):
# health
("GET", "/fledge/health/storage", 403), ("GET", "/fledge/health/logging", 403),
# user & roles
("GET", "/fledge/user", 403), ("GET", "/fledge/user?id=4", 200),
("GET", "/fledge/user?username={}".format(DATA_VIEW_USERNAME), 200),
("GET", "/fledge/user", 403), ("GET", "/fledge/user?id=4", 200), ("GET", "/fledge/user?id=1", 403),
("GET", "/fledge/user?username={}".format(DATA_VIEW_USERNAME), 200), ("GET", "/fledge/user?username=user", 403),
("GET", "/fledge/user?id={}&username={}".format(4, DATA_VIEW_USERNAME), 200),
("GET", "/fledge/user?id=1&username=admin", 403),
("GET", "/fledge/user?username={}&id={}".format(DATA_VIEW_USERNAME, 4), 200),
("PUT", "/fledge/user", 500), ("PUT", "/fledge/user/1/password", 403), ("PUT", "/fledge/user/4/password", 500),
("GET", "/fledge/user/role", 403),
Expand Down Expand Up @@ -433,10 +436,12 @@ def test_login(self, fledge_url, wait_time):
# health
("GET", "/fledge/health/storage", 200), ("GET", "/fledge/health/logging", 200),
# user & roles
("GET", "/fledge/user", 200), ("GET", "/fledge/user?id=5", 200),
("GET", "/fledge/user?username={}".format(CONTROL_USERNAME), 200),
("GET", "/fledge/user", 200), ("GET", "/fledge/user?id=5", 200), ("GET", "/fledge/user?id=1", 200),
("GET", "/fledge/user?username={}".format(CONTROL_USERNAME), 200), ("GET", "/fledge/user?username=admin", 200),
("GET", "/fledge/user?id={}&username={}".format(5, CONTROL_USERNAME), 200),
("GET", "/fledge/user?username={}&id={}".format(CONTROL_USERNAME, 5), 200),
("GET", "/fledge/user?username={}&id={}".format(VIEW_USERNAME, 3), 200),
("GET", "/fledge/user?id={}&username={}".format(4, DATA_VIEW_USERNAME), 200),
("PUT", "/fledge/user", 500), ("PUT", "/fledge/user/1/password", 401), ("PUT", "/fledge/user/5/password", 500),
("GET", "/fledge/user/role", 403),
# auth
Expand Down