Skip to content

test: added missing integration tests for Auth, Messaging, Functions and Firestore apis#195

Merged
demolaf merged 11 commits intomainfrom
missing-tests
Mar 24, 2026
Merged

test: added missing integration tests for Auth, Messaging, Functions and Firestore apis#195
demolaf merged 11 commits intomainfrom
missing-tests

Conversation

@demolaf
Copy link
Copy Markdown
Member

@demolaf demolaf commented Mar 23, 2026

This PR adds missing unit and integration tests across Auth, App Check, Messaging, Functions, and Firestore, and fixes several bugs uncovered in the process.

Bug fixes

  • fix(auth) — verifySessionCookie was always failing with an invalid signature error because dart_jsonwebtoken 3.x added checkHeaderType=true by default, rejecting Firebase session cookies that omit the typ header claim. Disabled the check since signature, issuer, audience, and expiry are all validated independently.
  • fix(auth) — updateProviderConfig had no effect for OIDC and SAML providers. generateUpdateMask expects a Map but was receiving a raw googleapis object, causing it to return an empty list and the PATCH request to update nothing. Fixed by calling .toJson() before passing to generateUpdateMask.
  • fix(app-check) — createToken with ttlMillis silently dropped the option. The App Check exchange API reads the TTL from the signed custom token's claims, but token_generator.dart never wrote a ttl claim into the JWT body. Fixed by including the claim when ttlMillis is set.
  • fix(storage) — STORAGE_EMULATOR_HOST set by an emulator-mode Storage instance leaked into subsequent production Storage instances in the same process (the google_cloud_storage package reads it via native FFI, bypassing Dart zone overrides). Added unsetNativeEnvironmentVariable and call it in the production Storage constructor to clear any leftover value.

New tests

  • App Check — integration tests for createToken (JWT structure, TTL range, custom TTL) and verifyToken
  • Auth — integration tests for OIDC/SAML provider config CRUD; unit tests for ConditionMessage serialisation; production-mode integration tests for verifySessionCookie, createSessionCookie, and verifyIdToken
  • Messaging — unit tests for ConditionMessage send path
  • Functions — unit and integration tests for TaskOptionsExperimental URI handling
  • Firestore — unit tests for the terminate() method

@gemini-code-assist
Copy link
Copy Markdown

Warning

Gemini is experiencing higher than usual traffic and was unable to create the summary. Please try again in a few hours by commenting /gemini summary.

@demolaf demolaf changed the title Missing tests test: added missing integration tests for Auth, Messaging, Functions and Firestore apis Mar 23, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

Coverage Report

✅ Coverage 74.58% meets 40% threshold

Total Coverage: 74.58%
Lines Covered: 5018/6728

Package Breakdown

Package Coverage
dart_firebase_admin 72.44%
google_cloud_firestore 77.01%

Minimum threshold: 40%

@demolaf demolaf marked this pull request as draft March 23, 2026 15:22
demolaf added 5 commits March 24, 2026 03:26
Firebase session cookies omit the `typ` header claim. dart_jsonwebtoken
3.x added checkHeaderType=true as the default which rejects tokens without
`typ: "JWT"`, causing verifySessionCookie to always fail with an invalid
signature error. Disable the check since signature, issuer, audience, and
expiry are all validated independently.
generateUpdateMask expects a Map but was receiving a raw googleapis object,
causing it to return an empty list. An empty update mask sent to the PATCH
endpoint results in no fields being updated, so updateProviderConfig had no
effect. Calling toJson() first produces the Map that generateUpdateMask can
traverse.
…mode

The google_cloud_storage package reads STORAGE_EMULATOR_HOST via native
FFI (getenv), bypassing Dart zone overrides. If an emulator-mode Storage
instance runs first it sets the native env var, which then leaks into any
subsequent production Storage instance in the same process, causing
getDownloadURL to hit the emulator and return 404.

Add unsetNativeEnvironmentVariable and call it in Storage._ when not in
emulator mode to clear any previously set value.
The Firebase App Check exchangeCustomToken API reads the TTL for the
resulting token from the signed custom token's claims, not from the
exchange request body. The ttlMillis option was accepted but silently
dropped because token_generator.dart never wrote a ttl claim into the
JWT body.
OIDCAuthProviderConfig._validate requires clientSecret to be a non-empty
string when creating a provider config. The integration test fixtures were
missing this field, causing all OIDC createProviderConfig calls to throw.
@demolaf
Copy link
Copy Markdown
Member Author

