10

I'm creating a Cognito User Pool and a test user using CloudFormation templates. I'm doing this for automated testing of login, user management code, and token code.

However, there doesn't appear to be a way to set the password to some known value so that the test code can proceed with login, which would be the first step in testing everything else.

related question but answer is "check your email account", which won't work for automated testing: Cloud Formation AWS::Cognito::UserPoolUser temporary password\

I can use the API to administratively set the password (at least the CLI can) but I want my test code to be as black box as possible. I want to specify all the preconditions in the Cloud Formation Template, as I do for everything else I'm testing.

This AWS forum answer says "use a custom resource", but provides no help in how to do so:

Paul S
  • 892
  • 10
  • 25
  • 1
    Adding users in a CFT might be an anti-pattern, because it's so useless to do so. This might be a better way to create users for automated testing: https://stackoverflow.com/a/54416127/5840937 – Paul S Jun 03 '19 at 20:09
  • 1
    it can be that AWS forum answer similar to thing to the linked answer, that is creating a CF custom resource with a lambda that would go use AWS.CognitoIdentityServiceProvider to perform https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminSetUserPassword.html , I wouldn't say it's specifically anti-pattern, it doesn't have any reasonable upside here to me comparing to the approach in linked answer, but it is directly tied up to CF stack lifetime, which is often what we want to achieve – ambientlight Oct 02 '19 at 09:33
  • 3
    at this point I've moved on. I now have my test harness create users with random email addresses and use the Cognito API to set their password. Yes Cognito fills up, but sufficient randomness and the lifetime of the users is that of the CFT cover up most issues, it's good enough. The downside is there's a lot of latency in creating users and logging them in, so the tests run slower than I would like. – Paul S Oct 02 '19 at 19:07

0 Answers0