Skip to content

Conversation

@vbudhram
Copy link
Contributor

Because

  • The auth-server already checks bounces against email aliases (e.g., test+123@gmail.comtest@gmail.com), but the shared email-sender library in libs/accounts/email-sender/ does not

This pull request

  • Adds checkBouncesWithAliases method that queries both the normalized root email and a wildcard alias pattern in parallel
  • Updates BouncesConfig with aliasCheckEnabled and emailAliasNormalization config fields
  • Adds optional email field to Bounce type for deduplication of merged results
  • Reuses existing EmailNormalization class from fxa-shared

Issue

Closes: https://mozilla-hub.atlassian.net/browse/FXA-12829

Checklist

  • My commit is GPG signed
  • Tests pass locally (if applicable)
  • Documentation updated (if applicable)
  • RTL rendering verified (if UI changed)

Other Information

  • Feature is off by default (aliasCheckEnabled: false). No behavior change unless explicitly enabled.
  • The underlying DB stored procedure (fetchEmailBounces_4) already uses LIKE, so wildcard queries (test+%@domain.com) work without DB changes.
  • Ports the same logic from packages/fxa-auth-server/lib/bounces.js to the shared lib.

@vbudhram vbudhram self-assigned this Jan 27, 2026
@vbudhram vbudhram requested a review from a team as a code owner January 27, 2026 20:09
@vbudhram vbudhram requested a review from Copilot January 27, 2026 20:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the shared email-sender bounce checking to understand and normalize email aliases, aligning its behavior with the auth-server’s alias-aware bounce logic.

Changes:

  • Extend BouncesConfig and Bounce types to support alias-aware checks (aliasCheckEnabled, emailAliasNormalization, optional email on Bounce).
  • Introduce checkBouncesWithAliases in Bounces, using EmailNormalization to query both normalized root and wildcard alias addresses in parallel, and merge/deduplicate results.
  • Add comprehensive Jest tests in bounces.spec.ts covering alias checks, threshold behavior, deduplication, and non-configured domain behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
libs/accounts/email-sender/src/bounces.ts Adds alias-aware bounce checking using EmailNormalization, new config fields, and deduplication of normalized/wildcard query results before applying existing bounce rules.
libs/accounts/email-sender/src/bounces.spec.ts Adds tests for alias-aware scenarios (on/off switch, thresholds, deduplication, and non-configured domains) to validate the new logic and config options.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +485 to +489
// For non-configured domain, both queries should use the original email
// (no transformation applied)
expect(db.emailBounces.findByEmail).toHaveBeenCalledTimes(2);
expect(db.emailBounces.findByEmail).toHaveBeenCalledWith(
'test+alias@other.com'
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test’s description and inline comment state that for non-configured domains, both bounce queries should use the original email, but the expectations only assert that findByEmail is called twice and that it was called with 'test+alias@other.com' at least once. As written, an implementation that uses the original email once and a transformed value the second time would still pass. To fully verify the intended behavior, consider asserting each call explicitly (for example, using toHaveBeenNthCalledWith for both calls, or checking the argument list of all invocations) so the test will fail if the wildcard query ever starts transforming the address for non-configured domains.

Copilot uses AI. Check for mistakes.
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { AppError } from '@fxa/accounts/errors';
import { EmailNormalization } from 'fxa-shared/email/email-normalization';
Copy link
Contributor

@dschom dschom Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not reference fxa-shared from libs... Can we just move this function here?

Copy link
Contributor

@dschom dschom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to actually use this routine in auth-server now to full fill the ticket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants