diff --git a/packages/rules-unit-testing/src/api/index.ts b/packages/rules-unit-testing/src/api/index.ts index 4a47f1491fd..51d16209187 100644 --- a/packages/rules-unit-testing/src/api/index.ts +++ b/packages/rules-unit-testing/src/api/index.ts @@ -27,6 +27,7 @@ import * as request from 'request'; import { base64 } from '@firebase/util'; import { setLogLevel, LogLevel } from '@firebase/logger'; import { Component, ComponentType } from '@firebase/component'; +import { base64Encode } from '@firebase/util'; const { firestore, database, storage } = firebase; export { firestore, database, storage }; @@ -157,6 +158,11 @@ export type FirebaseEmulatorOptions = { }; }; +function trimmedBase64Encode(val: string): string { + // Use base64url encoding and remove padding in the end (dot characters). + return base64Encode(val).replace(/\./g, ""); +} + function createUnsecuredJwt(token: TokenOptions, projectId?: string): string { // Unsecured JWTs use "none" as the algorithm. const header = { @@ -198,12 +204,11 @@ function createUnsecuredJwt(token: TokenOptions, projectId?: string): string { // Unsecured JWTs use the empty string as a signature. const signature = ''; return [ - base64.encodeString(JSON.stringify(header), /*webSafe=*/ false), - base64.encodeString(JSON.stringify(payload), /*webSafe=*/ false), + trimmedBase64Encode(JSON.stringify(header)), + trimmedBase64Encode(JSON.stringify(payload)), signature ].join('.'); } - export function apps(): firebase.app.App[] { return firebase.apps; }