Skip to content

Conversation

@sreecharan-desu
Copy link
Contributor

Fixes #16491. This PR updates the Redis wrapper in to safely access metrics methods (, ) using optional chaining (). This prevents crashes (e.g., ) when the metrics object is undefined or mocked incompletely, such as in certain test environments or when metrics are disabled via configuration.

@sreecharan-desu sreecharan-desu requested a review from a team as a code owner January 23, 2026 18:04
@sreecharan-desu sreecharan-desu force-pushed the fix/auth-server-redis-metrics-16491 branch from 5ba5528 to 31782fe Compare January 23, 2026 18:30
@dschom
Copy link
Contributor

dschom commented Feb 12, 2026

Fixes #16491. This PR updates the Redis wrapper in to safely access metrics methods (, ) using optional chaining (). This prevents crashes (e.g., ) when the metrics object is undefined or mocked incompletely, such as in certain test environments or when metrics are disabled via configuration.

Thank you for this contribution! We'd like to request that the mocks are fixed instead of using optional chaining. Although this.metrics is optional, we don't want to mask an incorrect instantiation or mock by making the methods themselves optional.

@sreecharan-desu
Copy link
Contributor Author

Thanks for the feedback! Reverted the optional chaining on methods and fixed the mock injection in instead. this.metrics is now properly instantiated with mocks.

@sreecharan-desu sreecharan-desu force-pushed the fix/auth-server-redis-metrics-16491 branch from afd08ad to 8aa82a2 Compare February 12, 2026 04:34
@sreecharan-desu
Copy link
Contributor Author

Tests for Redis metrics implementation are passing locally with Docker:

        ✔ removes all tokens for the user
        ✔ does nothing for nonexistent users
        ✔ does nothing for nonexistent clients
    Refresh Token Metadata
      setRefreshToken
        ✔ sets expiry
        ✔ prunes old tokens
        ✔ maxes out at 20 recent tokens

  Redis down
    touchSessionToken
      ✔ returns without error
    getSessionTokens
      ✔ returns an empty object without error
    pruneSessionTokens
      ✔ throws a timeout error


  43 passing (191ms)

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.

fxa-auth-server mock statsd lacks of function histogram

2 participants