From 47fd646030743c9dce5aa7b3d81bf557b1f70b3c Mon Sep 17 00:00:00 2001 From: Arvindh <30824765+arvindh123@users.noreply.github.com> Date: Wed, 7 Dec 2022 17:01:01 +0530 Subject: [PATCH] MF-1678 - Fetching users returns an invalid status code response (#1679) * fix: get /users authorize err code Signed-off-by: Arvindh * add: test case for forbidden request in GET /users Signed-off-by: Arvindh * update: api docs of GET /users Signed-off-by: Arvindh * add: test case for forbidden request in GET /users Signed-off-by: Arvindh Signed-off-by: Arvindh --- api/openapi/users.yml | 6 +++--- users/service.go | 2 +- users/service_test.go | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/api/openapi/users.yml b/api/openapi/users.yml index 9133de39..20c3c5d9 100644 --- a/api/openapi/users.yml +++ b/api/openapi/users.yml @@ -48,9 +48,9 @@ paths: '400': description: Failed due to malformed query parameters. '401': - description: | - Missing or invalid access token provided. - This endpoint is available only for administrators. + description: Missing or invalid access token provided. + '403': + description: This endpoint is available only for administrators. '404': description: A non-existent entity request. '422': diff --git a/users/service.go b/users/service.go index 335d9075..708e195e 100644 --- a/users/service.go +++ b/users/service.go @@ -252,7 +252,7 @@ func (svc usersService) ListUsers(ctx context.Context, token string, pm PageMeta } if err := svc.authorize(ctx, id.id, "authorities", "member"); err != nil { - return UserPage{}, errors.Wrap(errors.ErrAuthentication, err) + return UserPage{}, err } return svc.users.RetrieveAll(ctx, pm.Status, pm.Offset, pm.Limit, nil, pm.Email, pm.Metadata) } diff --git a/users/service_test.go b/users/service_test.go index ae85d5d1..45499fbc 100644 --- a/users/service_test.go +++ b/users/service_test.go @@ -246,6 +246,11 @@ func TestListUsers(t *testing.T) { size: 0, err: nil, }, + "list users with unauthorized token": { + token: unauthzToken, + size: 0, + err: errors.ErrAuthorization, + }, "list user with emtpy token": { token: "", size: 0, @@ -257,6 +262,11 @@ func TestListUsers(t *testing.T) { limit: nUsers, size: nUsers - 6, }, + "list using non-existent user": { + token: token, + email: nonExistingUser.Email, + err: errors.ErrNotFound, + }, } for desc, tc := range cases {