Skip to content

Commit 4bc9433

Browse files
committed
Added tests
1 parent 205f9ca commit 4bc9433

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

.changeset/gentle-laws-kneel.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"@firebase/database": patch
55
"@firebase/firestore": patch
66
"@firebase/functions": patch
7+
"@firebase/storage": patch
78
---
89

910
Add SSL checks to `connectDatabaseEmulator` and `connectFirestoreEmulator`

packages/storage/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export function connectStorageEmulator(
359359
port: number,
360360
options: {
361361
mockUserToken?: EmulatorMockTokenOptions | string;
362+
ssl?: boolean;
362363
} = {}
363364
): void {
364365
connectEmulatorInternal(storage as FirebaseStorageImpl, host, port, options);

packages/storage/src/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function connectStorageEmulator(
142142
} = {}
143143
): void {
144144
storage.host = `${host}:${port}`;
145-
storage._protocol = options.ssl ? 'http' : 'https';
145+
storage._protocol = options.ssl ? 'https' : 'http';
146146
const { mockUserToken } = options;
147147
if (mockUserToken) {
148148
storage._overrideAuthToken =

packages/storage/test/unit/service.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,27 @@ GOOG4-RSA-SHA256`
248248
expect(service._protocol).to.equal('http');
249249
void getDownloadURL(ref(service, 'test.png'));
250250
});
251+
it('sets emulator host correctly with ssl', done => {
252+
function newSend(connection: TestingConnection, url: string): void {
253+
// Expect emulator host to be in url of storage operations requests,
254+
// in this case getDownloadURL.
255+
expect(url).to.match(/^https:\/\/test\.host\.org:1234.+/);
256+
connection.abort();
257+
injectTestConnection(null);
258+
done();
259+
}
260+
261+
injectTestConnection(() => newTestConnection(newSend));
262+
const service = new FirebaseStorageImpl(
263+
testShared.fakeApp,
264+
testShared.fakeAuthProvider,
265+
testShared.fakeAppCheckTokenProvider
266+
);
267+
connectStorageEmulator(service, 'test.host.org', 1234, { ssl: true });
268+
expect(service.host).to.equal('test.host.org:1234');
269+
expect(service._protocol).to.equal('https');
270+
void getDownloadURL(ref(service, 'test.png'));
271+
});
251272
it('sets mock user token string if specified', done => {
252273
const mockUserToken = 'my-mock-user-token';
253274
function newSend(

0 commit comments

Comments
 (0)