demolaf commented Mar 24, 2026

/gemini summary

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

This pull request primarily focuses on enhancing the dart_firebase_admin library by adding missing integration tests for several core Firebase services (Auth, Messaging, Functions, and Firestore). Alongside the new tests, several minor bug fixes and feature enhancements were implemented, including improved App Check token generation, correct handling of Auth provider configuration updates, better management of the Storage emulator host environment variable, and a fix for JWT verification with Firebase session cookies. These changes improve the robustness and reliability of the library's interactions with Firebase services.

Highlights

  • App Check Token Generation: Added support for specifying a custom time-to-live (TTL) for App Check tokens during generation.
  • Auth Provider Configuration Updates: Corrected the handling of update masks for OAuth and SAML identity provider configurations in Auth, ensuring proper serialization of request bodies.
  • Storage Emulator Host Management: Implemented logic to explicitly unset the STORAGE_EMULATOR_HOST environment variable when the Storage service is not configured for emulator use, preventing potential environment leaks.
  • JWT Verification Flexibility: Modified JWT verification to disable the typ header check, accommodating Firebase session cookies which omit this claim.
  • Native Environment Variable Utility: Introduced a cross-platform utility function for unsetting native environment variables.
  • Expanded Integration Tests: Significantly expanded integration test coverage for App Check, Auth, Messaging, and Functions APIs, including new scenarios for token management, provider configurations, user retrieval, ID token verification, and task queueing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/dart_firebase_admin/lib/src/app_check/token_generator.dart
    • Added ttl claim to App Check token body when options?.ttlMillis is provided.
  • packages/dart_firebase_admin/lib/src/auth/auth_request_handler.dart
    • Updated generateUpdateMask calls to use request?.toJson() for updateOAuthIdpConfig and updateInboundSamlConfig.
  • packages/dart_firebase_admin/lib/src/storage/storage.dart
    • Added logic to unset STORAGE_EMULATOR_HOST when not in emulator mode.
  • packages/dart_firebase_admin/lib/src/utils/jwt.dart
    • Modified JWT.verify to disable checkHeaderType for Firebase session cookies.
  • packages/dart_firebase_admin/lib/src/utils/native_environment.dart
    • Added _unsetenv function and unsetNativeEnvironmentVariable for cross-platform environment variable removal.
  • packages/dart_firebase_admin/test/integration/app_check/app_check_test.dart
    • Added new integration tests for AppCheck.createToken and AppCheck.verifyToken, covering token generation, custom TTL, and token consumption.
  • packages/dart_firebase_admin/test/integration/auth/auth_prod_test.dart
    • Added integration tests for getProviderConfig, updateProviderConfig (OIDC and SAML), and listProviderConfigs (OIDC and SAML, including pagination).
  • packages/dart_firebase_admin/test/integration/auth/auth_test.dart
    • Added integration tests for getUser and verifyIdToken, including revocation checks.
  • packages/dart_firebase_admin/test/integration/functions/functions_test.dart
    • Added an integration test for enqueuing a task with an experimental URI.
  • packages/dart_firebase_admin/test/integration/messaging/messaging_test.dart
    • Added integration tests for send(ConditionMessage, dryRun) and sendEach() with mixed message types.
  • packages/dart_firebase_admin/test/unit/app_check/app_check_test.dart
    • Removed dart:async and ../../fixtures/helpers.dart imports.
    • Removed e2e tests which were moved to integration tests.
  • packages/dart_firebase_admin/test/unit/functions/functions_test.dart
    • Added a test for the app property.
    • Added unit tests for TaskOptionsExperimental.uri validation.
    • Added a test to verify experimental.uri is used as httpRequest URL.
  • packages/dart_firebase_admin/test/unit/messaging/messaging_test.dart
    • Added a unit test for sending a ConditionMessage.
  • packages/google_cloud_firestore/test/unit/firestore_test.dart
    • Added MockFirestoreHttpClient.
    • Added a unit test for terminate() calling close() on the HTTP client.
Activity
  • A bot initially failed to create a summary due to high traffic.
  • A coverage report was generated, showing 74.58% total coverage.
  • The author requested a summary again.

@demolaf demolaf marked this pull request as ready for review March 24, 2026 09:54
@demolaf demolaf merged commit d50b550 into main Mar 24, 2026
11 checks passed
@demolaf demolaf deleted the missing-tests branch March 24, 2026 10:55
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.

1 participant