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
@@ -45,9 +45,9 @@ Babyboo source: `~/Projects/babyboo` (read only). All tasks run serially; most t
|
||||
|
||||
## 8. Review follow-up: close self-escalation
|
||||
|
||||
- [ ] 8.1 In `mobile-api`: delete `POST /api/admin/users/{id}/changePassword` and `AdminUserService.changePassword`; in `AdminUserService` refuse (403, `OWN_ROLES`) a non-super caller whose update changes the role set on their own account, and refuse (400, `UNKNOWN_ROLE`) `ROLE_ADMIN` or `ROLE_MEMBER` on create and update; in `AdminAclService.updateGrants` refuse (403, `OWN_ROLE`) a non-super caller editing a role they hold, and delete `requireNoLockout`, which that rule makes unreachable. Tests first for each new scenario. Verify: `mvn -T 1C -B -q -pl solvway-mobile-api -am verify` exits 0.
|
||||
- [x] 8.1 In `mobile-api`: delete `POST /api/admin/users/{id}/changePassword` and `AdminUserService.changePassword`; in `AdminUserService` refuse (403, `OWN_ROLES`) a non-super caller whose update changes the role set on their own account, and refuse (400, `UNKNOWN_ROLE`) `ROLE_ADMIN` or `ROLE_MEMBER` on create and update; in `AdminAclService.updateGrants` refuse (403, `OWN_ROLE`) a non-super caller editing a role they hold, and delete `requireNoLockout`, which that rule makes unreachable. Tests first for each new scenario. Verify: `mvn -T 1C -B -q -pl solvway-mobile-api -am verify` exits 0.
|
||||
- Scope: `solvway-mobile-api/src/**/admin/**`, `solvway-mobile-api/src/**/service/Admin*`
|
||||
- [ ] 8.2 In the portal: delete the change-password route, `ChangePasswordDialog`, `changeAdminUserPassword` and the button on the edit-user page; the emailed reset stays. Verify: `npm run lint && npx tsc --noEmit && npx vitest run` exit 0.
|
||||
- [x] 8.2 In the portal: delete the change-password route, `ChangePasswordDialog`, `changeAdminUserPassword` and the button on the edit-user page; the emailed reset stays. Verify: `npm run lint && npx tsc --noEmit && npx vitest run` exit 0.
|
||||
- Scope: `solvway-admin-portal/**`
|
||||
|
||||
## Workflow follow-up
|
||||
|
||||
-1
@@ -15,7 +15,6 @@ public class RestApiSystemServiceConstants {
|
||||
public static final String API_REST_SYSTEM_MODULE_ADD_MODULE_ROLE = "/module/addModuleRole/{moduleId}/{roleId}";
|
||||
public static final String API_REST_SYSTEM_MODULE_DELETE_MODULE_ROLE = "/module/deleteModuleRole/{moduleId}/{roleId}";
|
||||
public static final String API_REST_SYSTEM_USER_SAVE = "/user/save";
|
||||
public static final String API_REST_SYSTEM_USER_UPDATE_USER_PASSWORD = "/user/updateUserPassword";
|
||||
public static final String API_REST_SYSTEM_USER_FIND_EXIST_BY_USERNAME = "/user/findExistByUsername/{username}";
|
||||
public static final String API_REST_SYSTEM_USER_FIND_BY_USERNAME_WITH_PASSWORD = "/user/findByUsernameWithPassword/{username}";
|
||||
public static final String API_REST_SYSTEM_USER_UPDATE_MEMBER_PHONE_VERIFIED = "/user/updatePhoneVerified";
|
||||
|
||||
-6
@@ -49,12 +49,6 @@ public class AdminUserController {
|
||||
return ResponseEntity.ok(adminUserService.update(id, request));
|
||||
}
|
||||
|
||||
@AppAuth
|
||||
@PostMapping("/users/{id}/changePassword")
|
||||
public ResponseEntity<Map<String, Object>> changePassword(@PathVariable Long id, @RequestBody Map<String, String> body) {
|
||||
return ResponseEntity.ok(Map.of("updated", adminUserService.changePassword(id, body.get("password"))));
|
||||
}
|
||||
|
||||
@AppAuth
|
||||
@PostMapping("/users/{id}/resetPassword")
|
||||
public ResponseEntity<Map<String, Object>> resetPassword(@PathVariable Long id) {
|
||||
|
||||
+5
-14
@@ -22,7 +22,6 @@ import java.util.Set;
|
||||
public class AdminAclService {
|
||||
private static final ParameterizedTypeReference<List<Map<String, Object>>> MAP_LIST = new ParameterizedTypeReference<>() {};
|
||||
private static final String AREA = "BO";
|
||||
private static final String ROLES_MODULE = "BO_ROLES";
|
||||
private static final long SUPER_ADMIN_ROLE_ID = 1L;
|
||||
private static final long ROLE_ADMIN_ID = 2L;
|
||||
|
||||
@@ -45,6 +44,11 @@ public class AdminAclService {
|
||||
User caller = adminAuthenticationService.loadUserByToken(HttpReqRespUtils.getJwtToken());
|
||||
if (caller == null) throw error(HttpStatus.UNAUTHORIZED, "Not signed in", "UNAUTHORIZED");
|
||||
|
||||
boolean isSuper = caller.getRoles() != null && caller.getRoles().stream().anyMatch(r -> r.getId() != null && r.getId() == SUPER_ADMIN_ROLE_ID);
|
||||
if (!isSuper && caller.getRoles() != null && caller.getRoles().stream().anyMatch(r -> r.getId() != null && r.getId() != ROLE_ADMIN_ID && r.getId().equals(roleId))) {
|
||||
throw error(HttpStatus.FORBIDDEN, "You cannot change the access of a role you hold", "OWN_ROLE");
|
||||
}
|
||||
|
||||
List<Map<String, Object>> modules = modules();
|
||||
Set<Long> known = new HashSet<>();
|
||||
Set<Long> current = new HashSet<>();
|
||||
@@ -54,7 +58,6 @@ public class AdminAclService {
|
||||
}
|
||||
Set<Long> wanted = new HashSet<>(moduleIds);
|
||||
if (!known.containsAll(wanted)) throw error(HttpStatus.BAD_REQUEST, "Unknown back-office module", "UNKNOWN_MODULE");
|
||||
requireNoLockout(caller, roleId, wanted, modules);
|
||||
|
||||
// ponytail: not atomic, adds run before deletes and a failure midway leaves a partial grant; a repeated PUT converges. Upgrade: one services-system endpoint that replaces grants in a transaction.
|
||||
for (Long id : wanted) if (!current.contains(id)) call(RestApiSystemServiceConstants.API_REST_SYSTEM_MODULE_ADD_MODULE_ROLE, id, roleId);
|
||||
@@ -62,18 +65,6 @@ public class AdminAclService {
|
||||
return getGrantTree(roleId);
|
||||
}
|
||||
|
||||
/** A non-super caller must still reach BO_ROLES through one of their roles (role 2 is on every admin and grants nothing). */
|
||||
private static void requireNoLockout(User caller, Long roleId, Set<Long> wanted, List<Map<String, Object>> modules) {
|
||||
if (caller.getRoles() == null || caller.getRoles().stream().anyMatch(r -> r.getId() != null && r.getId() == SUPER_ADMIN_ROLE_ID)) return;
|
||||
Set<Long> held = new HashSet<>();
|
||||
caller.getRoles().stream().map(r -> r.getId()).filter(i -> i != null && i != ROLE_ADMIN_ID).forEach(held::add);
|
||||
if (!held.contains(roleId)) return;
|
||||
Map<String, Object> rolesModule = modules.stream().filter(m -> ROLES_MODULE.equals(m.get("name"))).findFirst().orElse(null);
|
||||
if (rolesModule == null) return;
|
||||
boolean stillGranted = held.stream().anyMatch(r -> r.equals(roleId) ? wanted.contains(AdminRoleService.idOf(rolesModule)) : grantedTo(rolesModule, r));
|
||||
if (!stillGranted) throw error(HttpStatus.BAD_REQUEST, "This change would remove your own access to role management", "ACL_LOCKOUT");
|
||||
}
|
||||
|
||||
/** Hidden roles (ROLE_MEMBER, ROLE_ADMIN) look absent, as in the role list. */
|
||||
private void requireVisibleRole(Long roleId) {
|
||||
if (AdminRoleService.isHidden(adminRoleService.find(roleId))) {
|
||||
|
||||
+18
-11
@@ -17,8 +17,10 @@ import org.springframework.util.StringUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Admin users for the portal. Users travel as maps so fields the core {@link User} lacks (status) survive
|
||||
@@ -117,6 +119,7 @@ public class AdminUserService {
|
||||
User caller = caller();
|
||||
Map<String, Object> user = loadManaged(id, caller);
|
||||
requireSuperToGrant(caller, r.roles());
|
||||
requireOwnRolesUnchanged(caller, id, user, r.roles());
|
||||
if (r.enabled() != null && !r.enabled() && caller.getId() != null && caller.getId().equals(id)) {
|
||||
throw error(HttpStatus.BAD_REQUEST, "You cannot deactivate your own account", "SELF_DEACTIVATION");
|
||||
}
|
||||
@@ -143,16 +146,6 @@ public class AdminUserService {
|
||||
return adminAuthenticationService.resetAdminPassword((String) user.get("username"), (String) user.get("email"));
|
||||
}
|
||||
|
||||
public int changePassword(Long id, String password) {
|
||||
loadManaged(id, caller());
|
||||
ResponseEntity<Integer> ent = restTemplateUtil.postForEntity(
|
||||
url(RestApiSystemServiceConstants.API_REST_SYSTEM_USER_UPDATE_USER_PASSWORD), Integer.class,
|
||||
Map.of("userId", id, "password", password == null ? "" : password));
|
||||
int updated = ent.getBody() == null ? 0 : ent.getBody();
|
||||
if (updated == 0) throw error(HttpStatus.BAD_REQUEST, "Password does not meet the password rules", "PASSWORD_RULES");
|
||||
return updated;
|
||||
}
|
||||
|
||||
private Map<String, Object> load(Long id) {
|
||||
Map<String, Object> user = get(RestApiSystemServiceConstants.API_REST_SYSTEM_USER_FIND_BY_ID, id);
|
||||
if (user == null || !"A".equals(user.get("type"))) throw error(HttpStatus.NOT_FOUND, "User not found", "USER_NOT_FOUND");
|
||||
@@ -179,6 +172,20 @@ public class AdminUserService {
|
||||
}
|
||||
}
|
||||
|
||||
/** A non-super admin may not change their own roles; hidden roles are not part of what they could change. */
|
||||
private static void requireOwnRolesUnchanged(User caller, Long id, Map<String, Object> stored, List<AdminRoleRef> requested) {
|
||||
if (requested == null || isSuper(caller) || caller.getId() == null || !caller.getId().equals(id)) return;
|
||||
Set<Long> current = new HashSet<>();
|
||||
if (stored.get("roles") instanceof List<?> l) {
|
||||
for (Object o : l) {
|
||||
if (o instanceof Map<?, ?> m && m.get("id") instanceof Number n && !AdminRoleService.isHidden((Map<String, Object>) m)) current.add(n.longValue());
|
||||
}
|
||||
}
|
||||
Set<Long> wanted = new HashSet<>();
|
||||
requested.forEach(x -> wanted.add(x.id()));
|
||||
if (!wanted.equals(current)) throw error(HttpStatus.FORBIDDEN, "You cannot change your own roles", "OWN_ROLES");
|
||||
}
|
||||
|
||||
private static CodedResponseStatusException superRequired(String reason) {
|
||||
return error(HttpStatus.FORBIDDEN, reason, "SUPER_ADMIN_REQUIRED");
|
||||
}
|
||||
@@ -189,7 +196,7 @@ public class AdminUserService {
|
||||
List<Map<String, Object>> out = new ArrayList<>();
|
||||
for (AdminRoleRef ref : refs) {
|
||||
out.add((stored == null ? List.<Map<String, Object>>of() : stored).stream()
|
||||
.filter(m -> m.get("id") instanceof Number n && ref.id() != null && n.longValue() == ref.id())
|
||||
.filter(m -> m.get("id") instanceof Number n && ref.id() != null && n.longValue() == ref.id() && !AdminRoleService.isHidden(m))
|
||||
.findFirst().orElseThrow(() -> error(HttpStatus.BAD_REQUEST, "Unknown role " + ref.id(), "UNKNOWN_ROLE")));
|
||||
}
|
||||
return out;
|
||||
|
||||
+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);
|
||||
}
|
||||
}
|
||||
+11
-16
@@ -196,28 +196,23 @@ class AdminAclServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_removingBoRolesFromTheCallersOnlyGrantingRoleIsALockout() {
|
||||
caller(5, 2); // role 2 is attached to every admin and does not count
|
||||
assertCoded(() -> service.updateGrants(5L, List.of()), HttpStatus.BAD_REQUEST, "ACL_LOCKOUT");
|
||||
void update_nonSuperCallerEditingARoleTheyHoldIsRefused() {
|
||||
caller(5, 2); // role 2 is attached to every admin and is ignored
|
||||
assertCoded(() -> service.updateGrants(5L, List.of()), HttpStatus.FORBIDDEN, "OWN_ROLE");
|
||||
verifyNothingChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_removingBoRolesIsFineWhenAnotherCallerRoleStillGrantsIt() {
|
||||
stubModules(
|
||||
module(ROOT, "BO_ROOT", null, 1),
|
||||
module(USERS, "BO_USERS", ROOT, 1, 4),
|
||||
module(ROLES, "BO_ROLES", ROOT, 1, 5, 6));
|
||||
void update_ownRoleIsRefusedEvenWhenAnotherCallerRoleGrantsBoRoles() {
|
||||
caller(5, 6, 2);
|
||||
service.updateGrants(5L, List.of());
|
||||
verify(rest).getForEntity(eq(DEL), eq(Integer.class), eq(ROLES), eq(5L));
|
||||
assertCoded(() -> service.updateGrants(5L, List.of()), HttpStatus.FORBIDDEN, "OWN_ROLE");
|
||||
verifyNothingChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_keepingBoRolesOnTheCallersRoleIsFine() {
|
||||
service.updateGrants(5L, List.of(ROLES, USERS));
|
||||
verify(rest).getForEntity(eq(ADD), eq(Integer.class), eq(USERS), eq(5L));
|
||||
verify(rest, never()).getForEntity(eq(DEL), eq(Integer.class), any(), any());
|
||||
void update_ownRoleIsRefusedEvenWhenTheChangeKeepsBoRoles() {
|
||||
assertCoded(() -> service.updateGrants(5L, List.of(ROLES, USERS)), HttpStatus.FORBIDDEN, "OWN_ROLE");
|
||||
verifyNothingChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,8 +222,8 @@ class AdminAclServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_superAdminCallerIsNotSubjectToLockout() {
|
||||
caller(1);
|
||||
void update_superAdminCallerMayEditARoleTheyHold() {
|
||||
caller(1, 5);
|
||||
service.updateGrants(5L, List.of());
|
||||
verify(rest).getForEntity(eq(DEL), eq(Integer.class), eq(ROLES), eq(5L));
|
||||
}
|
||||
|
||||
+72
-14
@@ -43,7 +43,6 @@ class AdminUserServiceTest {
|
||||
private static final String BY_USERNAME = "/user/findByUsername/{username}";
|
||||
private static final String BY_EMAIL = "/user/findByEmail/{email}";
|
||||
private static final String BY_EMAIL_NOT = "/user/findByEmailAndIdNot/{email}/{id}";
|
||||
private static final String UPDATE_PWD = "/user/updateUserPassword";
|
||||
|
||||
private RestTemplateCustomUtil rest;
|
||||
private AdminAuthenticationService auth;
|
||||
@@ -497,9 +496,7 @@ class AdminUserServiceTest {
|
||||
assertCoded(() -> service.update(6L, new AdminUserRequest("X", null, null, null, null, null)),
|
||||
HttpStatus.FORBIDDEN, "SUPER_ADMIN_REQUIRED");
|
||||
assertCoded(() -> service.resetPassword(6L), HttpStatus.FORBIDDEN, "SUPER_ADMIN_REQUIRED");
|
||||
assertCoded(() -> service.changePassword(6L, "Str0ng#Pass"), HttpStatus.FORBIDDEN, "SUPER_ADMIN_REQUIRED");
|
||||
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
verify(rest, never()).postForEntity(eq(UPDATE_PWD), eq(Integer.class), any());
|
||||
verify(auth, never()).resetAdminPassword(anyString(), anyString());
|
||||
}
|
||||
|
||||
@@ -544,20 +541,81 @@ class AdminUserServiceTest {
|
||||
verify(auth).resetAdminPassword("stored", "stored@x.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
void changePassword_rulesRejected_is400() {
|
||||
stubFind(5, row(5, "A", "a", "a@x.com", true, "R"));
|
||||
when(rest.postForEntity(eq(UPDATE_PWD), eq(Integer.class), any())).thenReturn(ResponseEntity.ok(0));
|
||||
assertCoded(() -> service.changePassword(5L, "weak"), HttpStatus.BAD_REQUEST, "PASSWORD_RULES");
|
||||
// ---- own roles and hidden roles ----
|
||||
|
||||
private static final List<AdminRoleRef> HIDDEN_ADMIN = List.of(new AdminRoleRef(2L, "ROLE_ADMIN"));
|
||||
private static final List<AdminRoleRef> HIDDEN_MEMBER = List.of(new AdminRoleRef(3L, "ROLE_MEMBER"));
|
||||
|
||||
private void storedRolesInclude(Map<String, Object>... extra) {
|
||||
List<Map<String, Object>> all = new ArrayList<>(List.of(fullRole(1, "ROLE_SUPER_ADMIN"), fullRole(4, "ROLE_SALES"), fullRole(5, "ROLE_OPS")));
|
||||
all.addAll(List.of(extra));
|
||||
when(rest.getForEntity(eq("/role/findAll"), any(ParameterizedTypeReference.class))).thenReturn(ResponseEntity.ok(all));
|
||||
}
|
||||
|
||||
private Map<String, Object> ownRow() {
|
||||
Map<String, Object> m = row(1, "Boss", "boss", "b@x.com", true);
|
||||
m.put("roles", List.of(fullRole(2, "ROLE_ADMIN"), fullRole(4, "ROLE_SALES")));
|
||||
return m;
|
||||
}
|
||||
|
||||
@Test
|
||||
void changePassword_ok_returnsRowsUpdated() {
|
||||
void update_nonSuperCallerCannotChangeTheirOwnRoles() {
|
||||
storedRolesInclude(fullRole(2, "ROLE_ADMIN"));
|
||||
stubNoDuplicates();
|
||||
stubFind(1, ownRow());
|
||||
assertCoded(() -> service.update(1L, new AdminUserRequest(null, null, null, null, null, List.of(new AdminRoleRef(5L, "ROLE_OPS")))),
|
||||
HttpStatus.FORBIDDEN, "OWN_ROLES");
|
||||
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_nonSuperCallerCannotAddARoleToThemself() {
|
||||
storedRolesInclude(fullRole(2, "ROLE_ADMIN"));
|
||||
stubNoDuplicates();
|
||||
stubFind(1, ownRow());
|
||||
assertCoded(() -> service.update(1L, new AdminUserRequest(null, null, null, null, null,
|
||||
List.of(new AdminRoleRef(4L, "ROLE_SALES"), new AdminRoleRef(5L, "ROLE_OPS")))), HttpStatus.FORBIDDEN, "OWN_ROLES");
|
||||
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_nonSuperCallerSavingTheirOwnSameRolesPasses() {
|
||||
storedRolesInclude(fullRole(2, "ROLE_ADMIN"));
|
||||
stubNoDuplicates();
|
||||
stubFind(1, ownRow());
|
||||
stubSave(ownRow());
|
||||
service.update(1L, new AdminUserRequest("Boss2", null, null, null, null, ROLES));
|
||||
verify(rest).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_nonSuperCallerSavingWithoutRolesPasses() {
|
||||
stubNoDuplicates();
|
||||
stubFind(1, ownRow());
|
||||
stubSave(ownRow());
|
||||
service.update(1L, new AdminUserRequest("Boss2", null, null, null, null, null));
|
||||
verify(rest).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_superCallerMayChangeTheirOwnRoles() {
|
||||
callerIsSuper();
|
||||
stubNoDuplicates();
|
||||
stubFind(1, ownRow());
|
||||
stubSave(ownRow());
|
||||
service.update(1L, new AdminUserRequest(null, null, null, null, null, List.of(new AdminRoleRef(5L, "ROLE_OPS"))));
|
||||
verify(rest).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAndUpdate_hiddenRolesLookUnknown() {
|
||||
storedRolesInclude(fullRole(2, "ROLE_ADMIN"), fullRole(3, "ROLE_MEMBER"));
|
||||
stubNoDuplicates();
|
||||
stubFind(5, row(5, "A", "a", "a@x.com", true, "R"));
|
||||
when(rest.postForEntity(eq(UPDATE_PWD), eq(Integer.class), any())).thenReturn(ResponseEntity.ok(1));
|
||||
assertThat(service.changePassword(5L, "Str0ng#Pass")).isEqualTo(1);
|
||||
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
|
||||
verify(rest).postForEntity(eq(UPDATE_PWD), eq(Integer.class), body.capture());
|
||||
assertThat((Map<String, Object>) body.getValue()).containsEntry("userId", 5L).containsEntry("password", "Str0ng#Pass");
|
||||
for (List<AdminRoleRef> hidden : List.of(HIDDEN_ADMIN, HIDDEN_MEMBER)) {
|
||||
assertCoded(() -> service.create(req("N", "u", "e@x.com", hidden)), HttpStatus.BAD_REQUEST, "UNKNOWN_ROLE");
|
||||
assertCoded(() -> service.update(5L, new AdminUserRequest(null, null, null, null, null, hidden)), HttpStatus.BAD_REQUEST, "UNKNOWN_ROLE");
|
||||
}
|
||||
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user