amazon-web-servicespytestbotobotocoremoto

How to get verification code/change password code in boto3?


I'm writing tests in Moto and Pytest for a confirm sign up route that receives a verification code and a email and uses boto method confirm_sign_up to confirm user. My question is: After I created a user pool, a client and a user, how can I get the verification code that will be sended to the user e-mail?

I'm also creating tests for password change, that requires a code to change the user password. I also want to know how to get this password change code.

I looked for methods in boto and not discovered a method or attribute like this.


Solution

  • Moto does not require a valid verification code for either confirm_forgot_password or confirm_signup - anything will do.

    For confirm_forgot_password, there is a way to test expired confirmation codes.
    The forgot_password-method will return a header specific to Moto, x-moto-forgot-password-confirmation-code, that contains a confirmation code in the format moto-confirmation-code:....

    If you pass a code to confirm_forgot_password that starts with moto-confirmation-code:, but does not match up with the code returned by the forgot_password-method, it will throw an error.

    See the code here: https://github.com/getmoto/moto/blob/2b0d6ee0dc333cc4a581abf8ed0d6ebf2afdc3ab/moto/cognitoidp/models.py#L1551C9-L1551C32

    And internal tests that Moto uses for this scenario: https://github.com/getmoto/moto/blob/2b0d6ee0dc333cc4a581abf8ed0d6ebf2afdc3ab/tests/test_cognitoidp/test_cognitoidp.py#L3124