Skip to content

Commit

Permalink
CognitoIDP: Use default values for unspecified settings in update_use…
Browse files Browse the repository at this point in the history
…r_pool (#6866)
  • Loading branch information
kmdmnak authored Sep 30, 2023
1 parent 6fe4999 commit ad2d77a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
37 changes: 20 additions & 17 deletions moto/cognitoidp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,22 +399,7 @@ def __init__(
self.name = name
self.status = None

self.extended_config = DEFAULT_USER_POOL_CONFIG.copy()
self.extended_config.update(extended_config or {})

message_template = self.extended_config.get("VerificationMessageTemplate")
if message_template and "SmsVerificationMessage" not in extended_config:
self.extended_config["SmsVerificationMessage"] = message_template.get(
"SmsMessage"
)
if message_template and "EmailVerificationSubject" not in extended_config:
self.extended_config["EmailVerificationSubject"] = message_template.get(
"EmailSubject"
)
if message_template and "EmailVerificationMessage" not in extended_config:
self.extended_config["EmailVerificationMessage"] = message_template.get(
"EmailMessage"
)
self.update_extended_config(extended_config)

self.creation_date = utcnow()
self.last_modified_date = utcnow()
Expand Down Expand Up @@ -472,6 +457,24 @@ def domain(self) -> Optional["CognitoIdpUserPoolDomain"]:
None,
)

def update_extended_config(self, extended_config: Dict[str, Any]) -> None:
self.extended_config = DEFAULT_USER_POOL_CONFIG.copy()
self.extended_config.update(extended_config or {})

message_template = self.extended_config.get("VerificationMessageTemplate")
if message_template and "SmsVerificationMessage" not in extended_config:
self.extended_config["SmsVerificationMessage"] = message_template.get(
"SmsMessage"
)
if message_template and "EmailVerificationSubject" not in extended_config:
self.extended_config["EmailVerificationSubject"] = message_template.get(
"EmailSubject"
)
if message_template and "EmailVerificationMessage" not in extended_config:
self.extended_config["EmailVerificationMessage"] = message_template.get(
"EmailMessage"
)

def _base_json(self) -> Dict[str, Any]:
return {
"Id": self.id,
Expand Down Expand Up @@ -978,7 +981,7 @@ def update_user_pool(
self, user_pool_id: str, extended_config: Dict[str, Any]
) -> None:
user_pool = self.describe_user_pool(user_pool_id)
user_pool.extended_config = extended_config
user_pool.update_extended_config(extended_config)

def delete_user_pool(self, user_pool_id: str) -> None:
self.describe_user_pool(user_pool_id)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cognitoidp/test_cognitoidp.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,12 @@ def test_update_user_pool():
UserPoolId=user_pool_details["UserPool"]["Id"]
)
assert updated_user_pool_details["UserPool"]["Policies"] == new_policies
assert updated_user_pool_details["UserPool"]["AdminCreateUserConfig"] is not None
assert updated_user_pool_details["UserPool"]["EmailConfiguration"] is not None
assert (
updated_user_pool_details["UserPool"]["VerificationMessageTemplate"] is not None
)
assert updated_user_pool_details["UserPool"]["AccountRecoverySetting"] is not None


@mock_cognitoidp
Expand Down

0 comments on commit ad2d77a

Please sign in to comment.