test: Hotfix/Orgs rewrite causing 404 with 3 or more dots domains#9803
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
|
Thank you for following the naming conventions! 🙏 |
| @@ -0,0 +1,15 @@ | |||
| const getDefaultSubdomain = (url) => { | |||
| if (!url.startsWith("http:") && !url.startsWith("https:")) { | |||
| // Make it a valid URL. Mabe we can simply return null and opt-out from orgs support till the use a URL scheme. | |||
There was a problem hiding this comment.
Someone reported they were using cal.com without specifying https:// earlier. So I just added it, didn't verify what else fails if someone uses that.
| const getSubdomain = () => { | ||
| const _url = new URL(process.env.NEXT_PUBLIC_WEBAPP_URL); |
There was a problem hiding this comment.
Moved outside to allow writing unit tests
39a3660 to
82b31aa
Compare
82b31aa to
25bd1b8
Compare
📦 Next.js Bundle Analysis for @calcom/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 New Pages AddedThe following pages were added to the bundle from the code in this PR:
Ninety-eight Pages Changed SizeThe following pages changed size from the code in this PR compared to its base branch:
DetailsOnly the gzipped size is provided here based on an expert tip. First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If Any third party scripts you have added directly to your app using the The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored. |
| source: `/:user((?!${pages.join("|")}|_next|public))/:path*`, | ||
| destination: "/:user/:path*", | ||
| }, | ||
| ...(process.env.ORGANIZATIONS_ENABLED |
There was a problem hiding this comment.
Even though I have tried to fix the RegExp, still using this existing env variable to opt-out of the behaviour and not impact existing deployments by default.
| const subdomainRegExp = getSubdomainRegExp('https://calcom.example.com'); | ||
| expect(pagesRewriteRegex(subdomainRegExp).exec('calcom.example.com')).toEqual(null) | ||
| expect(pagesRewriteRegex(subdomainRegExp).exec('acme.calcom.example.com')?.groups?.orgSlug).toEqual('acme') | ||
| // The following also matches which causes anything other than the domain in NEXT_PUBLIC_WEBAPP_URL to give 404 |
There was a problem hiding this comment.
I am not sure what to do about this case?
| const _url = new URL(url); | ||
| const regex = new RegExp(/^([a-z]+\:\/{2})?((?<subdomain>[\w-.]+)\.[\w-]+\.\w+)$/); | ||
| //console.log(_url.hostname, _url.hostname.match(regex)); | ||
| return _url.hostname.match(regex)?.groups?.subdomain || null; |
| const defaultSubdomain = getDefaultSubdomain(url); | ||
| const subdomain = defaultSubdomain ? `(?!${defaultSubdomain})[^.]+` : "[^.]+"; | ||
| return subdomain; |
| url = `https://${url}`; | ||
| } | ||
| const _url = new URL(url); | ||
| const regex = new RegExp(/^([a-z]+\:\/{2})?((?<subdomain>[\w-.]+)\.[\w-]+\.\w+)$/); |
There was a problem hiding this comment.
Only this regex changed with inclusion of dot in subdomain capturing group
There was a problem hiding this comment.
so, when the subdomain is org.app.cal.com the slug will be org.app?
Current Playwright Test Results Summary✅ 114 Passing - Run may still be in progress, this comment will be updated as current testing workflow or job completes... (Last updated on 06/27/2023 06:57:10am UTC) Run DetailsRunning Workflow PR Update on Github Actions Commit: 50755b5 Started: 06/27/2023 06:54:51am UTC
|
| Test Case | Last 7 days Failures | Last 7 days Flakes |
|---|---|---|
|
Reschedule Tests -- old-booker Attendee should be able to reschedule a booking
Retry 1 • Initial Attempt |
0% (0)0 / 259 runsfailed over last 7 days |
14.67% (38)38 / 259 runsflaked over last 7 days |
📄 packages/embeds/embed-core/playwright/tests/action-based.e2e.ts • 1 Flake
Test Case Results
| Test Case | Last 7 days Failures | Last 7 days Flakes |
|---|---|---|
|
Popup Tests should be able to reschedule
Retry 1 • Initial Attempt |
27.17% (47)47 / 173 runsfailed over last 7 days |
70.52% (122)122 / 173 runsflaked over last 7 days |
|
Seems to be working for me @roae. Though, I would like you take it over as I am not fully aware of the logic. |
| const matcherConfigRootPath = { | ||
| has: [ | ||
| { | ||
| type: "host", | ||
| value: orgHostRegExp, | ||
| }, | ||
| ], | ||
| source: "/", | ||
| }; | ||
|
|
||
| const matcherConfigOrgMemberPath = { | ||
| has: [ | ||
| { | ||
| type: "host", | ||
| value: orgHostRegExp, | ||
| }, | ||
| ], | ||
| source: `/:user((?!${pages.join("|")}|_next|public)[a-zA-Z0-9\-_]+)`, | ||
| }; | ||
|
|
||
| const matcherConfigUserPath = { | ||
| has: [ | ||
| { | ||
| type: "host", | ||
| value: `^(?<orgSlug>${subdomainRegExp}[^.]+)\\..*`, | ||
| }, | ||
| ], | ||
| source: `/:user((?!${pages.join("|")}|_next|public))/:path*`, | ||
| }; |
There was a problem hiding this comment.
Abstracted out to shared with headers
| }, | ||
| ], | ||
| }, | ||
| ...[ |
There was a problem hiding this comment.
Added response header X-Cal-Org-path to easily identify to which path the rewrite occured. It would also help in writing checkly tests where we could just check the header to test if the rewrite is working correctly.
|
@hariombalhara it is not working on my end, I'm taking over of this. |
|
@roae I have added a response header to confirm the route(X-Cal-Org-Path). Can you check what the value for this is for you |
Yes, I notice that, it seems there was something bad in my BD I just reseted it and create a new organization and teams and is working now! |
roae
left a comment
There was a problem hiding this comment.
Thanks @hariombalhara, nice job.
It's working on my end.
|
I still experience the same identical issue on a new fresh installation. The fix it's already in :main ? |
|
I'm also still experiencing this on a fresh install inside docker. My full host domain only has 2 periods. Everything else works great, except for trying to access the root / path. |
…lcom#9803) * Fix RegExp * Used ORGANIZATIONS_ENABLED to opt-out of orgs behaviour * Add comments * Add a new testcase * Add response headers for easier debugging and Checkly tests in production







What does this PR do?
Fixes #9768
Added tests as well. Helped in testing and helps in avoiding future bugs.
Type of change
How should this be tested?
calcom.app.company.comandacme.calcom.app.company.comto 127.0.0.1calcom.app.company.comand see a 404. With this branch that 404 is fixed. Also, testacme.calcom.app.company.com, it should also not be 404.Here are the tests done with app.cal.com and vwo org.
Mandatory Tasks