← All use cases

Security Requirement Testing

Check password reset and authentication flows against your security requirements

When your own tests check security-related email flows such as password resets, account recovery, and email changes, MailBrew receives the emails for them. Write tests that check tokens cannot be reused, expire on time, and are rate limited.

What you can do with MailBrew

  1. 01

    Token checks

    Extract the token from the received email and test that it cannot be reused, stops working after it expires, and differs each time.

  2. 02

    Rate limit testing

    Repeat password reset or OTP requests and count the emails that arrive to check that your app's rate limits work.

  3. 03

    Account enumeration defenses

    Check that registered and unregistered addresses get the same response, and that only the registered one receives an email.

  4. 04

    Run it in CI

    Add it to CI to run the same checks on each change. It checks only what your tests cover and does not replace a security assessment.

Sample code

Python (pytest)

Python (pytest)
# pytest + MailBrew: a password reset link works only once
import os
import re
import requests

API = "https://mailbrew.dev/api/mailbrew"
HEADERS = {"X-API-Key": os.environ["MAILBREW_API_KEY"]}
APP = "https://staging.example.com"


def test_reset_token_is_single_use():
    addr = requests.post(f"{API}/addresses", json={"ttl": 300}, headers=HEADERS).json()["data"]["address"]
    register_user(addr)  # register in the app under test (sends one confirmation email)
    requests.post(f"{APP}/password/reset", json={"email": addr})

    # Wait until both the confirmation and the reset email have arrived
    emails = requests.get(f"{API}/addresses/{addr}/emails/wait", params={"timeout": 30, "count": 2},
                          headers=HEADERS, timeout=40).json()["data"]
    reset = next(e for e in emails if "password" in e["subject"].lower())
    token = re.search(r"token=([A-Za-z0-9]+)", reset["text_body"]).group(1)

    r1 = requests.post(f"{APP}/password/update", json={"token": token, "password": "NewPass123!"})
    assert r1.status_code == 200

    r2 = requests.post(f"{APP}/password/update", json={"token": token, "password": "AnotherPass!"})
    assert r2.status_code in (400, 422)

Ready to try this use case?

Get started with the free plan today. No credit card required.
Free plan: up to 100 emails/month and 5 addresses

Create free account →