Skip to content

Commit af7992d

Browse files
authored
corrects regex for domain matching authorized domains (#6479)
* corrects regex for domain matching authorized domains * add changelog
1 parent e53c50d commit af7992d

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Enable [preferRest](https://firebase.google.com/docs/reference/admin/node/firebase-admin.firestore.firestoresettings.md#firestoresettingspreferrest) option by default for Firestore functions. (#6147)
22
- Fixed a bug where re-deploying 2nd Gen Firestore function failed after updating secrets. (#6456)
3+
- Fixed a bug where similarly-named Hosting channels would cause issues when updating authorized domains. (#6356)

src/hosting/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,8 @@ export async function getCleanDomains(project: string, site: string): Promise<st
633633
return acc;
634634
}, {});
635635

636-
// match any string that has ${site}--*
637-
const siteMatch = new RegExp(`${site}--`, "i");
636+
// match any string that starts with ${site}--*
637+
const siteMatch = new RegExp(`^${site}--`, "i");
638638
// match any string that ends in firebaseapp.com
639639
const firebaseAppMatch = new RegExp(/firebaseapp.com$/);
640640
const domains = await getAuthDomains(project);

src/test/hosting/api.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,41 @@ describe("hosting", () => {
711711
expect(res).to.deep.equal(EXPECTED_DOMAINS_RESPONSE);
712712
expect(nock.isDone()).to.be.true;
713713
});
714+
715+
it("should not remove sites that are similarly named", async () => {
716+
// mock listChannels response
717+
nock(hostingApiOrigin)
718+
.get(`/v1beta1/projects/${PROJECT_ID}/sites/${SITE}/channels`)
719+
.query(() => true)
720+
.reply(200, {
721+
channels: [
722+
{ url: "https://my-site--ch1-4iyrl1uo.web.app" },
723+
{ url: "https://my-site--ch2-ygd8582v.web.app" },
724+
],
725+
});
726+
// mock getAuthDomains response
727+
nock(identityOrigin)
728+
.get(`/admin/v2/projects/${PROJECT_ID}/config`)
729+
.reply(200, {
730+
authorizedDomains: [
731+
"localhost",
732+
"randomurl.com",
733+
"my-site--ch1-4iyrl1uo.web.app",
734+
"my-site--expiredchannel-difhyc76.web.app",
735+
"backendof-my-site--some-abcd1234.web.app",
736+
],
737+
});
738+
739+
const res = await hostingApi.getCleanDomains(PROJECT_ID, SITE);
740+
741+
expect(res).to.deep.equal([
742+
"localhost",
743+
"randomurl.com",
744+
"my-site--ch1-4iyrl1uo.web.app",
745+
"backendof-my-site--some-abcd1234.web.app",
746+
]);
747+
expect(nock.isDone()).to.be.true;
748+
});
714749
});
715750

716751
describe("getSiteDomains", () => {

0 commit comments

Comments
 (0)