EveryRole

How to test email verification, from inbox to app

How to test email verification end to end. The test has to read the real email, so give it an inbox of its own, a new address per run, and five things to check.

To test email verification, the test has to do what a new user does: sign up, wait for the email, open it, follow the link, and end up in the app. The hard part is the middle. A browser test can’t open a person’s mailbox, so you give the test an inbox of its own, with a new address for every run, and you check the email itself before you click anything in it.

There are four ways to get at that email. They don’t prove the same thing.

Four ways a test gets at the confirmation email. Reading the token from the database proves the link's page works and nothing about the email. A mail catcher on staging proves the email's words and its link, not that it gets delivered. A real inbox the test can read proves the email was sent, arrived, and its link works. A person with a phone proves it didn't land in spam and that the link opens from a mail app.
Pick by what you need proved. The first one is the quickest and proves the least.

Why “read the token from the database” is not this test

It is the quickest thing to automate: sign up, look up the confirmation token in the database, build the link in the test, open it. It runs fast and never waits for anything.

It also passes when no email was sent at all. When the template is broken. When the link in the real email points at a staging host. When the mail provider’s key expired last night. Every one of those stops real sign-ups, and none of them is seen by a test that makes its own link.

Keep that test if you like it. It checks the page behind the link. Just don’t call it a test of email verification. It is a pass that didn’t check the thing.

How to test email verification: give the test an inbox

On staging: catch the mail. A mail catcher is a small server that accepts every message your app sends and shows it on a page, or over an API, without delivering it. The test asks it for the newest message to the address it signed up with. This is quick and safe, and it proves the email’s subject, words and link. It can’t prove delivery, because nothing was delivered.

On the live site: a real test inbox. Two ways to get one, without naming products:

  • An inbox service. Several exist. Each gives you addresses on its domain and an API that returns the emails sent to them. The test makes a new address, signs up with it, and asks the API for the message.
  • Your own domain. A mailbox that receives everything sent to qa+anything@yourdomain, read by the test over IMAP. Nothing to buy. You depend on your mail host’s delays and its spam filter, which is also a kind of test.

Either way the email travels the real path: your app, your mail provider, the internet, an inbox. That is the path your users are on.

E2E test of email verification: four rules

Whatever inbox you use, four rules keep the test honest.

A new address for every run. If run 12 and run 13 share an address, run 13 can find run 12’s email, click a stale link, and report whatever that does. Put the run’s id in the address.

Only accept an email that arrived after the sign-up. Note the time before pressing the button, and ignore anything older. This catches the same mistake from the other side.

Wait, with a limit. Ask the inbox every few seconds, and give up at a time you chose. Write that time down: it is your answer to “how long may a confirmation email take?”. Without a limit, a slow provider turns into a test that hangs for an hour.

Expect exactly one. Two confirmation emails for one sign-up is a bug (a double submit, a retry that sent twice). The test should fail on the second one, not click the first and move on.

What to check in the email, before clicking

Five checks, all on the message itself:

  1. It is addressed to the address that signed up.
  2. The sender and the subject are the ones you intend. A “noreply” sender at a domain nobody recognises looks like spam to the person reading it.
  3. It has exactly one confirmation link.
  4. The link’s host is the site the person signed up on. Read the address, don’t just follow it. This is the staging-host bug, and it is invisible from inside your own network.
  5. It has a plain-text part, with the link in it. Some mail programs show only that.

Then follow the link, and carry on with the cases for the link itself: once, twice, from another browser, after a newer one. Those are in test cases for a sign-up page, steps 3 and 4. A password reset email goes through the same inbox, and its link has a life of its own.

If your app sends a code to type, the checks are the same with one more pair: a wrong code is refused with a message, and the right code after a wrong one still works. That is wrong, then right, on a code field.

What no inbox test tells you

A test inbox says the email arrived at that inbox. It says nothing about the big mail providers’ spam folders, which is one place confirmation emails go missing. No end-to-end test fixes that. What helps is boring: sign up with a real personal address on each of the providers your users have, now and then, and look. Open it on a phone while you are there, because mail apps open links in their own small browser, and your “back where they were” may not survive it.

And clean up. Every run of this test makes an account. Delete it afterwards, through the app’s own “delete account” if there is one, and check it can no longer log in. Test data cleanup covers what to do when there isn’t.

How EveryRole tests the sign-up email

EveryRole has inboxes of its own, so there is nothing for you to set up. When you turn on the kind of user it calls “a brand-new user”, it signs up on your live site by itself, with an address made for that journey alone, so the emails it finds are its own. It reads the email, opens the link in it (or types the code), and goes through what a new user sees.

EveryRole's "A brand-new user" setting, switched off. It reads: EveryRole signs up by itself with its own inbox, confirms the email, and goes through what a new user sees. No login to give. Each run makes a real test account in your app, which EveryRole deletes afterwards through your app's own settings. On production it never pays: it stops at the checkout.
The setting in EveryRole. It is off until you turn it on, because each run makes a real account in your app.

It is off until you turn it on, for the reason on the screen: each run makes a real test account. EveryRole deletes that account afterwards through your app’s own settings, and says so when it could not.

Because it works from outside, it meets the email the way a stranger does. A link to a host it can’t reach fails there. The limit is the one above: its inbox is not a consumer mailbox, so it can’t tell you a message would have gone to spam.

Keep reading

Sign-up, login and passwords

Test cases for a login page, beyond the password

Test cases for a login page beyond right and wrong passwords: right after wrong, where you land, already signed in, Back after log out, with real answers.

6 min read