Skip to content

Commit 4610ce3

Browse files
committed
Never write to real storage
1 parent 1a82f15 commit 4610ce3

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

packages/app-check/src/internal-api.test.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ const fakePlatformLoggingProvider = getFakePlatformLoggingProvider();
4545

4646
describe('internal api', () => {
4747
let app: FirebaseApp;
48-
let storageStub: SinonStub;
48+
let storageReadStub: SinonStub;
49+
let storageWriteStub: SinonStub;
4950

5051
beforeEach(() => {
5152
app = getFakeApp();
52-
storageStub = stub(storage, 'readTokenFromStorage').resolves(undefined);
53+
storageReadStub = stub(storage, 'readTokenFromStorage').resolves(undefined);
54+
storageWriteStub = stub(storage, 'writeTokenToStorage');
5355
});
5456

5557
afterEach(async () => {
56-
storageStub.restore();
58+
storageReadStub.restore();
59+
storageWriteStub.restore();
5760
clearState();
5861
removegreCAPTCHAScriptsOnPage();
5962
});
@@ -135,7 +138,7 @@ describe('internal api', () => {
135138

136139
it('notifies listeners using cached token', async () => {
137140
activate(app, FAKE_SITE_KEY, false);
138-
storageStub.resolves(fakeCachedAppCheckToken);
141+
storageReadStub.resolves(fakeCachedAppCheckToken);
139142

140143
const listener1 = spy();
141144
const listener2 = spy();
@@ -195,7 +198,7 @@ describe('internal api', () => {
195198
it('loads persisted token to memory and returns it', async () => {
196199
activate(app, FAKE_SITE_KEY);
197200

198-
storageStub.resolves(fakeCachedAppCheckToken);
201+
storageReadStub.resolves(fakeCachedAppCheckToken);
199202

200203
const clientStub = stub(client, 'exchangeToken');
201204

@@ -213,7 +216,7 @@ describe('internal api', () => {
213216

214217
stub(reCAPTCHA, 'getToken').resolves(fakeRecaptchaToken);
215218
stub(client, 'exchangeToken').resolves(fakeRecaptchaAppCheckToken);
216-
const storageWriteStub = stub(storage, 'writeTokenToStorage');
219+
storageWriteStub.resetHistory();
217220
const result = await getToken(app, fakePlatformLoggingProvider);
218221
expect(result).to.deep.equal({ token: fakeRecaptchaAppCheckToken.token });
219222
expect(storageWriteStub).has.been.calledWith(
@@ -267,7 +270,7 @@ describe('internal api', () => {
267270
});
268271

269272
it('reads any memory-cached debug token if in debug mode', async () => {
270-
storageStub.resetHistory();
273+
storageReadStub.resetHistory();
271274
const clientStub = stub(client, 'exchangeToken');
272275
const debugState = getDebugState();
273276
debugState.enabled = true;
@@ -280,12 +283,12 @@ describe('internal api', () => {
280283
expect(token).to.deep.equal({
281284
token: fakeCachedAppCheckToken.token
282285
});
283-
expect(storageStub).has.not.been.called;
286+
expect(storageReadStub).has.not.been.called;
284287
expect(clientStub).has.not.been.called;
285288
});
286289

287290
it('reads any indexedDB cached debug token if in debug mode and no token in memory', async () => {
288-
storageStub.resolves(fakeCachedAppCheckToken);
291+
storageReadStub.resolves(fakeCachedAppCheckToken);
289292
const clientStub = stub(client, 'exchangeToken');
290293
const debugState = getDebugState();
291294
debugState.enabled = true;
@@ -305,7 +308,7 @@ describe('internal api', () => {
305308
activate(app, FAKE_SITE_KEY);
306309

307310
stub(client, 'exchangeToken').resolves(fakeRecaptchaAppCheckToken);
308-
const storageWriteStub = stub(storage, 'writeTokenToStorage');
311+
storageWriteStub.resetHistory();
309312
const debugState = getDebugState();
310313
debugState.enabled = true;
311314
debugState.token = new Deferred();
@@ -373,7 +376,7 @@ describe('internal api', () => {
373376
it('notifies the listener with the valid token in storage', done => {
374377
const clock = useFakeTimers();
375378
activate(app, FAKE_SITE_KEY);
376-
storageStub.resolves({
379+
storageReadStub.resolves({
377380
token: `fake-cached-app-check-token`,
378381
expireTimeMillis: 123,
379382
issuedAtTimeMillis: 0

0 commit comments

Comments
 (0)