fix(mobile-api): stop admins widening their own access
- A non-super admin cannot change the roles on their own account (403 OWN_ROLES).
- ROLE_ADMIN and ROLE_MEMBER cannot be assigned (400 UNKNOWN_ROLE, as if absent).
- A non-super admin cannot change the grants of a role they hold (403 OWN_ROLE);
this replaces the BO_ROLES lock-out check, which it makes unreachable.
- POST /api/admin/users/{id}/changePassword is removed; the emailed reset stays.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
816c8bcb5e
commit
4c48ebea2e
9 files changed
+114
-70
No files matched your search
+3
-3
@@ -129,9 +129,9 @@ class AdminRoleControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void putModules_lockoutAnswers400() throws Exception {
|
||||
when(acl.updateGrants(eq(4L), any())).thenThrow(new CodedResponseStatusException(HttpStatus.BAD_REQUEST, "lockout", "ACL_LOCKOUT"));
|
||||
void putModules_ownRoleAnswers403() throws Exception {
|
||||
when(acl.updateGrants(eq(4L), any())).thenThrow(new CodedResponseStatusException(HttpStatus.FORBIDDEN, "own role", "OWN_ROLE"));
|
||||
mvc.perform(put("/api/admin/roles/4/modules").contentType(MediaType.APPLICATION_JSON).content("{\"moduleIds\":[]}"))
|
||||
.andExpect(status().isBadRequest());
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -99,10 +99,10 @@ class AdminUserControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void changePassword_returnsUpdated() throws Exception {
|
||||
when(users.changePassword(5L, "Str0ng#Pass")).thenReturn(1);
|
||||
void changePassword_endpointNoLongerExists() throws Exception {
|
||||
mvc.perform(post("/api/admin/users/5/changePassword").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"password\":\"Str0ng#Pass\"}"))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.updated").value(1));
|
||||
.andExpect(status().is4xxClientError());
|
||||
org.mockito.Mockito.verifyNoInteractions(users);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user