Skip to content

Rework apps, update admin, remove lodash #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@
"@types/express": "4.17.3",
"cors": "^2.8.5",
"express": "^4.17.1",
"lodash": "^4.17.14",
"node-fetch": "^2.6.7"
},
"devDependencies": {
Expand All @@ -194,7 +193,6 @@
"@types/chai": "^4.1.7",
"@types/chai-as-promised": "^7.1.0",
"@types/jsonwebtoken": "^8.3.2",
"@types/lodash": "^4.14.135",
"@types/mocha": "^5.2.7",
"@types/mock-require": "^2.0.0",
"@types/nock": "^10.0.3",
Expand Down Expand Up @@ -234,4 +232,4 @@
"engines": {
"node": ">=14.10.0"
}
}
}
26 changes: 13 additions & 13 deletions spec/common/providers/https.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from 'chai';
import * as firebase from 'firebase-admin';
import { App, deleteApp, initializeApp } from 'firebase-admin/app';
import * as sinon from 'sinon';

import { apps as appsNamespace } from '../../../src/apps';
import { getApp, setApp } from '../../../src/common/app';
import * as debug from '../../../src/common/debug';
import * as https from '../../../src/common/providers/https';
import * as mocks from '../../fixtures/credential/key.json';
Expand Down Expand Up @@ -76,7 +76,7 @@ async function runCallableTest(test: CallTest): Promise<any> {
}

describe('onCallHandler', () => {
let app: firebase.app.App;
let app: App;

before(() => {
const credential = {
Expand All @@ -92,16 +92,16 @@ describe('onCallHandler', () => {
};
},
};
app = firebase.initializeApp({
app = initializeApp({
projectId: 'aProjectId',
credential,
});
Object.defineProperty(appsNamespace(), 'admin', { get: () => app });
setApp(app);
});

after(() => {
app.delete();
delete appsNamespace.singleton;
deleteApp(app);
setApp(undefined);
});

it('should handle success', () => {
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('onCallHandler', () => {

it('should handle auth', async () => {
const mock = mockFetchPublicKeys();
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateIdToken(projectId);
await runCallableTest({
httpRequest: mockRequest(null, 'application/json', {
Expand All @@ -313,7 +313,7 @@ describe('onCallHandler', () => {
});

it('should reject bad auth', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateUnsignedIdToken(projectId);
await runCallableTest({
httpRequest: mockRequest(null, 'application/json', {
Expand Down Expand Up @@ -341,7 +341,7 @@ describe('onCallHandler', () => {

it('should handle AppCheck token', async () => {
const mock = mockFetchAppCheckPublicJwks();
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const appId = '123:web:abc';
const appCheckToken = generateAppCheckToken(projectId, appId);
await runCallableTest({
Expand All @@ -365,7 +365,7 @@ describe('onCallHandler', () => {
});

it('should reject bad AppCheck token', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const appId = '123:web:abc';
const appCheckToken = generateUnsignedAppCheckToken(projectId, appId);
await runCallableTest({
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('onCallHandler', () => {
});

it('should skip auth token verification', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateUnsignedIdToken(projectId);
await runCallableTest({
httpRequest: mockRequest(null, 'application/json', {
Expand All @@ -498,7 +498,7 @@ describe('onCallHandler', () => {
});

it('should skip app check token verification', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const appId = '123:web:abc';
const appCheckToken = generateUnsignedAppCheckToken(projectId, appId);
await runCallableTest({
Expand Down
18 changes: 9 additions & 9 deletions spec/common/providers/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
// SOFTWARE.

import { expect } from 'chai';
import * as firebase from 'firebase-admin';
import { App, deleteApp, initializeApp } from 'firebase-admin/app';

import { apps as appsNamespace } from '../../../src/apps';
import { getApp, setApp } from '../../../src/common/app';
import * as https from '../../../src/common/providers/https';
import {
onDispatchHandler,
Expand Down Expand Up @@ -78,7 +78,7 @@ export async function runTaskTest(test: TaskTest): Promise<any> {
}

describe('onEnqueueHandler', () => {
let app: firebase.app.App;
let app: App;

function mockEnqueueRequest(
data: unknown,
Expand All @@ -102,16 +102,16 @@ describe('onEnqueueHandler', () => {
};
},
};
app = firebase.initializeApp({
app = initializeApp({
projectId: 'aProjectId',
credential,
});
Object.defineProperty(appsNamespace(), 'admin', { get: () => app });
setApp(app);
});

after(() => {
app.delete();
delete appsNamespace.singleton;
deleteApp(app);
setApp(undefined);
});

it('should handle success', () => {
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('onEnqueueHandler', () => {
});

it('should handle auth', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateIdToken(projectId);
await runTaskTest({
httpRequest: mockEnqueueRequest(null, 'application/json', {
Expand All @@ -221,7 +221,7 @@ describe('onEnqueueHandler', () => {
});

it('should accept unsigned auth too', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateUnsignedIdToken(projectId);
await runTaskTest({
httpRequest: mockEnqueueRequest(null, 'application/json', {
Expand Down
3 changes: 1 addition & 2 deletions spec/fixtures/mockrequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as jwt from 'jsonwebtoken';
import * as jwkToPem from 'jwk-to-pem';
import * as _ from 'lodash';
import * as nock from 'nock';
import * as mockJWK from '../fixtures/credential/jwk.json';
import * as mockKey from '../fixtures/credential/key.json';
Expand Down Expand Up @@ -32,7 +31,7 @@ export function mockRequest(
} = {}
) {
const body: any = {};
if (!_.isUndefined(data)) {
if (typeof data !== 'undefined') {
body.data = data;
}

Expand Down
143 changes: 0 additions & 143 deletions spec/v1/apps.spec.ts

This file was deleted.

15 changes: 9 additions & 6 deletions spec/v1/cloud-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// SOFTWARE.

import { expect } from 'chai';
import * as _ from 'lodash';

import {
Change,
Expand Down Expand Up @@ -176,9 +175,10 @@ describe('makeCloudFunction', () => {
});

it('should construct the right context for event', () => {
const args: any = _.assign({}, cloudFunctionArgs, {
const args: any = {
...cloudFunctionArgs,
handler: (data: any, context: EventContext) => context,
});
};
const cf = makeCloudFunction(args);
const test: Event = {
context: {
Expand Down Expand Up @@ -206,10 +206,11 @@ describe('makeCloudFunction', () => {
});

it('should throw error when context.params accessed in handler environment', () => {
const args: any = _.assign({}, cloudFunctionArgs, {
const args: any = {
...cloudFunctionArgs,
handler: (data: any, context: EventContext) => context,
triggerResource: () => null,
});
};
const cf = makeCloudFunction(args);
const test: Event = {
context: {
Expand Down Expand Up @@ -429,7 +430,9 @@ describe('Change', () => {

it('should apply the customizer function to `before` and `after`', () => {
function customizer<T>(input: any) {
_.set(input, 'another', 'value');
if (input) {
input.another = 'value';
}
return input as T;
}
const created = Change.fromJSON<object>(
Expand Down
Loading