mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): keep SMS_MFA on a user pool update until MFA is turned off (#7088)
* fix(cloudformation): keep SMS_MFA on a user pool update until MFA is turned off The AWS::Cognito::UserPool reference says that once SMS_MFA is enabled, only MfaConfiguration OFF turns it off. An update that stopped listing SMS_MFA in EnabledMfas cleared it. replaceUserPoolMfaConfig now keeps the pool's SMS setting when none is given and the mode is not OFF. Closes #7086 * fix(cognito): keep SMS MFA with the pool's current SMS settings Keeping SMS MFA replayed the settings it was enabled with, so an update that dropped SMS_MFA and changed SmsAuthenticationMessage or SmsConfiguration put the old values back over the ones updateUserPool had just applied. The kept SMS MFA now takes the pool's current message and SMS configuration.
This commit is contained in:
1 parent
3acebc90fe
commit
f0a1b11385
5 files changed
+61
-2
No files matched your search
+34
@@ -528,6 +528,40 @@ class CognitoCfnIntegrationTest {
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
}
|
||||
|
||||
/** Once SMS_MFA is enabled, only MfaConfiguration OFF turns it off, per the template reference. */
|
||||
@Test
|
||||
void anUpdateKeepsSmsMfaUntilMfaIsTurnedOff() throws Exception {
|
||||
String stack = "cognito-cfn-enabled-mfas-keep-sms-it";
|
||||
String smsConfiguration = "\"SmsConfiguration\": {\"SnsCallerArn\": \"arn:aws:iam::000000000000:role/sms\"}";
|
||||
cloudFormation(stack, "CreateStack", enabledMfasTemplate(
|
||||
"\"MfaConfiguration\": \"OPTIONAL\", \"EnabledMfas\": [\"SMS_MFA\", \"SOFTWARE_TOKEN_MFA\"], "
|
||||
+ smsConfiguration));
|
||||
String poolId = outputValue(describeStacks(stack, "CREATE_COMPLETE"), "PoolId");
|
||||
|
||||
cloudFormation(stack, "UpdateStack", enabledMfasTemplate(
|
||||
"\"MfaConfiguration\": \"OPTIONAL\", \"EnabledMfas\": [\"SOFTWARE_TOKEN_MFA\"], "
|
||||
+ "\"SmsAuthenticationMessage\": \"New code {####}\", "
|
||||
+ "\"SmsConfiguration\": {\"SnsCallerArn\": \"arn:aws:iam::000000000000:role/sms-v2\"}"));
|
||||
describeStacks(stack, "UPDATE_COMPLETE");
|
||||
cognitoAction("GetUserPoolMfaConfig", "{\"UserPoolId\": \"" + poolId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("MfaConfiguration", equalTo("OPTIONAL"))
|
||||
.body("SoftwareTokenMfaConfiguration.Enabled", equalTo(true))
|
||||
.body("SmsMfaConfiguration.SmsAuthenticationMessage", equalTo("New code {####}"))
|
||||
.body("SmsMfaConfiguration.SmsConfiguration.SnsCallerArn", equalTo("arn:aws:iam::000000000000:role/sms-v2"));
|
||||
cognitoAction("DescribeUserPool", "{\"UserPoolId\": \"" + poolId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("UserPool.SmsAuthenticationMessage", equalTo("New code {####}"))
|
||||
.body("UserPool.SmsConfiguration.SnsCallerArn", equalTo("arn:aws:iam::000000000000:role/sms-v2"));
|
||||
|
||||
cloudFormation(stack, "UpdateStack", enabledMfasTemplate("\"MfaConfiguration\": \"OFF\""));
|
||||
describeStacks(stack, "UPDATE_COMPLETE");
|
||||
assertMfa(poolId, "OFF", false, false);
|
||||
|
||||
cloudFormation(stack, "DeleteStack", null);
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
}
|
||||
|
||||
/** OFF with a listed factor is refused by SetUserPoolMfaConfig after the pool exists. */
|
||||
@Test
|
||||
void aRefusedEnabledMfasOnCreateRemovesThePool() throws Exception {
|
||||
|
||||
+11
@@ -53,6 +53,17 @@ class CognitoReplaceMfaConfigTest {
|
||||
assertNotNull(pool.getSmsMfaConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
void smsThatIsNotGivenStaysOnUntilMfaIsTurnedOff() {
|
||||
service.replaceUserPoolMfaConfig(poolId, "OPTIONAL", true, Map.of("SmsAuthenticationMessage", "{####}"), null);
|
||||
|
||||
service.replaceUserPoolMfaConfig(poolId, "OPTIONAL", true, null, null);
|
||||
assertEquals("{####}", service.describeUserPool(poolId).getSmsMfaConfiguration().get("SmsAuthenticationMessage"));
|
||||
|
||||
service.replaceUserPoolMfaConfig(poolId, "OFF", null, null, null);
|
||||
assertNull(service.describeUserPool(poolId).getSmsMfaConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
void thePoolAReaderAlreadyHoldsKeepsItsSettings() {
|
||||
UserPool before = service.describeUserPool(poolId);
|
||||
|
||||
Reference in new issue
Block a user