Skip to content

Commit

Permalink
FIX: hostname value on emulated rewrited function (#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCis authored and samtstern committed Jun 3, 2019
1 parent e44fa00 commit bf1c1de
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
* Fixed bug where environment variables are unset for script in `emulators:exec`.
* `emulators:exec` script now inherits stdout and stderr.
* Improved reliability and performance of project listing for `firebase use` command.
* Fixed bug where `firestore:delete` skips legacy documents with numeric IDs.
* Fixed bug where `firestore:delete` skips legacy documents with numeric IDs.
* Fixed bug in Firestore emulator where it ignored `x-forwarded-host` header.
1 change: 1 addition & 0 deletions src/emulator/functionsEmulatorRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ async function ProcessHTTPS(frb: FunctionsRuntimeBundle, trigger: EmulatedTrigge
}
};

ephemeralServer.enable("trust proxy");
ephemeralServer.use(bodyParser.json({}));
ephemeralServer.use(bodyParser.text({}));
ephemeralServer.use(bodyParser.urlencoded({ extended: true }));
Expand Down
36 changes: 36 additions & 0 deletions src/test/emulators/functionsEmulatorRuntime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,42 @@ describe("FunctionsEmulator-Runtime", () => {

await runtime.exit;
}).timeout(TIMEOUT_MED);

it("should handle `x-forwarded-host`", async () => {
const runtime = InvokeRuntimeWithFunctions(FunctionRuntimeBundles.onRequest, () => {
require("firebase-admin").initializeApp();
return {
function_id: require("firebase-functions").https.onRequest(
async (req: any, res: any) => {
res.json({ hostname: req.hostname });
}
),
};
});

await runtime.ready;
await new Promise((resolve) => {
request(
{
socketPath: runtime.metadata.socketPath,
path: "/",
headers: {
"x-forwarded-host": "real-hostname",
},
},
(res) => {
let data = "";
res.on("data", (chunk) => (data += chunk));
res.on("end", () => {
expect(JSON.parse(data)).to.deep.equal({ hostname: "real-hostname" });
resolve();
});
}
).end();
});

await runtime.exit;
}).timeout(TIMEOUT_MED);
});

describe("Cloud Firestore", () => {
Expand Down

0 comments on commit bf1c1de

Please sign in to comment.