mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cognito): implement AdminEnableUser and AdminDisableUser (#514)
- Add adminEnableUser/adminDisableUser methods to CognitoService - Add handler routing in CognitoJsonHandler - Enforce isEnabled check across all auth flows (Password, SRP, Refresh) - Add comprehensive unit tests for enable/disable lifecycle
This commit is contained in:
1 parent
6f12f78201
commit
6e8127c0e8
3 files changed
+108
No files matched your search
@@ -709,4 +709,78 @@ class CognitoServiceTest {
|
||||
|
||||
assertEquals(0, groupStore.scan(k -> k.startsWith(prefix)).size());
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Issue #433 — AdminEnableUser / AdminDisableUser
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void adminDisableUserSetsEnabledFalse() {
|
||||
UserPool pool = createPoolAndUser();
|
||||
|
||||
CognitoUser before = service.adminGetUser(pool.getId(), "alice");
|
||||
assertTrue(before.isEnabled(), "User should be enabled by default");
|
||||
|
||||
service.adminDisableUser(pool.getId(), "alice");
|
||||
|
||||
CognitoUser after = service.adminGetUser(pool.getId(), "alice");
|
||||
assertFalse(after.isEnabled(), "User should be disabled after adminDisableUser");
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminEnableUserSetsEnabledTrue() {
|
||||
UserPool pool = createPoolAndUser();
|
||||
service.adminDisableUser(pool.getId(), "alice");
|
||||
|
||||
service.adminEnableUser(pool.getId(), "alice");
|
||||
|
||||
CognitoUser user = service.adminGetUser(pool.getId(), "alice");
|
||||
assertTrue(user.isEnabled(), "User should be enabled after adminEnableUser");
|
||||
}
|
||||
|
||||
@Test
|
||||
void disabledUserCannotAuthenticate() {
|
||||
UserPool pool = createPoolAndUser();
|
||||
UserPoolClient client = service.createUserPoolClient(
|
||||
pool.getId(), "c", false, false, List.of(), List.of());
|
||||
|
||||
service.adminDisableUser(pool.getId(), "alice");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.initiateAuth(client.getClientId(), "USER_PASSWORD_AUTH",
|
||||
Map.of("USERNAME", "alice", "PASSWORD", "Perm1234!")));
|
||||
assertEquals("UserNotConfirmedException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void reEnabledUserCanAuthenticate() {
|
||||
UserPool pool = createPoolAndUser();
|
||||
UserPoolClient client = service.createUserPoolClient(
|
||||
pool.getId(), "c", false, false, List.of(), List.of());
|
||||
|
||||
service.adminDisableUser(pool.getId(), "alice");
|
||||
service.adminEnableUser(pool.getId(), "alice");
|
||||
|
||||
Map<String, Object> result = service.initiateAuth(
|
||||
client.getClientId(), "USER_PASSWORD_AUTH",
|
||||
Map.of("USERNAME", "alice", "PASSWORD", "Perm1234!"));
|
||||
assertNotNull(((Map<String, Object>) result.get("AuthenticationResult")).get("AccessToken"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminDisableUserNonexistentThrows() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
|
||||
|
||||
assertThrows(AwsException.class, () ->
|
||||
service.adminDisableUser(pool.getId(), "ghost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminEnableUserNonexistentThrows() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
|
||||
|
||||
assertThrows(AwsException.class, () ->
|
||||
service.adminEnableUser(pool.getId(), "ghost"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user