Skip to content

Commit b86fa54

Browse files
committed
Address review feedback.
1 parent 0279432 commit b86fa54

File tree

4 files changed

+73
-76
lines changed

4 files changed

+73
-76
lines changed

.changeset/wise-toys-care.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
"@firebase/database-types": feature
3-
"@firebase/database": feature
4-
"firebase": feature
5-
"@firebase/firestore-types": feature
6-
"@firebase/firestore": feature
7-
"@firebase/storage-types": feature
8-
"@firebase/storage": feature
9-
"@firebase/util": feature
2+
'@firebase/database-types': minor
3+
'@firebase/database': minor
4+
'firebase': minor
5+
'@firebase/firestore-types': minor
6+
'@firebase/firestore': minor
7+
'@firebase/storage-types': minor
8+
'@firebase/storage': minor
9+
'@firebase/util': minor
1010
---
1111

1212
Implement mockUserToken for Storage and fix JWT format bugs.

packages/database-types/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
"index.d.ts"
1313
],
1414
"dependencies": {
15-
"@firebase/app-types": "0.6.3"
16-
},
17-
"peerDependencies": {
18-
"@firebase/util": "1.x"
15+
"@firebase/app-types": "0.6.3",
16+
"@firebase/util": "1.2.0"
1917
},
2018
"repository": {
2119
"directory": "packages/database-types",

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

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe('Firebase Storage > Service', () => {
187187
}, 'storage/invalid-default-bucket');
188188
});
189189
});
190-
describe('connectStorageEmulator(service, host, port, options)', () => {
190+
describe('connectStorageEmulator(service, host, port)', () => {
191191
it('sets emulator host correctly', done => {
192192
function newSend(
193193
connection: TestingConnection,
@@ -209,69 +209,9 @@ describe('Firebase Storage > Service', () => {
209209
testShared.makePool(newSend)
210210
);
211211
service.useEmulator('test.host.org', 1234);
212-
const impl = service._delegate as FirebaseStorageImpl;
213-
expect(impl.host).to.equal('http://test.host.org:1234');
214-
expect(impl._overrideAuthToken).to.be.undefined;
215-
void service.ref('test.png').getDownloadURL();
216-
});
217-
it('sets mock user token string if specified', done => {
218-
const mockUserToken = 'my-mock-user-token';
219-
function newSend(
220-
connection: TestingConnection,
221-
url: string,
222-
method: string,
223-
body?: ArrayBufferView | Blob | string | null,
224-
headers?: Headers
225-
): void {
226-
// Expect emulator host to be in url of storage operations requests,
227-
// in this case getDownloadURL.
228-
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
229-
expect(headers?.['Authorization']).to.eql(`Firebase ${mockUserToken}`);
230-
connection.abort();
231-
done();
232-
}
233-
const service = makeService(
234-
testShared.fakeApp,
235-
testShared.fakeAuthProvider,
236-
testShared.fakeAppCheckTokenProvider,
237-
testShared.makePool(newSend)
238-
);
239-
service.useEmulator('test.host.org', 1234, { mockUserToken });
240-
const impl = service._delegate as FirebaseStorageImpl;
241-
expect(impl.host).to.equal('http://test.host.org:1234');
242-
expect(impl._overrideAuthToken).to.equal(mockUserToken);
243-
void service.ref('test.png').getDownloadURL();
244-
});
245-
it('creates mock user token from object if specified', done => {
246-
let token: string | undefined = undefined;
247-
function newSend(
248-
connection: TestingConnection,
249-
url: string,
250-
method: string,
251-
body?: ArrayBufferView | Blob | string | null,
252-
headers?: Headers
253-
): void {
254-
// Expect emulator host to be in url of storage operations requests,
255-
// in this case getDownloadURL.
256-
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
257-
expect(headers?.['Authorization']).to.eql(`Firebase ${token}`);
258-
connection.abort();
259-
done();
260-
}
261-
const service = makeService(
262-
testShared.fakeApp,
263-
testShared.fakeAuthProvider,
264-
testShared.fakeAppCheckTokenProvider,
265-
testShared.makePool(newSend)
212+
expect((service._delegate as FirebaseStorageImpl).host).to.equal(
213+
'http://test.host.org:1234'
266214
);
267-
service.useEmulator('test.host.org', 1234, {
268-
mockUserToken: { sub: 'alice' }
269-
});
270-
const impl = service._delegate as FirebaseStorageImpl;
271-
expect(impl.host).to.equal('http://test.host.org:1234');
272-
token = impl._overrideAuthToken;
273-
// Token should be an unsigned JWT with header { "alg": "none", "type": "JWT" } (base64url):
274-
expect(token).to.match(/^eyJhbGciOiJub25lIiwidHlwZSI6IkpXVCJ9\./);
275215
void service.ref('test.png').getDownloadURL();
276216
});
277217
});

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

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ GOOG4-RSA-SHA256`
235235
);
236236
});
237237
});
238-
describe('connectStorageEmulator(service, host, port)', () => {
238+
describe('connectStorageEmulator(service, host, port, options)', () => {
239239
it('sets emulator host correctly', done => {
240240
function newSend(
241241
connection: TestingConnection,
@@ -260,6 +260,65 @@ GOOG4-RSA-SHA256`
260260
expect(service.host).to.equal('http://test.host.org:1234');
261261
void getDownloadURL(ref(service, 'test.png'));
262262
});
263+
it('sets mock user token string if specified', done => {
264+
const mockUserToken = 'my-mock-user-token';
265+
function newSend(
266+
connection: TestingConnection,
267+
url: string,
268+
method: string,
269+
body?: ArrayBufferView | Blob | string | null,
270+
headers?: Headers
271+
): void {
272+
// Expect emulator host to be in url of storage operations requests,
273+
// in this case getDownloadURL.
274+
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
275+
expect(headers?.['Authorization']).to.eql(`Firebase ${mockUserToken}`);
276+
connection.abort();
277+
done();
278+
}
279+
const service = new FirebaseStorageImpl(
280+
testShared.fakeApp,
281+
testShared.fakeAuthProvider,
282+
testShared.fakeAppCheckTokenProvider,
283+
testShared.makePool(newSend)
284+
);
285+
connectStorageEmulator(service, 'test.host.org', 1234, { mockUserToken });
286+
expect(service.host).to.equal('http://test.host.org:1234');
287+
expect(service._overrideAuthToken).to.equal(mockUserToken);
288+
void getDownloadURL(ref(service, 'test.png'));
289+
});
290+
it('creates mock user token from object if specified', done => {
291+
let token: string | undefined = undefined;
292+
function newSend(
293+
connection: TestingConnection,
294+
url: string,
295+
method: string,
296+
body?: ArrayBufferView | Blob | string | null,
297+
headers?: Headers
298+
): void {
299+
// Expect emulator host to be in url of storage operations requests,
300+
// in this case getDownloadURL.
301+
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
302+
expect(headers?.['Authorization']).to.eql(`Firebase ${token}`);
303+
connection.abort();
304+
done();
305+
}
306+
307+
const service = new FirebaseStorageImpl(
308+
testShared.fakeApp,
309+
testShared.fakeAuthProvider,
310+
testShared.fakeAppCheckTokenProvider,
311+
testShared.makePool(newSend)
312+
);
313+
connectStorageEmulator(service, 'test.host.org', 1234, {
314+
mockUserToken: { sub: 'alice' }
315+
});
316+
expect(service.host).to.equal('http://test.host.org:1234');
317+
token = service._overrideAuthToken;
318+
// Token should be an unsigned JWT with header { "alg": "none", "type": "JWT" } (base64url):
319+
expect(token).to.match(/^eyJhbGciOiJub25lIiwidHlwZSI6IkpXVCJ9\./);
320+
void getDownloadURL(ref(service, 'test.png'));
321+
});
263322
});
264323
describe('ref(service, path)', () => {
265324
const service = new FirebaseStorageImpl(

0 commit comments

Comments
 (0)