Conversation

jonathanedey

es time.time and google.auth.jwt._helpers.utcnowto use a fixed timestamp (MOCK_CURRENT_TIME) in tests/test_token_gen.py and tests/test_tenant_mgt.py.

This addresses test flakiness and inconsistencies by ensuring that:

  • Tokens and cookies are generated with predictable iat and exp claims based on MOCK_CURRENT_TIME.
  • The verification logic within the Firebase Admin SDK and the underlying google-auth library also uses MOCK_CURRENT_TIME.

google-labs-jules bot and others added 3 commits May 26, 2025 20:20
…ation tests

es time.time and google.auth.jwt._helpers.utcnow to use a fixed
timestamp (MOCK_CURRENT_TIME) throughout tests/test_token_gen.py.

This addresses test flakiness and inconsistencies by ensuring that:
1. Tokens and cookies are generated with predictable `iat` and `exp` claims
   based on MOCK_CURRENT_TIME.
2. The verification logic within the Firebase Admin SDK and the underlying
   google-auth library also uses MOCK_CURRENT_TIME.

Helper functions _get_id_token and _get_session_cookie were updated to
default to using MOCK_CURRENT_TIME for their internal time calculations,
simplifying test code.

Relevant fixtures and token definitions were updated to rely on these
new defaults and the fixed timestamp.

The setup_method in TestVerifyIdToken, TestVerifySessionCookie,
TestCertificateCaching, and TestCertificateFetchTimeout now mock
time.time and google.auth.jwt._helpers.utcnow to ensure that all
time-sensitive operations during testing use the MOCK_CURRENT_TIME.
Extends the time mocking strategy (using a fixed MOCK_CURRENT_TIME)
to tests in `tests/test_tenant_mgt.py` to ensure consistency with
changes previously made in `tests/test_token_gen.py`.

Specifically:
- Imported `MOCK_CURRENT_TIME` from `tests.test_token_gen`.
- Added `setup_method` (and `teardown_method`) to the
  `TestVerifyIdToken` and `TestCreateCustomToken` classes.
- These setup methods  `time.time` and
  `google.auth.jwt._helpers.utcnow` to return `MOCK_CURRENT_TIME`
  (or its datetime equivalent).

This ensures that token generation (for custom tokens) and token
verification within `test_tenant_mgt.py` align with the mocked
timeline, preventing potential flakiness or failures due to
time inconsistencies. All tests in `test_tenant_mgt.py` pass
with these changes.
@jonathanedeyjonathanedey merged commit 2d9b18c into master May 27, 2025
13 checks passed
@jonathanedeyjonathanedey deleted the je-fix-mock-time-token-tests branch May 27, 2025 13:07
Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.