Skip to content

Commit cb28261

Browse files
authored
Preserve user input in initializeTestApp (#3923)
1 parent 79f4a5a commit cb28261

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

.changeset/ninety-kings-agree.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/rules-unit-testing': patch
3+
---
4+
5+
Do not delete uid property from user auth object in initializeTestApp()

packages/rules-unit-testing/src/api/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ function createUnsecuredJwt(token: TokenOptions, projectId?: string): string {
127127
throw new Error("Auth must contain 'sub', 'uid', or 'user_id' field!");
128128
}
129129

130-
// Remove the uid option since it's not actually part of the token spec
131-
delete token.uid;
132-
133130
const payload: FirebaseIdToken = {
134131
// Set all required fields to decent defaults
135132
iss: `https://securetoken.google.com/${project}`,
@@ -148,6 +145,11 @@ function createUnsecuredJwt(token: TokenOptions, projectId?: string): string {
148145
...token
149146
};
150147

148+
// Remove the uid option since it's not actually part of the token spec.
149+
if (payload.uid) {
150+
delete payload.uid;
151+
}
152+
151153
// Unsecured JWTs use the empty string as a signature.
152154
const signature = '';
153155
return [

packages/rules-unit-testing/test/database.test.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,21 @@ describe('Testing Module Tests', function () {
245245
wrongClaim.firestore().doc('test/test').set({ hello: 'test' })
246246
);
247247
});
248-
248+
249+
it('initializeTestApp() does not destroy user input', function () {
250+
const options = {
251+
projectId: 'fakeproject',
252+
auth: {
253+
uid: 'sam',
254+
255+
}
256+
};
257+
const optionsCopy = Object.assign({}, options);
258+
259+
firebase.initializeTestApp(options);
260+
expect(options).to.deep.equal(optionsCopy);
261+
});
262+
249263
it('loadDatabaseRules() throws if no databaseName or rules', async function () {
250264
// eslint-disable-next-line @typescript-eslint/no-explicit-any
251265
await expect((firebase as any).loadDatabaseRules.bind(null, {})).to.throw(

0 commit comments

Comments
 (0)