Skip to content

Preserve user input in initializeTestApp #3923

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 1 commit into from
Oct 12, 2020
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
5 changes: 5 additions & 0 deletions .changeset/ninety-kings-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/rules-unit-testing': patch
---

Do not delete uid property from user auth object in initializeTestApp()
8 changes: 5 additions & 3 deletions packages/rules-unit-testing/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ function createUnsecuredJwt(token: TokenOptions, projectId?: string): string {
throw new Error("Auth must contain 'sub', 'uid', or 'user_id' field!");
}

// Remove the uid option since it's not actually part of the token spec
delete token.uid;

const payload: FirebaseIdToken = {
// Set all required fields to decent defaults
iss: `https://securetoken.google.com/${project}`,
Expand All @@ -148,6 +145,11 @@ function createUnsecuredJwt(token: TokenOptions, projectId?: string): string {
...token
};

// Remove the uid option since it's not actually part of the token spec.
if (payload.uid) {
delete payload.uid;
}

// Unsecured JWTs use the empty string as a signature.
const signature = '';
return [
Expand Down
16 changes: 15 additions & 1 deletion packages/rules-unit-testing/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,21 @@ describe('Testing Module Tests', function () {
wrongClaim.firestore().doc('test/test').set({ hello: 'test' })
);
});


it('initializeTestApp() does not destroy user input', function () {
const options = {
projectId: 'fakeproject',
auth: {
uid: 'sam',
email: '[email protected]'
}
};
const optionsCopy = Object.assign({}, options);

firebase.initializeTestApp(options);
expect(options).to.deep.equal(optionsCopy);
});

it('loadDatabaseRules() throws if no databaseName or rules', async function () {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await expect((firebase as any).loadDatabaseRules.bind(null, {})).to.throw(
Expand Down