Skip to content

Commit 137a0d9

Browse files
authored
fix(auth): Add missing Math.floor() when setting validDuration in createSessionCookie() (#2712)
* fix(auth): Add missing `Math.floor()` when setting `validDuration` in `createSessionCookie()` * fix unit tests
1 parent 56d967f commit 137a0d9

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/auth/auth-api-request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ export abstract class AbstractAuthRequestHandler {
10941094
const request = {
10951095
idToken,
10961096
// Convert to seconds.
1097-
validDuration: expiresIn / 1000,
1097+
validDuration: Math.floor(expiresIn / 1000),
10981098
};
10991099
return this.invokeRequestHandler(this.getAuthUrlBuilder(), FIREBASE_AUTH_CREATE_SESSION_COOKIE, request)
11001100
.then((response: any) => response.sessionCookie);

test/integration/auth.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,7 @@ describe('admin.auth', () => {
25632563
describe('createSessionCookie()', () => {
25642564
let expectedExp: number;
25652565
let expectedIat: number;
2566-
const expiresIn = 24 * 60 * 60 * 1000;
2566+
const expiresIn = (24 * 60 * 60 * 1000) + 234;
25672567
let payloadClaims: any;
25682568
let currentIdToken: string;
25692569
const uid = sessionCookieUids[0];

test/unit/auth/auth-api-request.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,8 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
10551055
const expectedError = new FirebaseAuthError(
10561056
AuthClientErrorCode.INVALID_SESSION_COOKIE_DURATION,
10571057
);
1058-
const outOfBoundDuration = 60 * 60 * 1000 * 24 * 14 + 1;
1058+
// Add more than a second since this value is Math.floor()'ed
1059+
const outOfBoundDuration = 60 * 60 * 1000 * 24 * 14 + 1001;
10591060

10601061
const requestHandler = handler.init(mockApp);
10611062
return requestHandler.createSessionCookie('ID_TOKEN', outOfBoundDuration)

0 commit comments

Comments
 (0)