SaveRolesForUserEndpoint ignores Identity results and documents the wrong error status
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp, rails
- Domain
- api, authorization, backend
Research direction
Start in src/PublicApi/UserManagementEndpoints/SaveRolesForUserEndpoint.cs, where AddToRolesAsync and RemoveFromRolesAsync are called and their IdentityResult values discarded, and where the Produces declarations are set. Then read the existing tests in tests/PublicApiIntegrationTests/UserManagementEndpoints/SaveRolesForUserEndpointTest.cs. Done when an unknown role returns 400 or 404, failed IdentityResults return a non-success status, the Produces declarations match, and the new unknown-role and already-assigned tests pass.
Written by the indexing model from the issue text.
Description
Problem
PUT api/users/{userId}/roles (src/PublicApi/UserManagementEndpoints/SaveRolesForUserEndpoint.cs):
- Unknown role causes a 500. If
RolesToAddcontains a role that doesn't exist,UserManager.AddToRolesAsyncthrowsInvalidOperationException("Role X does not exist"), andExceptionMiddlewareturns that into 500 Internal Server Error. - Failed results are ignored. The
IdentityResultvalues fromAddToRolesAsyncandRemoveFromRolesAsyncare thrown away. Adding a role the user already has, or removing one they don't have, fails in Identity, but the endpoint returns 200 OK. If the add succeeds and the remove fails, the user is left partly updated. - Wrong status in the OpenAPI description. The description declares
409 Conflict, but the endpoint never returns it. When the target is the default admin user it returns400 Bad Request, which isn't declared at all. - Generic exception. When a user has no
UserName, the endpoint throws a plainSystem.Exception("Unknown user to update"), which becomes a 500.
Expected
- Return 400, or 404 for an unknown role, with an error message instead of a 500.
- Check each
IdentityResultand return a non-success status when it fails. - Make the
Produces(...)declarations match the statuses the endpoint actually returns (200/400/404).
Notes
Found while adding integration tests in #319. Once this is fixed, add tests to tests/PublicApiIntegrationTests/UserManagementEndpoints/SaveRolesForUserEndpointTest.cs for the unknown-role and already-assigned cases.
- Dominant language
- C#
- Stars
- 642
- Forks
- 320
- Avg merge
- 3h 9m
- Merged PRs (30d)
- 11
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NimblePros/eShopOnWeb
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NimblePros/eShopOnWeb#333 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
NimblePros/eShopOnWeb#332 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
NimblePros/eShopOnWeb#326 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
NimblePros/eShopOnWeb#325 ·
Maintainers usually reply within 1 day
-
Order detail page shows any user's orderPossibly taken @ardalis claimed this today. Openagent-assigned
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NimblePros/eShopOnWeb#315 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
All issues in NimblePros/eShopOnWeb
Similar issues
-
area-NavigationView bug needs-triage team-Controls
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
microsoft/microsoft-ui-xaml#12671 · 3 comments ·
Maintainers usually reply within 2 days
-
Retarget the extension to Fallout 10.5Possibly taken @ChrisonSimtian claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
aspnet/Benchmarks#2226 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day