Skip to content

fix(firestore): honour Settings.ssl when building the API endpoint - #316

Open
Lyokone wants to merge 1 commit into
mainfrom
fix/settings-ssl
Open

fix(firestore): honour Settings.ssl when building the API endpoint#316
Lyokone wants to merge 1 commit into
mainfrom
fix/settings-ssl

Conversation

@Lyokone

@Lyokone Lyokone commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Problem

Settings.ssl is a dead field. It is stored, carried through copyWith, and compared in ==/hashCode — but nothing ever reads it:

Uri get _firestoreApiHost {
  final emulatorHost = Environment.getFirestoreEmulatorHost(...);
  if (emulatorHost != null) return Uri.http(emulatorHost, '/');
  return Uri.https(_settings.host ?? 'firestore.googleapis.com', '/'); // ssl never consulted
}

So a custom Settings.host could not be reached over plain HTTP, and ssl: false silently did nothing.

This is observable today: test/fixtures/helpers.dart passes ssl: false next to a custom host for emulator tests. It works only because FIRESTORE_EMULATOR_HOST is also set, which takes a separate branch that happens to hardcode HTTP. Remove the ssl: false there and nothing changes.

Fix

The scheme now follows Settings.ssl on the non-emulator path.

FIRESTORE_EMULATOR_HOST keeps precedence over both host and ssl, since it is the documented way to point the SDK at an emulator — only the custom-host path changes behaviour. The default remains ssl: true, so production callers are unaffected, and nobody can be depending on the current behaviour because there is no way to observe it.

_firestoreApiHost is now firestoreApiHost (@internal, @visibleForTesting) so the resolution can be asserted directly, matching how other tests in this package reach into src/.

The Settings.ssl doc comment described behaviour the field did not have; it is corrected too.

Tests

test/firestore_api_host_test.dart covers five cases: the production default, custom host with ssl: true, custom host with ssl: false, default host with ssl: false, and FIRESTORE_EMULATOR_HOST overriding both.

Each test passes environmentOverride so an ambient FIRESTORE_EMULATOR_HOST cannot leak into the expectations.

Verified the tests are not vacuous — with the one-line fix reverted, exactly the two ssl: false cases fail and the other three still pass, so they act as regression guards:

### with the fix reverted:
00:00 +3 -2: Some tests failed.
  firestoreApiHost uses HTTP against the default host when ssl is false
  firestoreApiHost uses HTTP for a custom host when ssl is false

Full package suite: +266 -7. The 7 failures are pre-existing on main — all bundle_test.dart, failing with MetadataServerException: Could not connect to metadata.google.internal because they need a project ID from the environment that CI supplies via the emulator. Confirmed identical on a pristine checkout, so there is no regression here.

dart analyze clean, dart format clean.

Note

No CHANGELOG entry: 0.5.3 is already released and this repo's release commits collect entries, so I left the next version to the releaser. Happy to add one if you would rather it land with the PR.

`Settings.ssl` was a dead field. It was stored, carried through copyWith,
and compared in == and hashCode, but nothing ever read it: the endpoint
was built with `Uri.https(...)` unconditionally unless
FIRESTORE_EMULATOR_HOST was set. A custom `Settings.host` therefore could
not be reached over plain HTTP, and `ssl: false` did nothing.

The scheme now follows `Settings.ssl` on the non-emulator path.
FIRESTORE_EMULATOR_HOST keeps precedence over both `host` and `ssl`,
since it is the documented way to point the SDK at an emulator; only the
custom-host path changes behaviour. The default stays `ssl: true`, so
production callers are unaffected.

Note that test/fixtures/helpers.dart already passed `ssl: false` next to
a custom host for emulator tests, and worked only because the separate
FIRESTORE_EMULATOR_HOST branch happened to hardcode HTTP.

Also corrects the `Settings.ssl` doc comment, which described behaviour
the field did not have.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Firestore client to respect the ssl setting when constructing the API host URI, allowing connections over plain HTTP when ssl is set to false. It also exposes the firestoreApiHost getter for testing and adds comprehensive unit tests to verify the URI resolution logic under different configurations. There are no review comments, and I have no feedback to provide.

@github-actions

Copy link
Copy Markdown

Coverage Report

✅ Coverage 75.69% meets 40% threshold

Total Coverage: 75.69%
Lines Covered: 5287/6985

Package Breakdown

Package Coverage
google_cloud_firestore 78.76%
firebase_admin_sdk 73.02%

Minimum threshold: 40%

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