← All posts

Test Magic Link Login in Staging Across Different Origins

· FakeSignup
magic linkstagingqatesting

When testing magic link logins in staging, you'll often encounter a hurdle: the email client opens in a different browser tab or even a separate application, while your application under test is running on a different origin. This makes it difficult to reliably click the magic link and have it authenticate your user. The solution is to use a tool that can intercept and display the magic link directly within your testing environment, allowing for an immediate click-through.

Testing Magic Link Login in Staging with Origin Differences

The core problem with testing magic link logins in staging is that the email containing the magic link and the application receiving the authentication request are distinct entities. If you're using a staging email server that forwards to your personal inbox, you'll have to manually switch tabs, find the email, copy the link, and paste it back into your application's browser tab. This is slow and error-prone. When the application is running on app.staging.example.com and the magic link is intended to be clicked from mail.staging.example.com (or even an external client), the browser's Same-Origin Policy can also complicate direct interaction.

To effectively test magic link login flows in staging, you need a way to present the magic link directly to the user within the context of their testing session. This means the magic link should appear in a place that's easily accessible without context switching. For automated or semi-automated testing, this is crucial. The link needs to be clickable and immediately redirect to the correct application origin for authentication.

Setting Up Your Test Environment

First, ensure your staging environment is configured to send test emails to a dedicated, temporary inbox. This inbox should be accessible programmatically or via a user interface that integrates with your testing workflow. For manual and semi-automated testing, a dedicated tool that provides a persistent inbox view alongside your test application is ideal.

You'll need a way to capture these test emails. Many services offer temporary email addresses. For developers and QA teams, a tool like FakeSignup is designed for this purpose, providing a dedicated inbox that can be accessed directly. This avoids the need for external email clients entirely during testing.

Capturing and Clicking Magic Links

The key to overcoming the origin difference is to have the magic link appear where you can click it immediately. This is where a tool with an integrated inbox becomes essential.

Here’s a typical workflow:

  1. Trigger Login: Initiate the magic link login process in your staging application. This usually involves entering an email address and submitting a form.
  2. Receive Email: Your staging application sends an email with a unique magic link to the temporary email address you provided.
  3. Access Magic Link: Instead of checking an external email client, the magic link appears in the FakeSignup inbox, typically in a side panel or a dedicated tab within the extension.
  4. Click Link: Click directly on the magic link displayed in the FakeSignup inbox.
  5. Authentication: The link opens in your browser, automatically directed to your staging application's origin, and completes the authentication process.

This direct click-through is what makes testing magic link login flows efficient, even when the email origin and application origin differ.

Automating Magic Link Tests

For more advanced testing, particularly for full automation, you’ll want to integrate this process. The FakeSignup extension, available on the Chrome Web Store, offers features to aid in this.

To install the extension:

Once installed, the extension provides an inbox view. For full automation, you'd typically use the Full Auto premium feature. This feature allows the extension to monitor incoming emails, extract the magic link, and programmatically pass it to your test runner or directly to the browser for authentication. This bypasses the need for manual clicking entirely, making your end-to-end tests for magic link logins much faster and more reliable. Saved accounts are stored locally in Chrome.

Verifying Magic Link Expiry and Security

Beyond just the click-through, you should also test the security aspects of your magic link implementation. This includes verifying that links expire after a reasonable period. Your staging environment should be configured to simulate this expiry.

When a magic link expires, the user should be presented with a clear message and an option to resend the link. Test this flow by waiting longer than the expected expiry time after receiving the link and then attempting to click it. Ensure the application handles this gracefully and prompts the user for a new login. This is a critical part of testing magic link login functionality in staging environments.

Handling Different Email Providers in Staging

Your staging environment might be configured to use various simulated email providers or even connect to a real, but dedicated, mail server. The FakeSignup extension is designed to work with the temporary email addresses it generates. When testing magic link login in staging, ensure your application's email sending service is correctly configured to target these temporary addresses. The extension's inbox will then capture any emails sent to these addresses, regardless of the technical setup of the staging email infrastructure, as long as the emails are directed to the domains FakeSignup supports.