fix(cognito): refuse DeleteUserPool while deletion protection is active (#3961)

DeletionProtection was stored and round-tripped but never read on the
delete path, so a protected pool was deleted like any other and a
CloudFormation DeleteStack owning one succeeded. AWS refuses with
InvalidParameterException until UpdateUserPool switches the flag to
INACTIVE, and the stack reports DELETE_FAILED with that reason.

The check reads the pool store directly: describeUserPool would turn a
delete of a missing id into ResourceNotFoundException (a separate
divergence) and generate signing keys as a side effect.

Closes #3948
This commit is contained in:
David authored and GitHub committed 2026-09-19 19:53:48 -04:00
1 parent 7d9f499f2d
commit 1e8485830c
5 files changed
+174 -1

No files matched your search

@@ -468,6 +468,27 @@ class CognitoFeaturesTest {
cognito.adminDeleteUser(b -> b.userPoolId(poolId).username(tempUser));
}
@Test
@Order(61)
void deletionProtectionRefusesDeleteUntilDeactivated() {
String protectedPoolId = cognito.createUserPool(b -> b
.poolName("compat-protected-pool")
.deletionProtection(DeletionProtectionType.ACTIVE))
.userPool().id();
try {
assertThatThrownBy(() -> cognito.deleteUserPool(b -> b.userPoolId(protectedPoolId)))
.isInstanceOf(InvalidParameterException.class)
.hasMessageContaining("deletion protection is activated");
assertThat(cognito.describeUserPool(b -> b.userPoolId(protectedPoolId)).userPool().deletionProtection())
.isEqualTo(DeletionProtectionType.ACTIVE);
} finally {
cognito.updateUserPool(b -> b.userPoolId(protectedPoolId).deletionProtection(DeletionProtectionType.INACTIVE));
cognito.deleteUserPool(b -> b.userPoolId(protectedPoolId));
}
assertThatThrownBy(() -> cognito.describeUserPool(b -> b.userPoolId(protectedPoolId)))
.isInstanceOf(ResourceNotFoundException.class);
}
// ── Issue #234 note ───────────────────────────────────────────────────────
// GetTokensFromRefreshToken is tested in sdk-test-node/tests/cognito-features.test.ts
// because GetTokensFromRefreshTokenCommand is not available in Java SDK 2.31.8.