Skip to content

Add support for running the emulators over SSL #8967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/gentle-laws-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@firebase/database-compat": patch
"@firebase/database-types": patch
"@firebase/database": patch
"@firebase/firestore": patch
"@firebase/functions": patch
"@firebase/storage": patch
---

Add SSL checks to `connectDatabaseEmulator` and `connectFirestoreEmulator`
1 change: 1 addition & 0 deletions common/api-review/database.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function child(parent: DatabaseReference, path: string): DatabaseReferenc
// @public
export function connectDatabaseEmulator(db: Database, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
ssl?: boolean;
}): void;

// @public
Expand Down
1 change: 1 addition & 0 deletions common/api-review/firestore-lite.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class CollectionReference<AppModelType = DocumentData, DbModelType extend
// @public
export function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
ssl?: boolean;
}): void;

// @public
Expand Down
1 change: 1 addition & 0 deletions common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class CollectionReference<AppModelType = DocumentData, DbModelType extend
// @public
export function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
ssl?: boolean;
}): void;

// @public
Expand Down
2 changes: 1 addition & 1 deletion common/api-review/functions.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FirebaseApp } from '@firebase/app';
import { FirebaseError } from '@firebase/util';

// @public
export function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void;
export function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number, ssl?: boolean): void;

// @public
export interface Functions {
Expand Down
1 change: 1 addition & 0 deletions common/api-review/storage.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Unsubscribe } from '@firebase/util';
// @public
export function connectStorageEmulator(storage: FirebaseStorage, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
ssl?: boolean;
}): void;

