Videos
Check out our tutorial video series.
How to test MFA 2FA short-codes and login magic links. Integration testing using throwaway email accounts and phone numbers. Capture SMS and email shortcodes.
Many modern web and mobile applications use modern user account authentication techniques that involve temporary passwords. These one-time passwords (OTP) are sent via email or SMS as part of 2FA two factor authentication in OAuth and SAML applications. Using a free email service we can test username and password authentication methods end-to-end in software applications.
One time email links are emails that are sent to a user of a website when they enter their email address during login. A server sends the email containing a link or passcode that expires after a short time. This password can be used by the user to sign into an application without requiring a typical permanent password.
AWS provides the Cognito authentication service for logging users into applications using OAuth or SAML username and password. In a demo app we created for this post we can use a simple react app hosted at playground.mailslurp.com to sign up for an account on a dummy application. A verification code is then sent to your email address which can be entered into a confirmation screen to confirm the account.
We can test this demo app using Cypress JS and the MailSlurp email API.
Then run to scaffold your tests.
The main steps for testing OTP are as follows:
We can automate that process using a Cypress end-to-end test like the one below.
Start your test by creating a throwaway email account.
Next we need to load the app we are testing using :
Use the inbox email address and submit it to the test application.
Once we submit the form wait for the code to arrive using the WaitForController methods. This method will hold the connection open for 30 seconds until the email arrives. It will throw an exception if the email does not arrive before then. Then we use a regex pattern to extract the OTP code and submit it.
Submit the email one-time password and assert the welcome page is shown.
Then we can see authorized welcome screen:
By using disposable email addresses we can test OTP 2FA one time passwords in any real world application. Test your authentication username and password login for real using actual email addresses so you know that your application is functioning.
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.