Skip to content

Commit

Permalink
Fix Auth Emulator deleteTenant not working with Node Admin. (firebase…
Browse files Browse the repository at this point in the history
…#3817)

* Fix Auth Emulator deleteTenant not working with Node Admin.

* Add changelog.

* Add more comments.
  • Loading branch information
yuchenshi authored and devpeerapong committed Dec 14, 2021
1 parent 081a8e2 commit fa4c6a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -0,0 +1 @@
- Fix Auth Emulator deleteTenant not working with Node Admin (#3817).
8 changes: 8 additions & 0 deletions src/emulator/auth/server.ts
Expand Up @@ -124,6 +124,14 @@ export async function createApp(
// This is similar to production behavior. Safe since all APIs are cookieless.
app.use(cors({ origin: true }));

// Workaround for clients (e.g. Node.js Admin SDK) that send request bodies
// with HTTP DELETE requests. Such requests are tolerated by production, but
// exegesis will reject them without the following hack.
app.delete("*", (req, _, next) => {
delete req.headers["content-type"];
next();
});

app.get("/", (req, res) => {
return res.json({
authEmulator: {
Expand Down
18 changes: 18 additions & 0 deletions src/test/emulators/auth/tenant.spec.ts
Expand Up @@ -106,6 +106,24 @@ describeAuthEmulator("tenant management", ({ authApi }) => {
expectStatusCode(200, res);
});
});

it("should delete tenants if request body is passed", async () => {
const projectId = "project-id";
const tenant = await registerTenant(authApi(), projectId, {});

await authApi()
.delete(
`/identitytoolkit.googleapis.com/v2/projects/${projectId}/tenants/${tenant.tenantId}`
)
.set("Authorization", "Bearer owner")
// Sets content-type and sends "{}" in request payload. This is very
// uncommon for HTTP DELETE requests, but clients like the Node.js Admin
// SDK do it anyway. We want the emulator to tolerate this.
.send({})
.then((res) => {
expectStatusCode(200, res);
});
});
});

describe("listTenants", () => {
Expand Down

0 comments on commit fa4c6a3

Please sign in to comment.