Skip to content

Throw a more helpful error if there isn't a 'sub' field #1366

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

Merged
merged 2 commits into from
Nov 8, 2018
Merged
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
3 changes: 3 additions & 0 deletions packages/testing/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ function createUnsecuredJwt(auth: object): string {
(auth as any).iat = (auth as any).iat || 0;
// Use `uid` field as a backup when `sub` is missing.
(auth as any).sub = (auth as any).sub || (auth as any).uid;
if (!(auth as any).sub) {
throw new Error("auth must be an object with a 'sub' or 'uid' field");
}
// Unsecured JWTs use the empty string as a signature.
const signature = '';
return [
Expand Down
4 changes: 2 additions & 2 deletions packages/testing/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ describe('Testing Module Tests', function() {

it('apps() returns apps created with initializeTestApp', async function() {
const numApps = firebase.apps().length;
await firebase.initializeTestApp({ databaseName: 'foo', auth: {} });
await firebase.initializeTestApp({ databaseName: 'foo', auth: null });
expect(firebase.apps().length).to.equal(numApps + 1);
await firebase.initializeTestApp({ databaseName: 'bar', auth: {} });
await firebase.initializeTestApp({ databaseName: 'bar', auth: null });
expect(firebase.apps().length).to.equal(numApps + 2);
});

Expand Down