mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cognito): align AdminGetUser lookup with pool sign-in settings (#1571)
This commit is contained in:
1 parent
e20f7d83d2
commit
e6448eec7d
2 files changed
+175
-17
No files matched your search
@@ -33,18 +33,20 @@ import static org.mockito.Mockito.when;
|
||||
class CognitoServiceTest {
|
||||
|
||||
private CognitoService service;
|
||||
private InMemoryStorage<String, CognitoUser> userStore;
|
||||
private InMemoryStorage<String, CognitoGroup> groupStore;
|
||||
private RegionResolver regionResolver;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
userStore = new InMemoryStorage<>();
|
||||
groupStore = new InMemoryStorage<>();
|
||||
regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
service = new CognitoService(
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
userStore,
|
||||
groupStore,
|
||||
new InMemoryStorage<>(), // revokedTokenStore
|
||||
"http://localhost:4566",
|
||||
@@ -1353,7 +1355,7 @@ class CognitoServiceTest {
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Issue #220 — adminGetUser resolves sub UUID and email aliases
|
||||
// AdminGetUser resolves configured identifiers
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
@@ -1370,13 +1372,132 @@ class CognitoServiceTest {
|
||||
|
||||
@Test
|
||||
void adminGetUserByEmailAlias() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TestPool", "AliasAttributes", List.of("email")),
|
||||
"us-east-1"
|
||||
);
|
||||
service.adminCreateUser(pool.getId(), "bob",
|
||||
Map.of("email", "bob@example.com", "email_verified", "true"), null);
|
||||
|
||||
CognitoUser found = service.adminGetUser(pool.getId(), "bob@example.com");
|
||||
assertEquals("bob", found.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminGetUserByPhoneNumberAlias() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TestPool", "AliasAttributes", List.of("phone_number")),
|
||||
"us-east-1"
|
||||
);
|
||||
service.adminCreateUser(pool.getId(), "bob",
|
||||
Map.of("phone_number", "+15551234567", "phone_number_verified", "true"), null);
|
||||
|
||||
CognitoUser found = service.adminGetUser(pool.getId(), "+15551234567");
|
||||
assertEquals("bob", found.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminGetUserByPreferredUsernameAlias() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TestPool", "AliasAttributes", List.of("preferred_username")),
|
||||
"us-east-1"
|
||||
);
|
||||
service.adminCreateUser(pool.getId(), "bob", Map.of("preferred_username", "bobby"), null);
|
||||
|
||||
CognitoUser found = service.adminGetUser(pool.getId(), "bobby");
|
||||
assertEquals("bob", found.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminGetUserByEmailUsernameAttribute() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TestPool", "UsernameAttributes", List.of("email")),
|
||||
"us-east-1"
|
||||
);
|
||||
service.adminCreateUser(pool.getId(), "bob", Map.of("email", "bob@example.com"), null);
|
||||
|
||||
CognitoUser found = service.adminGetUser(pool.getId(), "bob@example.com");
|
||||
assertEquals("bob", found.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminGetUserByPhoneNumberUsernameAttribute() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TestPool", "UsernameAttributes", List.of("phone_number")),
|
||||
"us-east-1"
|
||||
);
|
||||
service.adminCreateUser(pool.getId(), "bob", Map.of("phone_number", "+15551234567"), null);
|
||||
|
||||
CognitoUser found = service.adminGetUser(pool.getId(), "+15551234567");
|
||||
assertEquals("bob", found.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminGetUserRejectsEmailWithoutConfiguredAlias() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
|
||||
service.adminCreateUser(pool.getId(), "bob", Map.of("email", "bob@example.com"), null);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.adminGetUser(pool.getId(), "bob@example.com"));
|
||||
assertEquals("UserNotFoundException", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminGetUserRejectsUnverifiedEmailAlias() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TestPool", "AliasAttributes", List.of("email")),
|
||||
"us-east-1"
|
||||
);
|
||||
service.adminCreateUser(pool.getId(), "bob", Map.of("email", "bob@example.com"), null);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.adminGetUser(pool.getId(), "bob@example.com"));
|
||||
assertEquals("UserNotFoundException", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminGetUserRejectsUnknownPoolWithResourceNotFound() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.adminGetUser("us-east-1_missing", "bob"));
|
||||
assertEquals("ResourceNotFoundException", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminGetUserRejectsAmbiguousLookupValueCreatedViaAdminCreateUser() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TestPool", "AliasAttributes", List.of("email")),
|
||||
"us-east-1"
|
||||
);
|
||||
service.adminCreateUser(pool.getId(), "shared-lookup", Map.of("email", "owner@example.com"), null);
|
||||
service.adminCreateUser(pool.getId(), "alice",
|
||||
Map.of("email", "shared-lookup", "email_verified", "true"), null);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.adminGetUser(pool.getId(), "shared-lookup"));
|
||||
assertEquals("InvalidParameterException", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminGetUserRejectsAmbiguousLookupValueCreatedViaAdminUpdateUserAttributes() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TestPool", "AliasAttributes", List.of("email")),
|
||||
"us-east-1"
|
||||
);
|
||||
service.adminCreateUser(pool.getId(), "shared-lookup", Map.of("email", "owner@example.com"), null);
|
||||
service.adminCreateUser(pool.getId(), "alice", Map.of("email", "alice@example.com"), null);
|
||||
service.adminUpdateUserAttributes(pool.getId(), "alice",
|
||||
Map.of("email", "shared-lookup", "email_verified", "true"));
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.adminGetUser(pool.getId(), "shared-lookup"));
|
||||
assertEquals("InvalidParameterException", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Issue #233 — listUsers Filter
|
||||
// =========================================================================
|
||||
|
||||
Reference in new issue
Block a user