// Warning: (ae-forgotten-export) The symbol "StringData" needs to be exported by the entry point index.d.ts
Expand Down
7 changes: 4 additions & 3 deletions docs-devsite/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Firebase Realtime Database
| <b>function(app, ...)</b> |
| [getDatabase(app, url)](./database.md#getdatabase_d9cea01) | Returns the instance of the Realtime Database SDK that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface)<!-- -->. Initializes a new instance with default settings if no instance exists or if the existing instance uses a custom database URL. |
| <b>function(db, ...)</b> |
| [connectDatabaseEmulator(db, host, port, options)](./database.md#connectdatabaseemulator_27b9e93) | Modify the provided instance to communicate with the Realtime Database emulator.<p>Note: This method must be called before performing any other operation. |
| [connectDatabaseEmulator(db, host, port, options)](./database.md#connectdatabaseemulator_20a9664) | Modify the provided instance to communicate with the Realtime Database emulator.<p>Note: This method must be called before performing any other operation. |
| [goOffline(db)](./database.md#gooffline_732b338) | Disconnects from the server (all Database operations will be completed offline).<!-- -->The client automatically maintains a persistent connection to the Database server, which will remain active indefinitely and reconnect when disconnected. However, the <code>goOffline()</code> and <code>goOnline()</code> methods may be used to control the client connection in cases where a persistent connection is undesirable.<!-- -->While offline, the client will no longer receive data updates from the Database. However, all Database operations performed locally will continue to immediately fire events, allowing your application to continue behaving normally. Additionally, each operation performed locally will automatically be queued and retried upon reconnection to the Database server.<!-- -->To reconnect to the Database and begin receiving remote events, see <code>goOnline()</code>. |
| [goOnline(db)](./database.md#goonline_732b338) | Reconnects to the server and synchronizes the offline Database state with the server state.<!-- -->This method should be used after disabling the active connection with <code>goOffline()</code>. Once reconnected, the client will transmit the proper data and fire the appropriate events so that your client "catches up" automatically. |
| [ref(db, path)](./database.md#ref_5f88fa2) | Returns a <code>Reference</code> representing the location in the Database corresponding to the provided path. If no path is provided, the <code>Reference</code> will point to the root of the Database. |
Expand Down Expand Up @@ -135,7 +135,7 @@ The `Database` instance of the provided app.

## function(db, ...)

### connectDatabaseEmulator(db, host, port, options) {:#connectdatabaseemulator_27b9e93}
### connectDatabaseEmulator(db, host, port, options) {:#connectdatabaseemulator_20a9664}

Modify the provided instance to communicate with the Realtime Database emulator.

Expand All @@ -146,6 +146,7 @@ Modify the provided instance to communicate with the Realtime Database emulator.
```typescript
export declare function connectDatabaseEmulator(db: Database, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
ssl?: boolean;
}): void;
```

Expand All @@ -156,7 +157,7 @@ export declare function connectDatabaseEmulator(db: Database, host: string, port
| db | [Database](./database.database.md#database_class) | The instance to modify. |
| host | string | The emulator host (ex: localhost) |
| port | number | The emulator port (ex: 8080) |
| options | { mockUserToken?: [EmulatorMockTokenOptions](./util.md#emulatormocktokenoptions) \| string; } | |
| options | { mockUserToken?: [EmulatorMockTokenOptions](./util.md#emulatormocktokenoptions) \| string; ssl?: boolean; } | |

<b>Returns:</b>

Expand Down
7 changes: 4 additions & 3 deletions docs-devsite/firestore_.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ https://github.com/firebase/firebase-js-sdk
| [clearIndexedDbPersistence(firestore)](./firestore_.md#clearindexeddbpersistence_231a8e0) | Clears the persistent storage. This includes pending writes and cached documents.<!-- -->Must be called while the [Firestore](./firestore_.firestore.md#firestore_class) instance is not started (after the app is terminated or when the app is first initialized). On startup, this function must be called before other functions (other than [initializeFirestore()](./firestore_.md#initializefirestore_fc7d200) or [getFirestore()](./firestore_.md#getfirestore)<!-- -->)). If the [Firestore](./firestore_.firestore.md#firestore_class) instance is still running, the promise will be rejected with the error code of <code>failed-precondition</code>.<!-- -->Note: <code>clearIndexedDbPersistence()</code> is primarily intended to help write reliable tests that use Cloud Firestore. It uses an efficient mechanism for dropping existing data but does not attempt to securely overwrite or otherwise make cached data unrecoverable. For applications that are sensitive to the disclosure of cached data in between user sessions, we strongly recommend not enabling persistence at all. |
| [collection(firestore, path, pathSegments)](./firestore_.md#collection_1eb4c23) | Gets a <code>CollectionReference</code> instance that refers to the collection at the specified absolute path. |
| [collectionGroup(firestore, collectionId)](./firestore_.md#collectiongroup_1838fc3) | Creates and returns a new <code>Query</code> instance that includes all documents in the database that are contained in a collection or subcollection with the given <code>collectionId</code>. |
| [connectFirestoreEmulator(firestore, host, port, options)](./firestore_.md#connectfirestoreemulator_7c247cd) | Modify this instance to communicate with the Cloud Firestore emulator.<!-- -->Note: This must be called before this instance has been used to do any operations. |
| [connectFirestoreEmulator(firestore, host, port, options)](./firestore_.md#connectfirestoreemulator_6c8868a) | Modify this instance to communicate with the Cloud Firestore emulator.<!-- -->Note: This must be called before this instance has been used to do any operations. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know what role this comment is meant to play in the generated docs?

It is in most (but not all, see database.md) of the identical added doc blurbs.

| [disableNetwork(firestore)](./firestore_.md#disablenetwork_231a8e0) | Disables network usage for this instance. It can be re-enabled via [enableNetwork()](./firestore_.md#enablenetwork_231a8e0)<!-- -->. While the network is disabled, any snapshot listeners, <code>getDoc()</code> or <code>getDocs()</code> calls will return results from cache, and any write operations will be queued until the network is restored. |
| [doc(firestore, path, pathSegments)](./firestore_.md#doc_1eb4c23) | Gets a <code>DocumentReference</code> instance that refers to the document at the specified absolute path. |
| [enableIndexedDbPersistence(firestore, persistenceSettings)](./firestore_.md#enableindexeddbpersistence_224174f) | Attempts to enable persistent storage, if possible.<!-- -->On failure, <code>enableIndexedDbPersistence()</code> will reject the promise or throw an exception. There are several reasons why this can fail, which can be identified by the <code>code</code> on the error.<!-- -->\* failed-precondition: The app is already open in another browser tab. \* unimplemented: The browser is incompatible with the offline persistence implementation.<!-- -->Note that even after a failure, the [Firestore](./firestore_.firestore.md#firestore_class) instance will remain usable, however offline persistence will be disabled.<!-- -->Note: <code>enableIndexedDbPersistence()</code> must be called before any other functions (other than [initializeFirestore()](./firestore_.md#initializefirestore_fc7d200)<!-- -->, [getFirestore()](./firestore_.md#getfirestore) or [clearIndexedDbPersistence()](./firestore_.md#clearindexeddbpersistence_231a8e0)<!-- -->.<!-- -->Persistence cannot be used in a Node.js environment. |
Expand Down Expand Up @@ -377,7 +377,7 @@ export declare function collectionGroup(firestore: Firestore, collectionId: stri

The created `Query`<!-- -->.

### connectFirestoreEmulator(firestore, host, port, options) {:#connectfirestoreemulator_7c247cd}
### connectFirestoreEmulator(firestore, host, port, options) {:#connectfirestoreemulator_6c8868a}

Modify this instance to communicate with the Cloud Firestore emulator.

Expand All @@ -388,6 +388,7 @@ Note: This must be called before this instance has been used to do any operation
```typescript
export declare function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
ssl?: boolean;
}): void;
```

Expand All @@ -398,7 +399,7 @@ export declare function connectFirestoreEmulator(firestore: Firestore, host: str
| firestore | [Firestore](./firestore_.firestore.md#firestore_class) | The <code>Firestore</code> instance to configure to connect to the emulator. |
| host | string | the emulator host (ex: localhost). |
| port | number | the emulator port (ex: 9000). |
| options | { mockUserToken?: [EmulatorMockTokenOptions](./util.md#emulatormocktokenoptions) \| string; } | |
| options | { mockUserToken?: [EmulatorMockTokenOptions](./util.md#emulatormocktokenoptions) \| string; ssl?: boolean; } | |

<b>Returns:</b>

Expand Down
7 changes: 4 additions & 3 deletions docs-devsite/firestore_lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ https://github.com/firebase/firebase-js-sdk
| <b>function(firestore, ...)</b> |
| [collection(firestore, path, pathSegments)](./firestore_lite.md#collection_1eb4c23) | Gets a <code>CollectionReference</code> instance that refers to the collection at the specified absolute path. |
| [collectionGroup(firestore, collectionId)](./firestore_lite.md#collectiongroup_1838fc3) | Creates and returns a new <code>Query</code> instance that includes all documents in the database that are contained in a collection or subcollection with the given <code>collectionId</code>. |
| [connectFirestoreEmulator(firestore, host, port, options)](./firestore_lite.md#connectfirestoreemulator_7c247cd) | Modify this instance to communicate with the Cloud Firestore emulator.<!-- -->Note: This must be called before this instance has been used to do any operations. |
| [connectFirestoreEmulator(firestore, host, port, options)](./firestore_lite.md#connectfirestoreemulator_6c8868a) | Modify this instance to communicate with the Cloud Firestore emulator.<!-- -->Note: This must be called before this instance has been used to do any operations. |
| [doc(firestore, path, pathSegments)](./firestore_lite.md#doc_1eb4c23) | Gets a <code>DocumentReference</code> instance that refers to the document at the specified absolute path. |
| [runTransaction(firestore, updateFunction, options)](./firestore_lite.md#runtransaction_6f03ec4) | Executes the given <code>updateFunction</code> and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, Cloud Firestore retries the <code>updateFunction</code>. If it fails to commit after 5 attempts, the transaction fails.<!-- -->The maximum number of writes allowed in a single transaction is 500. |
| [terminate(firestore)](./firestore_lite.md#terminate_231a8e0) | Terminates the provided <code>Firestore</code> instance.<!-- -->After calling <code>terminate()</code> only the <code>clearIndexedDbPersistence()</code> functions may be used. Any other function will throw a <code>FirestoreError</code>. Termination does not cancel any pending writes, and any promises that are awaiting a response from the server will not be resolved.<!-- -->To restart after termination, create a new instance of <code>Firestore</code> with [getFirestore()](./firestore_.md#getfirestore)<!-- -->.<!-- -->Note: Under normal circumstances, calling <code>terminate()</code> is not required. This function is useful only when you want to force this instance to release all of its resources or in combination with [clearIndexedDbPersistence()](./firestore_.md#clearindexeddbpersistence_231a8e0) to ensure that all local state is destroyed between test runs. |
Expand Down Expand Up @@ -308,7 +308,7 @@ export declare function collectionGroup(firestore: Firestore, collectionId: stri

The created `Query`<!-- -->.

### connectFirestoreEmulator(firestore, host, port, options) {:#connectfirestoreemulator_7c247cd}
### connectFirestoreEmulator(firestore, host, port, options) {:#connectfirestoreemulator_6c8868a}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this get updated? Just vagaries of the generation process I guess?


Modify this instance to communicate with the Cloud Firestore emulator.

Expand All @@ -319,6 +319,7 @@ Note: This must be called before this instance has been used to do any operation
```typescript
export declare function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
ssl?: boolean;
}): void;
```

Expand All @@ -329,7 +330,7 @@ export declare function connectFirestoreEmulator(firestore: Firestore, host: str
| firestore | [Firestore](./firestore_lite.firestore.md#firestore_class) | The <code>Firestore</code> instance to configure to connect to the emulator. |
| host | string | the emulator host (ex: localhost). |
| port | number | the emulator port (ex: 9000). |
| options | { mockUserToken?: [EmulatorMockTokenOptions](./util.md#emulatormocktokenoptions) \| string; } | |
| options | { mockUserToken?: [EmulatorMockTokenOptions](./util.md#emulatormocktokenoptions) \| string; ssl?: boolean; } | |

<b>Returns:</b>

Expand Down
7 changes: 4 additions & 3 deletions docs-devsite/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Cloud Functions for Firebase
| <b>function(app, ...)</b> |
| [getFunctions(app, regionOrCustomDomain)](./functions.md#getfunctions_60f2095) | Returns a [Functions](./functions.functions.md#functions_interface) instance for the given app. |
| <b>function(functionsInstance, ...)</b> |
| [connectFunctionsEmulator(functionsInstance, host, port)](./functions.md#connectfunctionsemulator_505c08d) | Modify this instance to communicate with the Cloud Functions emulator.<!-- -->Note: this must be called before this instance has been used to do any operations. |
| [connectFunctionsEmulator(functionsInstance, host, port, ssl)](./functions.md#connectfunctionsemulator_a989598) | Modify this instance to communicate with the Cloud Functions emulator.<!-- -->Note: this must be called before this instance has been used to do any operations. |
| [httpsCallable(functionsInstance, name, options)](./functions.md#httpscallable_1dd297c) | Returns a reference to the callable HTTPS trigger with the given name. |
| [httpsCallableFromURL(functionsInstance, url, options)](./functions.md#httpscallablefromurl_7af6987) | Returns a reference to the callable HTTPS trigger with the specified url. |

Expand Down Expand Up @@ -72,7 +72,7 @@ export declare function getFunctions(app?: FirebaseApp, regionOrCustomDomain?: s

## function(functionsInstance, ...)

### connectFunctionsEmulator(functionsInstance, host, port) {:#connectfunctionsemulator_505c08d}
### connectFunctionsEmulator(functionsInstance, host, port, ssl) {:#connectfunctionsemulator_a989598}

Modify this instance to communicate with the Cloud Functions emulator.

Expand All @@ -81,7 +81,7 @@ Note: this must be called before this instance has been used to do any operation
<b>Signature:</b>

```typescript
export declare function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void;
export declare function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number, ssl?: boolean): void;
```

#### Parameters
Expand All @@ -91,6 +91,7 @@ export declare function connectFunctionsEmulator(functionsInstance: Functions, h
| functionsInstance | [Functions](./functions.functions.md#functions_interface) | |
| host | string | The emulator host (ex: localhost) |
| port | number | The emulator port (ex: 5001) |
| ssl | boolean | |

<b>Returns:</b>

Expand Down
7 changes: 4 additions & 3 deletions docs-devsite/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Cloud Storage for Firebase
| <b>function(app, ...)</b> |
| [getStorage(app, bucketUrl)](./storage.md#getstorage_25f3a57) | Gets a [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance for the given Firebase app. |
| <b>function(storage, ...)</b> |
| [connectStorageEmulator(storage, host, port, options)](./storage.md#connectstorageemulator_e9039de) | Modify this [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance to communicate with the Cloud Storage emulator. |
| [connectStorageEmulator(storage, host, port, options)](./storage.md#connectstorageemulator_ac343b7) | Modify this [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance to communicate with the Cloud Storage emulator. |
| [ref(storage, url)](./storage.md#ref_5672fc1) | Returns a [StorageReference](./storage.storagereference.md#storagereference_interface) for the given url. |
| <b>function(ref, ...)</b> |
| [deleteObject(ref)](./storage.md#deleteobject_30df0b2) | Deletes the object at this location. |
Expand Down Expand Up @@ -106,7 +106,7 @@ A [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) inst

## function(storage, ...)

### connectStorageEmulator(storage, host, port, options) {:#connectstorageemulator_e9039de}
### connectStorageEmulator(storage, host, port, options) {:#connectstorageemulator_ac343b7}

Modify this [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance to communicate with the Cloud Storage emulator.

Expand All @@ -115,6 +115,7 @@ Modify this [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_inter
```typescript
export declare function connectStorageEmulator(storage: FirebaseStorage, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
ssl?: boolean;
}): void;
```

Expand All @@ -125,7 +126,7 @@ export declare function connectStorageEmulator(storage: FirebaseStorage, host: s
| storage | [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) | The [FirebaseStorage](./storage.firebasestorage.md#firebasestorage_interface) instance |
| host | string | The emulator host (ex: localhost) |
| port | number | The emulator port (ex: 5001) |
| options | { mockUserToken?: [EmulatorMockTokenOptions](./util.md#emulatormocktokenoptions) \| string; } | Emulator options. <code>options.mockUserToken</code> is the mock auth token to use for unit testing Security Rules. |
| options | { mockUserToken?: [EmulatorMockTokenOptions](./util.md#emulatormocktokenoptions) \| string; ssl?: boolean; } | Emulator options. <code>options.mockUserToken</code> is the mock auth token to use for unit testing Security Rules. |

<b>Returns:</b>

Expand Down
Loading
Loading