Skip to content

Commit

Permalink
Merge branch 'master' into jh-4gb-emu
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan authored Jan 14, 2021
2 parents 59505f6 + 933ef1b commit 23005ff
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Catches errors while updating authorized domains when deleting channels, printing a warning instead of failing.
- Fixes issue where `host` header was being incorrectly set when proxying to Cloud Run or Cloud Functions for Firebase from the Hosting emulator. (#3012)
- Adds support for setting availableMemoryMb to 4GB in the Cloud Functions for Firebase emulator. (#3026)
- Adds support for setting availableMemoryMb to 4GB in the Cloud Functions for Firebase emulator. (#3026)
- Fixes issue where emulated HTTP functions would crash when the URL contained query parameters (#3032)
- Fixes issue with routing to emulated HTTP functions in regions outside of `us-central1` (#3031)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"description": "",
"main": "functions/index.js",
"dependencies": {
"async": "^3.0.1",
"firebase-admin": "^8.6.0",
"firebase-admin": "^9.4.2",
"firebase-functions": "^3.3.0"
},
"author": "",
"license": "ISC"
"license": "MIT"
}
4 changes: 2 additions & 2 deletions src/emulator/functionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,8 @@ export class FunctionsEmulator implements EmulatorInstance {
// req.url = /:projectId/:region/:trigger_name/*
const url = new URL(`${req.protocol}://${req.hostname}${req.url}`);
const path = `${url.pathname}${url.search}`.replace(
`/${this.args.projectId}/us-central1/${triggerId}`,
""
new RegExp(`\/${this.args.projectId}\/[^\/]*\/${triggerId}\/?`),
"/"
);

// We do this instead of just 302'ing because many HTTP clients don't respect 302s so it may
Expand Down
54 changes: 54 additions & 0 deletions src/test/emulators/functionsEmulator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,34 @@ describe("FunctionsEmulator-Hub", () => {
});
}).timeout(TIMEOUT_LONG);

it("should return the correct url, baseUrl, originalUrl with query params", async () => {
useFunctions(() => {
require("firebase-admin").initializeApp();
return {
function_id: require("firebase-functions").https.onRequest(
(req: express.Request, res: express.Response) => {
res.json({
url: req.url,
baseUrl: req.baseUrl,
originalUrl: req.originalUrl,
query: req.query,
});
}
),
};
});

await supertest(functionsEmulator.createHubServer())
.get("/fake-project-id/us-central1/function_id?a=1&b=2")
.expect(200)
.then((res) => {
expect(res.body.url).to.eq("/?a=1&b=2");
expect(res.body.baseUrl).to.eq("");
expect(res.body.originalUrl).to.eq("/?a=1&b=2");
expect(res.body.query).to.deep.eq({ a: "1", b: "2" });
});
}).timeout(TIMEOUT_LONG);

it("should return the correct url, baseUrl, originalUrl for a subroute", async () => {
useFunctions(() => {
require("firebase-admin").initializeApp();
Expand All @@ -253,6 +281,32 @@ describe("FunctionsEmulator-Hub", () => {
});
}).timeout(TIMEOUT_LONG);

it("should return the correct url, baseUrl, originalUrl for any region", async () => {
useFunctions(() => {
require("firebase-admin").initializeApp();
return {
function_id: require("firebase-functions")
.region("europe-west3")
.https.onRequest((req: express.Request, res: express.Response) => {
res.json({
url: req.url,
baseUrl: req.baseUrl,
originalUrl: req.originalUrl,
});
}),
};
});

await supertest(functionsEmulator.createHubServer())
.get("/fake-project-id/europe-west3/function_id")
.expect(200)
.then((res) => {
expect(res.body.url).to.eq("/");
expect(res.body.baseUrl).to.eq("");
expect(res.body.originalUrl).to.eq("/");
});
}).timeout(TIMEOUT_LONG);

it("should route request body", async () => {
useFunctions(() => {
require("firebase-admin").initializeApp();
Expand Down
18 changes: 15 additions & 3 deletions src/test/extensions/updateHelper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { expect } from "chai";
import * as nock from "nock";
import * as sinon from "sinon";

import { FirebaseError } from "../../error";
import * as updateHelper from "../../extensions/updateHelper";
import * as prompt from "../../prompt";
import { firebaseExtensionsRegistryOrigin } from "../../api";
import * as extensionsApi from "../../extensions/extensionsApi";
import * as extensionsHelper from "../../extensions/extensionsHelper";
import * as prompt from "../../prompt";
import * as resolveSource from "../../extensions/resolveSource";
import * as extensionsApi from "../../extensions/extensionsApi";
import * as updateHelper from "../../extensions/updateHelper";

const SPEC = {
name: "test",
Expand Down Expand Up @@ -143,12 +145,17 @@ describe("updateHelper", () => {
promptStub = sinon.stub(prompt, "promptOnce");
createSourceStub = sinon.stub(extensionsHelper, "createSourceFromLocation");
getInstanceStub = sinon.stub(extensionsApi, "getInstance").resolves(INSTANCE);

// The logic will fetch the extensions registry, but it doesn't need to receive anything.
nock(firebaseExtensionsRegistryOrigin).get("/extensions.json").reply(200, {});
});

afterEach(() => {
promptStub.restore();
createSourceStub.restore();
getInstanceStub.restore();

nock.cleanAll();
});

it("should return the correct source name for a valid local source", async () => {
Expand Down Expand Up @@ -190,12 +197,17 @@ describe("updateHelper", () => {
promptStub = sinon.stub(prompt, "promptOnce");
createSourceStub = sinon.stub(extensionsHelper, "createSourceFromLocation");
getInstanceStub = sinon.stub(extensionsApi, "getInstance").resolves(INSTANCE);

// The logic will fetch the extensions registry, but it doesn't need to receive anything.
nock(firebaseExtensionsRegistryOrigin).get("/extensions.json").reply(200, {});
});

afterEach(() => {
promptStub.restore();
createSourceStub.restore();
getInstanceStub.restore();

nock.cleanAll();
});

it("should return the correct source name for a valid url source", async () => {
Expand Down

0 comments on commit 23005ff

Please sign in to comment.