Skip to content

Commit

Permalink
Address review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchenshi committed Aug 13, 2021
1 parent 0279432 commit b86fa54
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 76 deletions.
16 changes: 8 additions & 8 deletions .changeset/wise-toys-care.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
"@firebase/database-types": feature
"@firebase/database": feature
"firebase": feature
"@firebase/firestore-types": feature
"@firebase/firestore": feature
"@firebase/storage-types": feature
"@firebase/storage": feature
"@firebase/util": feature
'@firebase/database-types': minor
'@firebase/database': minor
'firebase': minor
'@firebase/firestore-types': minor
'@firebase/firestore': minor
'@firebase/storage-types': minor
'@firebase/storage': minor
'@firebase/util': minor
---

Implement mockUserToken for Storage and fix JWT format bugs.
6 changes: 2 additions & 4 deletions packages/database-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
"index.d.ts"
],
"dependencies": {
"@firebase/app-types": "0.6.3"
},
"peerDependencies": {
"@firebase/util": "1.x"
"@firebase/app-types": "0.6.3",
"@firebase/util": "1.2.0"
},
"repository": {
"directory": "packages/database-types",
Expand Down
66 changes: 3 additions & 63 deletions packages/storage/test/unit/service.compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('Firebase Storage > Service', () => {
}, 'storage/invalid-default-bucket');
});
});
describe('connectStorageEmulator(service, host, port, options)', () => {
describe('connectStorageEmulator(service, host, port)', () => {
it('sets emulator host correctly', done => {
function newSend(
connection: TestingConnection,
Expand All @@ -209,69 +209,9 @@ describe('Firebase Storage > Service', () => {
testShared.makePool(newSend)
);
service.useEmulator('test.host.org', 1234);
const impl = service._delegate as FirebaseStorageImpl;
expect(impl.host).to.equal('http://test.host.org:1234');
expect(impl._overrideAuthToken).to.be.undefined;
void service.ref('test.png').getDownloadURL();
});
it('sets mock user token string if specified', done => {
const mockUserToken = 'my-mock-user-token';
function newSend(
connection: TestingConnection,
url: string,
method: string,
body?: ArrayBufferView | Blob | string | null,
headers?: Headers
): void {
// Expect emulator host to be in url of storage operations requests,
// in this case getDownloadURL.
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
expect(headers?.['Authorization']).to.eql(`Firebase ${mockUserToken}`);
connection.abort();
done();
}
const service = makeService(
testShared.fakeApp,
testShared.fakeAuthProvider,
testShared.fakeAppCheckTokenProvider,
testShared.makePool(newSend)
);
service.useEmulator('test.host.org', 1234, { mockUserToken });
const impl = service._delegate as FirebaseStorageImpl;
expect(impl.host).to.equal('http://test.host.org:1234');
expect(impl._overrideAuthToken).to.equal(mockUserToken);
void service.ref('test.png').getDownloadURL();
});
it('creates mock user token from object if specified', done => {
let token: string | undefined = undefined;
function newSend(
connection: TestingConnection,
url: string,
method: string,
body?: ArrayBufferView | Blob | string | null,
headers?: Headers
): void {
// Expect emulator host to be in url of storage operations requests,
// in this case getDownloadURL.
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
expect(headers?.['Authorization']).to.eql(`Firebase ${token}`);
connection.abort();
done();
}
const service = makeService(
testShared.fakeApp,
testShared.fakeAuthProvider,
testShared.fakeAppCheckTokenProvider,
testShared.makePool(newSend)
expect((service._delegate as FirebaseStorageImpl).host).to.equal(
'http://test.host.org:1234'
);
service.useEmulator('test.host.org', 1234, {
mockUserToken: { sub: 'alice' }
});
const impl = service._delegate as FirebaseStorageImpl;
expect(impl.host).to.equal('http://test.host.org:1234');
token = impl._overrideAuthToken;
// Token should be an unsigned JWT with header { "alg": "none", "type": "JWT" } (base64url):
expect(token).to.match(/^eyJhbGciOiJub25lIiwidHlwZSI6IkpXVCJ9\./);
void service.ref('test.png').getDownloadURL();
});
});
Expand Down
61 changes: 60 additions & 1 deletion packages/storage/test/unit/service.exp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ GOOG4-RSA-SHA256`
);
});
});
describe('connectStorageEmulator(service, host, port)', () => {
describe('connectStorageEmulator(service, host, port, options)', () => {
it('sets emulator host correctly', done => {
function newSend(
connection: TestingConnection,
Expand All @@ -260,6 +260,65 @@ GOOG4-RSA-SHA256`
expect(service.host).to.equal('http://test.host.org:1234');
void getDownloadURL(ref(service, 'test.png'));
});
it('sets mock user token string if specified', done => {
const mockUserToken = 'my-mock-user-token';
function newSend(
connection: TestingConnection,
url: string,
method: string,
body?: ArrayBufferView | Blob | string | null,
headers?: Headers
): void {
// Expect emulator host to be in url of storage operations requests,
// in this case getDownloadURL.
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
expect(headers?.['Authorization']).to.eql(`Firebase ${mockUserToken}`);
connection.abort();
done();
}
const service = new FirebaseStorageImpl(
testShared.fakeApp,
testShared.fakeAuthProvider,
testShared.fakeAppCheckTokenProvider,
testShared.makePool(newSend)
);
connectStorageEmulator(service, 'test.host.org', 1234, { mockUserToken });
expect(service.host).to.equal('http://test.host.org:1234');
expect(service._overrideAuthToken).to.equal(mockUserToken);
void getDownloadURL(ref(service, 'test.png'));
});
it('creates mock user token from object if specified', done => {
let token: string | undefined = undefined;
function newSend(
connection: TestingConnection,
url: string,
method: string,
body?: ArrayBufferView | Blob | string | null,
headers?: Headers
): void {
// Expect emulator host to be in url of storage operations requests,
// in this case getDownloadURL.
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
expect(headers?.['Authorization']).to.eql(`Firebase ${token}`);
connection.abort();
done();
}

const service = new FirebaseStorageImpl(
testShared.fakeApp,
testShared.fakeAuthProvider,
testShared.fakeAppCheckTokenProvider,
testShared.makePool(newSend)
);
connectStorageEmulator(service, 'test.host.org', 1234, {
mockUserToken: { sub: 'alice' }
});
expect(service.host).to.equal('http://test.host.org:1234');
token = service._overrideAuthToken;
// Token should be an unsigned JWT with header { "alg": "none", "type": "JWT" } (base64url):
expect(token).to.match(/^eyJhbGciOiJub25lIiwidHlwZSI6IkpXVCJ9\./);
void getDownloadURL(ref(service, 'test.png'));
});
});
describe('ref(service, path)', () => {
const service = new FirebaseStorageImpl(
Expand Down

0 comments on commit b86fa54

Please sign in to comment.