mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cognito): name missing user pools in errors (#2936)
* fix(cognito): name missing user pools in errors * test(cognito): address missing pool review
This commit is contained in:
1 parent
14ca62d9f7
commit
c30ca8fb5f
5 files changed
+45
-7
No files matched your search
@@ -17,6 +17,8 @@ Floci strips reserved `floci:*` tags from stored and returned `UserPoolTags` on
|
||||
|
||||
Standalone `TagResource` rejects reserved `floci:*` keys. `ListTagsForResource` and `UntagResource` operate on the persisted user-pool tag map.
|
||||
|
||||
An action given a user pool ID that does not resolve returns `ResourceNotFoundException` with the live service's wording, `User pool <poolId> does not exist.`, so tooling that matches Cognito error text behaves the same way locally.
|
||||
|
||||
## Supported Actions
|
||||
|
||||
### User Pools
|
||||
|
||||
@@ -359,7 +359,7 @@ public class CognitoService implements ResourceProvider {
|
||||
|
||||
public UserPool describeUserPool(String id) {
|
||||
UserPool pool = poolStore.get(id)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "User pool not found", 400));
|
||||
.orElseThrow(() -> userPoolNotFound(id));
|
||||
boolean generatedKeys = ensureJwtSigningKeys(pool);
|
||||
boolean generatedSecret = ensureRefreshTokenSecret(pool);
|
||||
if (generatedKeys || generatedSecret) {
|
||||
@@ -1416,7 +1416,7 @@ public class CognitoService implements ResourceProvider {
|
||||
|
||||
public CognitoUser adminGetUser(String userPoolId, String username) {
|
||||
UserPool pool = poolStore.get(userPoolId).orElseThrow(
|
||||
() -> new AwsException("ResourceNotFoundException", "User pool not found", 400));
|
||||
() -> userPoolNotFound(userPoolId));
|
||||
LinkedHashMap<String, CognitoUser> matches = new LinkedHashMap<>();
|
||||
userStore.get(userKey(userPoolId, username))
|
||||
.ifPresent(u -> matches.put(u.getUsername(), u));
|
||||
@@ -2034,9 +2034,9 @@ public class CognitoService implements ResourceProvider {
|
||||
UserPoolClient client = clientStore.get(clientId)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Client not found",
|
||||
400));
|
||||
UserPool pool = poolStore.get(client.getUserPoolId())
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"User pool not found", 400));
|
||||
String userPoolId = client.getUserPoolId();
|
||||
UserPool pool = poolStore.get(userPoolId)
|
||||
.orElseThrow(() -> userPoolNotFound(userPoolId));
|
||||
CognitoUser user = adminGetUser(client.getUserPoolId(), username);
|
||||
if (verificationCodeService != null && isSignUpConfirmationEnabled(pool)) {
|
||||
try {
|
||||
@@ -2398,6 +2398,11 @@ public class CognitoService implements ResourceProvider {
|
||||
|
||||
// ──────────────────────────── Private helpers ────────────────────────────
|
||||
|
||||
private static AwsException userPoolNotFound(String userPoolId) {
|
||||
return new AwsException("ResourceNotFoundException",
|
||||
"User pool " + userPoolId + " does not exist.", 400);
|
||||
}
|
||||
|
||||
UserPoolClient findClientById(String clientId) {
|
||||
return clientStore.get(clientId)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Client not found", 400));
|
||||
|
||||
@@ -230,6 +230,20 @@ class CognitoIntegrationTest {
|
||||
assertFalse(sub.path("Mutable").asBoolean(), "sub must not be Mutable");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void describeUnknownUserPoolNamesPoolInResourceNotFoundMessage() {
|
||||
String missingPoolId = "us-east-1_000000000";
|
||||
|
||||
cognitoAction("DescribeUserPool", """
|
||||
{ "UserPoolId": "%s" }
|
||||
""".formatted(missingPoolId))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"))
|
||||
.body("message", equalTo("User pool " + missingPoolId + " does not exist."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void confirmForgotPasswordRejectsWrongConfirmationCode() throws Exception {
|
||||
|
||||
@@ -1468,6 +1468,20 @@ class CognitoServiceTest {
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void confirmSignUpNamesDeletedUserPoolInResourceNotFoundMessage() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
|
||||
UserPoolClient client = service.createUserPoolClient(
|
||||
pool.getId(), "test-client", false, false, List.of(), List.of());
|
||||
service.deleteUserPool(pool.getId());
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.confirmSignUp(client.getClientId(), "carol", "123456"));
|
||||
assertEquals("ResourceNotFoundException", ex.getErrorCode());
|
||||
assertEquals("User pool " + pool.getId() + " does not exist.", ex.getMessage());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"email_verified", "phone_number_verified"})
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -1854,9 +1868,12 @@ class CognitoServiceTest {
|
||||
|
||||
@Test
|
||||
void adminGetUserRejectsUnknownPoolWithResourceNotFound() {
|
||||
String missingPoolId = "us-east-1_missing";
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.adminGetUser("us-east-1_missing", "bob"));
|
||||
() -> service.adminGetUser(missingPoolId, "bob"));
|
||||
assertEquals("ResourceNotFoundException", ex.getErrorCode());
|
||||
assertEquals("User pool " + missingPoolId + " does not exist.", ex.getMessage());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ class S3WellKnownKeyIntegrationTest {
|
||||
.then()
|
||||
.extract().asString();
|
||||
|
||||
if (body.contains("ResourceNotFoundException") || body.contains("User pool not found")) {
|
||||
if (body.contains("ResourceNotFoundException") || body.contains("User pool ")) {
|
||||
throw new AssertionError(
|
||||
"GET /" + BUCKET + "/" + JWKS_KEY
|
||||
+ " was routed to Cognito instead of S3. Response: " + body);
|
||||
|
||||
Reference in new issue
Block a user