Skip to content

corrects regex for domain matching authorized domains #6479

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 2 commits into from
Oct 26, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Enable [preferRest](https://firebase.google.com/docs/reference/admin/node/firebase-admin.firestore.firestoresettings.md#firestoresettingspreferrest) option by default for Firestore functions. (#6147)
- Fixed a bug where re-deploying 2nd Gen Firestore function failed after updating secrets. (#6456)
- Fixed a bug where similarly-named Hosting channels would cause issues when updating authorized domains. (#6356)
4 changes: 2 additions & 2 deletions src/hosting/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ export async function getCleanDomains(project: string, site: string): Promise<st
return acc;
}, {});

// match any string that has ${site}--*
const siteMatch = new RegExp(`${site}--`, "i");
// match any string that starts with ${site}--*
const siteMatch = new RegExp(`^${site}--`, "i");
// match any string that ends in firebaseapp.com
const firebaseAppMatch = new RegExp(/firebaseapp.com$/);
const domains = await getAuthDomains(project);
Expand Down
35 changes: 35 additions & 0 deletions src/test/hosting/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,41 @@ describe("hosting", () => {
expect(res).to.deep.equal(EXPECTED_DOMAINS_RESPONSE);
expect(nock.isDone()).to.be.true;
});

it("should not remove sites that are similarly named", async () => {
// mock listChannels response
nock(hostingApiOrigin)
.get(`/v1beta1/projects/${PROJECT_ID}/sites/${SITE}/channels`)
.query(() => true)
.reply(200, {
channels: [
{ url: "https://my-site--ch1-4iyrl1uo.web.app" },
{ url: "https://my-site--ch2-ygd8582v.web.app" },
],
});
// mock getAuthDomains response
nock(identityOrigin)
.get(`/admin/v2/projects/${PROJECT_ID}/config`)
.reply(200, {
authorizedDomains: [
"localhost",
"randomurl.com",
"my-site--ch1-4iyrl1uo.web.app",
"my-site--expiredchannel-difhyc76.web.app",
"backendof-my-site--some-abcd1234.web.app",
],
});

const res = await hostingApi.getCleanDomains(PROJECT_ID, SITE);

expect(res).to.deep.equal([
"localhost",
"randomurl.com",
"my-site--ch1-4iyrl1uo.web.app",
"backendof-my-site--some-abcd1234.web.app",
]);
expect(nock.isDone()).to.be.true;
});
});

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