Skip to content

Commit 505b745

Browse files
committed
protection from null server apps in browser targets
1 parent fe42c64 commit 505b745

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

packages/auth/test/integration/flows/firebaseserverapp.test.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ const signInWaitDuration = 200;
4545

4646
describe('Integration test: Auth FirebaseServerApp tests', () => {
4747
let auth: Auth;
48-
let serverAppAuth: Auth;
48+
let serverAppAuth: Auth | null;
4949

5050
beforeEach(() => {
5151
auth = getTestInstance();
5252
});
5353

5454
afterEach(async () => {
55-
await signOut(serverAppAuth);
55+
if (serverAppAuth) {
56+
await signOut(serverAppAuth);
57+
serverAppAuth = null;
58+
}
5659
await cleanUpTestInstance(auth);
5760
});
5861

@@ -120,8 +123,11 @@ describe('Integration test: Auth FirebaseServerApp tests', () => {
120123
if (serverAuthUser) {
121124
numberServerLogins++;
122125
expect(user.uid).to.be.equal(serverAuthUser.uid);
123-
expect(serverAppAuth.currentUser).to.equal(serverAuthUser);
126+
expect(serverAppAuth).to.not.be.null;
124127
expect(serverAuthUser.getIdToken);
128+
if (serverAppAuth) {
129+
expect(serverAppAuth.currentUser).to.equal(serverAuthUser);
130+
}
125131
}
126132
});
127133

@@ -171,7 +177,10 @@ describe('Integration test: Auth FirebaseServerApp tests', () => {
171177
onAuthStateChanged(serverAppAuth, serverAuthUser => {
172178
if (serverAuthUser) {
173179
numberServerLogins++;
174-
expect(serverAppAuth.currentUser).to.equal(serverAuthUser);
180+
expect(serverAppAuth).to.not.be.null;
181+
if (serverAppAuth) {
182+
expect(serverAppAuth.currentUser).to.equal(serverAuthUser);
183+
}
175184
expect(user.uid).to.be.equal(serverAuthUser.uid);
176185
expect(serverAuthUser.refreshToken).to.be.empty;
177186
expect(user.isAnonymous).to.be.equal(serverAuthUser.isAnonymous);
@@ -211,7 +220,10 @@ describe('Integration test: Auth FirebaseServerApp tests', () => {
211220
if (serverAuthUser) {
212221
numberServerLogins++;
213222
expect(user.uid).to.be.equal(serverAuthUser.uid);
214-
expect(serverAppAuth.currentUser).to.equal(serverAuthUser);
223+
expect(serverAppAuth).to.not.be.null;
224+
if (serverAppAuth) {
225+
expect(serverAppAuth.currentUser).to.equal(serverAuthUser);
226+
}
215227
}
216228
});
217229

@@ -248,7 +260,10 @@ describe('Integration test: Auth FirebaseServerApp tests', () => {
248260
onAuthStateChanged(serverAppAuth, serverAuthUser => {
249261
if (serverAuthUser) {
250262
numberServerLogins++;
251-
expect(serverAppAuth.currentUser).to.equal(serverAuthUser);
263+
expect(serverAppAuth).to.not.be.null;
264+
if (serverAppAuth) {
265+
expect(serverAppAuth.currentUser).to.equal(serverAuthUser);
266+
}
252267
expect(user.uid).to.be.equal(serverAuthUser.uid);
253268
expect(user.displayName).to.be.null;
254269
void updateProfile(serverAuthUser, {
@@ -268,8 +283,11 @@ describe('Integration test: Auth FirebaseServerApp tests', () => {
268283
}
269284

270285
expect(numberServerLogins).to.equal(1);
271-
expect(serverAppAuth.currentUser).to.not.be.null;
272-
expect(serverAppAuth.currentUser?.displayName).to.not.be.null;
273-
expect(serverAppAuth.currentUser?.displayName).to.equal(newDisplayName);
286+
expect(serverAppAuth).to.not.be.null;
287+
if (serverAppAuth) {
288+
expect(serverAppAuth.currentUser).to.not.be.null;
289+
expect(serverAppAuth.currentUser?.displayName).to.not.be.null;
290+
expect(serverAppAuth.currentUser?.displayName).to.equal(newDisplayName);
291+
}
274292
});
275293
});

0 commit comments

Comments
 (0)