
Testing Magic Link Login Flows With a Disposable Inbox
Need a disposable inbox right now?
Spin up a temporary email address in seconds — no signup, no spam, no trace.
Magic link login skips the password and the one-time code: the user clicks a link in their email and lands back on your site already signed in. It's one of the smoothest flows to use and one of the hardest to test, because there's no code to type into a field and no password to hardcode into a fixture. The link only exists inside an inbox, it usually works exactly once, and it typically expires inside fifteen minutes. If your test suite can't open a real inbox and follow that link the way a user does, you're not testing the login flow — you're testing everything up to the point where the email gets queued.
Why magic links break the usual test setup
A password test is trivial: hardcode a hash, log in, done. An OTP test is annoying but tractable — poll an inbox, read four to eight digits, type them into a field. A magic link test has a different shape entirely. The credential your test needs to consume is a full URL, sent once, tied to a session token the server invalidates the moment it's used. There's no field to fill in; the test has to actually navigate to that URL in the same browser context a user would use.
This is where teams get tempted to fake it — read the token straight out of a database or debug log and construct the URL by hand. That confirms token generation works. It tells you nothing about whether the email actually renders the link correctly, whether a link-shortener or tracking wrapper mangles the query string, or whether the token is still valid by the time a real mail round-trip finishes. Those are exactly the bugs that show up in production and never show up in a suite that skips the inbox.
One address per run, not one shared mailbox
The failure mode that makes magic-link tests flaky in CI is reusing a single test inbox across parallel runs. Two workers hit the same address, two links land in the same inbox, and whichever worker's poll grabs the second link first ends up authenticating with a token meant for the other run — or clicking a link that's already been consumed. The fix is the same pattern that works for OTP testing: one address per run, generated fresh, never reused.
GET /getMail is also CyberTemp's implicit inbox-creation call — the first request against a new address just works, no separate setup step. That makes it easy to mint a throwaway address per test invocation:
import uuid
def fresh_address(): return f"magiclink-{uuid.uuid4().hex[:10]}@cybertemp.xyz"
Every run gets an address nobody else is polling, so there's no race between two workers reading the same mailbox and no leftover link from a previous run inflating your message count.
Polling for the link and extracting it safely
Once the address exists, the rest is a poll loop against the same endpoint, with a regex tuned to your link's shape instead of a digit pattern:
import httpx, re, timeAPI_KEY = "tk_..." HEADERS = {"X-API-Key": API_KEY} BASE = "https://api.cybertemp.xyz"
def get_mail(address): r = httpx.get(f"{BASE}/getMail", params={"email": address}, headers=HEADERS) r.raise_for_status() return r.json()
def wait_for_magic_link(address, timeout=60): link_pattern = re.compile(r'href="(https://yourapp\.com/auth/[^"]+)"') deadline = time.time() + timeout while time.time() < deadline: for message in get_mail(address): match = link_pattern.search(message.get("body", "")) if match: return match.group(1) time.sleep(2) raise TimeoutError(f"no magic link arrived for {address} within {timeout}s")
Anchor the regex to your own domain and auth path, not a generic URL pattern. Transactional templates often include tracking pixels and footer links that are also valid URLs — match too loosely and you'll occasionally grab the wrong one and burn a debugging session on a false failure.
Once you have the URL, hand it to whatever drives your browser layer — Playwright's page.goto(link), Cypress's cy.visit(link), or a plain HTTP client if you're testing the redirect chain instead of the rendered page. That navigation is the actual assertion: did the link authenticate the session, and did it land where your app promises it will.
The single-use trap, and matching your timeout to reality
Magic links are usually single-use by design — the server invalidates the token as soon as it's requested, which is the right security default. It also means your test has to be careful never to fetch the link's URL more than once. A retry wrapper that re-requests on timeout, a proxy that pre-fetches links for a preview, or a logging step that curls the URL "just to be safe" will all burn the token before your real test navigation happens, and the failure looks like a broken login when it's really double-consumption in the test itself. Keep the poll loop and the navigation as the only two things that ever touch the link — retry the poll, not the click.
The other place these tests go wrong is the timeout. A fifteen-minute expiry sounds generous until a backed-up CI queue means the test doesn't run until eight minutes after signup fired. Poll on a short interval, fail well before the token's real expiry, and log the actual elapsed time on failure — a test that times out because mail delivery was slow that day and one that fails because the token already expired are different bugs with different fixes. This is the same discipline covered in debugging an email verification loop that won't complete: compare the message's actual timestamp against your server's issued-at log rather than assuming the gap is zero.
Turning it into a standing CI check
Once the poll-extract-navigate sequence works for one manual run, wrap it into a fixture that:
Generates a fresh address before the test and tears it down after with
DELETE /inbox?email=..., so throwaway addresses don't eat into your plan's inbox limit.Asserts on exactly one message arriving, not "at least one" — a duplicate send on retry is a real bug worth catching, not something to tolerate silently.
Fails loudly if the link pattern doesn't match anything in the body, instead of falling through to a generic "element not found" error three steps later in the browser layer.
That's a small addition on top of infrastructure most teams already have for OTP testing — the same inbox-per-run structure covered in getting OTP codes into Playwright and Cypress tests, just extracting a link instead of a digit string. If several CI jobs run this fixture in parallel, watch your concurrent-inbox count; handling rate limits and retries in CyberTemp API scripts covers what to do once polling frequency starts tripping a 429 instead of just running slow.
Bottom line
Magic links are one piece of the broader move away from passwords, alongside passkeys and OTP-based two-factor — and the recovery-path problem is the same across all of them, the way passkeys still fall back to a recovery email when a device is lost. If your auth system supports more than one passwordless method, run the same disposable-inbox pattern against each of them rather than treating magic links as a one-off case.
If you're scripting this against a real CI matrix — several jobs running in parallel, each needing its own inbox and its own poll budget — the point where a free-tier key's concurrent-inbox limit becomes the bottleneck arrives sooner than most teams expect. The paid tiers raise both the concurrent-inbox count and the request rate, which is what actually matters once this fixture runs on every pull request instead of just on your laptop before a release.