Skip to content

Commit 248f654

Browse files
committed
Added ssl check for firestore
1 parent ec405ae commit 248f654

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/firestore/src/lite-api/database.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ export function connectFirestoreEmulator(
325325
} = {}
326326
): void {
327327
firestore = cast(firestore, Firestore);
328+
let ssl = false;
329+
if (/^https:\/\//.test(host)) {
330+
ssl = true;
331+
host = host.substring(8);
332+
}
328333
const settings = firestore._getSettings();
329334
const existingConfig = {
330335
...settings,
@@ -340,7 +345,7 @@ export function connectFirestoreEmulator(
340345
const newConfig = {
341346
...settings,
342347
host: newHostSetting,
343-
ssl: false,
348+
ssl,
344349
emulatorOptions: options
345350
};
346351
// No-op if the new configuration matches the current configuration. This supports SSR

packages/firestore/test/unit/api/database.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,17 @@ describe('Settings', () => {
564564
expect(db._getEmulatorOptions()).to.equal(emulatorOptions);
565565
});
566566

567+
it('sets ssl to true if prefixed with https://', () => {
568+
// Use a new instance of Firestore in order to configure settings.
569+
const db = newTestFirestore();
570+
const emulatorOptions = { mockUserToken: 'test' };
571+
connectFirestoreEmulator(db, 'https://127.0.0.1', 9000, emulatorOptions);
572+
573+
expect(db._getSettings().host).to.exist.and.to.equal('127.0.0.1:9000');
574+
expect(db._getSettings().ssl).to.exist.and.to.be.true;
575+
expect(db._getEmulatorOptions()).to.equal(emulatorOptions);
576+
});
577+
567578
it('prefers host from useEmulator to host from settings', () => {
568579
// Use a new instance of Firestore in order to configure settings.
569580
const db = newTestFirestore();

0 commit comments

Comments
 (0)