Skip to content

Commit 015e24d

Browse files
committed
Address PR comments
1 parent 6175d9b commit 015e24d

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ import '../test/setup';
1818
import { expect } from 'chai';
1919
import { stub } from 'sinon';
2020
import { setTokenAutoRefreshEnabled, initializeAppCheck } from './api';
21-
import {
22-
FAKE_SITE_KEY,
23-
getFullApp,
24-
getFakeApp,
25-
getFakeCustomTokenProvider
26-
} from '../test/util';
21+
import { FAKE_SITE_KEY, getFullApp, getFakeApp } from '../test/util';
2722
import { getState } from './state';
2823
import * as reCAPTCHA from './recaptcha';
2924
import { deleteApp, FirebaseApp } from '@firebase/app-exp';
@@ -52,7 +47,7 @@ describe('api', () => {
5247
).to.throw(/appCheck\/already-initialized/);
5348
});
5449

55-
it('initialize reCAPTCHA when a sitekey is provided', () => {
50+
it('initialize reCAPTCHA when a ReCaptchaV3Provider is provided', () => {
5651
const initReCAPTCHAStub = stub(reCAPTCHA, 'initialize').returns(
5752
Promise.resolve({} as any)
5853
);
@@ -65,16 +60,6 @@ describe('api', () => {
6560
);
6661
});
6762

68-
it('does NOT initialize reCAPTCHA when a custom token provider is provided', () => {
69-
const fakeCustomTokenProvider = getFakeCustomTokenProvider();
70-
const initReCAPTCHAStub = stub(reCAPTCHA, 'initialize');
71-
initializeAppCheck(app, {
72-
provider: fakeCustomTokenProvider
73-
});
74-
expect(getState(app).provider).to.equal(fakeCustomTokenProvider);
75-
expect(initReCAPTCHAStub).to.have.not.been.called;
76-
});
77-
7863
it('sets activated to true', () => {
7964
expect(getState(app).activated).to.equal(false);
8065
initializeAppCheck(app, {

packages-exp/app-check-exp/src/api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ export function initializeAppCheck(
6565
* refreshes App Check tokens as needed. If undefined, defaults to the
6666
* value of `app.automaticDataCollectionEnabled`, which defaults to
6767
* false and can be set in the app config.
68-
*
69-
* @internal
7068
*/
7169
function _activate(
7270
app: FirebaseApp,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('internal api', () => {
8787
clock.restore();
8888
});
8989

90-
it('uses reCAPTCHA token to exchange for AppCheck token if no customTokenProvider is provided', async () => {
90+
it('uses reCAPTCHA token to exchange for AppCheck token', async () => {
9191
initializeAppCheck(app, {
9292
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY)
9393
});
@@ -282,7 +282,11 @@ describe('internal api', () => {
282282

283283
stub(reCAPTCHA, 'getToken').returns(Promise.resolve(fakeRecaptchaToken));
284284
stub(client, 'exchangeToken').returns(
285-
Promise.resolve(fakeRecaptchaAppCheckToken)
285+
Promise.resolve({
286+
token: 'new-recaptcha-app-check-token',
287+
expireTimeMillis: 345,
288+
issuedAtTimeMillis: 0
289+
})
286290
);
287291

288292
expect(

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ export async function getToken(
104104
* request a new token
105105
*/
106106
try {
107-
if (state.provider) {
108-
token = await state.provider.getToken();
109-
}
107+
// state.provider is populated in initializeAppCheck()
108+
// ensureActivated() at the top of this function checks that
109+
// initializeAppCheck() has been called.
110+
token = await state.provider!.getToken();
110111
} catch (e) {
111112
// `getToken()` should never throw, but logging error text to console will aid debugging.
112113
logger.error(e);

0 commit comments

Comments
 (0)