-
Notifications
You must be signed in to change notification settings - Fork 17
46864 frontend [ Configuration ] Public forms via URL-path /forms/ #217
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
EBirkenfeld
merged 15 commits into
master
from
frontend/configuration/46864__public_forms_via_url_path
Jun 3, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8baf224
46864 feat(forms): add path-based public form routing
EBirkenfeld 125e67a
46864 feat(forms): add path-based public form routing
EBirkenfeld 4ab1839
Merge branch 'frontend/configuration/46864__public_forms_via_url_path…
EBirkenfeld 5bd0421
Merge branch 'frontend/configuration/46864__public_forms_via_url_path…
EBirkenfeld 2eadc67
Merge branch 'frontend/configuration/46864__public_forms_via_url_path…
EBirkenfeld 96b42dd
Merge branch 'frontend/configuration/46864__public_forms_via_url_path…
EBirkenfeld 0d5a052
Merge branch 'frontend/configuration/46864__public_forms_via_url_path…
EBirkenfeld 9662566
46864 refactor(forms): extract shared isFormPath helper and unify for…
EBirkenfeld dc7f0d3
46864 refactor(forms): extract shared isFormPath helper and unify for…
EBirkenfeld f16158b
Merge branch 'frontend/configuration/46864__public_forms_via_url_path…
EBirkenfeld 8aeee60
Merge branch 'frontend/configuration/46864__public_forms_via_url_path…
EBirkenfeld 8190fe3
Merge branch 'frontend/configuration/46864__public_forms_via_url_path…
EBirkenfeld 479e453
Merge remote-tracking branch 'origin/master' into frontend/configurat…
EBirkenfeld cbc1c95
Merge branch 'master' into frontend/configuration/46864__public_forms…
EBirkenfeld c405b0b
Merge branch 'master' into frontend/configuration/46864__public_forms…
EBirkenfeld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
frontend/src/public/utils/identifyAppPart/__tests__/getFormsBasename.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { getFormsBasename, FORMS_PATH_PREFIX } from '../constants'; | ||
|
|
||
| describe('getFormsBasename', () => { | ||
| describe('path-based mode — returns FORMS_PATH_PREFIX', () => { | ||
| it('should return "/forms" for /forms/{token}', () => { | ||
| expect(getFormsBasename('/forms/abc123')).toBe(FORMS_PATH_PREFIX); | ||
| }); | ||
|
|
||
| it('should return "/forms" for /forms/{token}/ with trailing slash', () => { | ||
| expect(getFormsBasename('/forms/abc123/')).toBe(FORMS_PATH_PREFIX); | ||
| }); | ||
|
|
||
| it('should return "/forms" for exact /forms prefix (no token)', () => { | ||
| expect(getFormsBasename('/forms')).toBe(FORMS_PATH_PREFIX); | ||
| }); | ||
|
|
||
| it('should return "/forms" for /forms/ with trailing slash only', () => { | ||
| expect(getFormsBasename('/forms/')).toBe(FORMS_PATH_PREFIX); | ||
| }); | ||
|
|
||
| it('should return "/forms" for nested path /forms/embed/{token}', () => { | ||
| expect(getFormsBasename('/forms/embed/abc123')).toBe(FORMS_PATH_PREFIX); | ||
| }); | ||
|
|
||
| it('should return "/forms" for deep nested path /forms/a/b/c', () => { | ||
| expect(getFormsBasename('/forms/a/b/c')).toBe(FORMS_PATH_PREFIX); | ||
| }); | ||
|
|
||
| it('should return "/forms" for UUID token /forms/550e8400-e29b-41d4-a716-446655440000', () => { | ||
| expect(getFormsBasename('/forms/550e8400-e29b-41d4-a716-446655440000')).toBe(FORMS_PATH_PREFIX); | ||
| }); | ||
| }); | ||
|
|
||
| describe('subdomain mode — returns undefined', () => { | ||
| it('should return undefined for root path /', () => { | ||
| expect(getFormsBasename('/')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined for /{token} (subdomain mode)', () => { | ||
| expect(getFormsBasename('/abc123')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined for /{token}/ with trailing slash', () => { | ||
| expect(getFormsBasename('/abc123/')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined for /embed/{token} (subdomain embed)', () => { | ||
| expect(getFormsBasename('/embed/abc123')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined for /error/ path', () => { | ||
| expect(getFormsBasename('/error/')).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('boundary cases — paths starting with "form" but not "/forms"', () => { | ||
| it('should return undefined for /formsome (no slash after "form")', () => { | ||
| expect(getFormsBasename('/formsome')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined for /formation/abc', () => { | ||
| expect(getFormsBasename('/formation/abc')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined for /form (shorter than /forms)', () => { | ||
| expect(getFormsBasename('/form')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined for /formset/abc', () => { | ||
| expect(getFormsBasename('/formset/abc')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined for empty path', () => { | ||
| expect(getFormsBasename('')).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('security — prevents path traversal or injection', () => { | ||
| it('should return undefined for /Forms/abc (case-sensitive)', () => { | ||
| expect(getFormsBasename('/Forms/abc')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined for /FORMS/abc (uppercase)', () => { | ||
| expect(getFormsBasename('/FORMS/abc')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return "/forms" for /forms/../../etc (still starts with /forms/)', () => { | ||
| // The function only checks prefix, path traversal is handled by Express | ||
| expect(getFormsBasename('/forms/../../etc')).toBe(FORMS_PATH_PREFIX); | ||
| }); | ||
| }); | ||
| }); |
136 changes: 136 additions & 0 deletions
136
frontend/src/public/utils/identifyAppPart/__tests__/identifyAppPartOnClient.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // <reference types="jest" /> | ||
| import { identifyAppPartOnClient } from '../identifyAppPartOnClient'; | ||
| import { EAppPart } from '../types'; | ||
| import { FORMS_PATH_PREFIX } from '../constants'; | ||
|
|
||
| jest.mock('../../getConfig', () => ({ | ||
| getBrowserConfig: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../history', () => ({ | ||
| history: { location: { pathname: '/' }, push: jest.fn(), listen: jest.fn() }, | ||
| })); | ||
|
|
||
| import { getBrowserConfig } from '../../getConfig'; | ||
| import { history } from '../../history'; | ||
|
|
||
| const setWindowLocation = (overrides: Record<string, string> = {}) => { | ||
| Object.defineProperty(window, 'location', { | ||
| value: { | ||
| pathname: '/', | ||
| hostname: 'localhost', | ||
| ...overrides, | ||
| }, | ||
| writable: true, | ||
| configurable: true, | ||
| }); | ||
| }; | ||
|
|
||
| describe('identifyAppPartOnClient', () => { | ||
| const mockGetBrowserConfig = getBrowserConfig as jest.Mock; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| setWindowLocation(); | ||
| (history as any).location.pathname = '/'; | ||
| }); | ||
|
|
||
| describe('forms detection', () => { | ||
| it('returns PublicFormApp for path-based forms (/forms/*)', () => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: '' } }); | ||
| setWindowLocation({ pathname: `${FORMS_PATH_PREFIX}/abc123` }); | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.PublicFormApp); | ||
| }); | ||
|
|
||
| it('returns PublicFormApp when pathname equals /forms', () => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: '' } }); | ||
| setWindowLocation({ pathname: FORMS_PATH_PREFIX }); | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.PublicFormApp); | ||
| }); | ||
|
|
||
| it('returns PublicFormApp for subdomain forms', () => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: 'form.example.com' } }); | ||
| setWindowLocation({ hostname: 'form.example.com' }); | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.PublicFormApp); | ||
| }); | ||
|
|
||
| it('returns PublicFormApp when both path and subdomain match', () => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: 'form.example.com' } }); | ||
| setWindowLocation({ | ||
| pathname: `${FORMS_PATH_PREFIX}/token`, | ||
| hostname: 'form.example.com', | ||
| }); | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.PublicFormApp); | ||
| }); | ||
| }); | ||
|
|
||
| describe('guest task', () => { | ||
| beforeEach(() => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: '' } }); | ||
| }); | ||
|
|
||
| it('returns GuestTaskApp when history pathname contains /guest-task/', () => { | ||
| (history as any).location.pathname = '/guest-task/some-token'; | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.GuestTaskApp); | ||
| }); | ||
| }); | ||
|
|
||
| describe('main app fallback', () => { | ||
| beforeEach(() => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: '' } }); | ||
| }); | ||
|
|
||
| it('returns MainApp for regular paths', () => { | ||
| setWindowLocation({ pathname: '/dashboard' }); | ||
| (history as any).location.pathname = '/dashboard'; | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.MainApp); | ||
| }); | ||
|
|
||
| it('returns MainApp when formSubdomain is empty string', () => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: '' } }); | ||
| setWindowLocation({ hostname: 'localhost', pathname: '/dashboard' }); | ||
| (history as any).location.pathname = '/dashboard'; | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.MainApp); | ||
| }); | ||
| }); | ||
|
|
||
| describe('edge cases', () => { | ||
| beforeEach(() => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: '' } }); | ||
| }); | ||
|
|
||
| it('does NOT match /formsome as forms path (boundary check)', () => { | ||
| setWindowLocation({ pathname: '/formsome/token' }); | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.MainApp); | ||
| }); | ||
|
|
||
| it('does NOT match /form as forms path', () => { | ||
| setWindowLocation({ pathname: '/form/token' }); | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.MainApp); | ||
| }); | ||
|
|
||
| it('handles formSubdomain=undefined without crashing', () => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: undefined } }); | ||
| setWindowLocation({ pathname: '/dashboard' }); | ||
| (history as any).location.pathname = '/dashboard'; | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.MainApp); | ||
| }); | ||
|
|
||
| it('partial hostname match — exact comparison rejects substrings', () => { | ||
| mockGetBrowserConfig.mockReturnValue({ config: { formSubdomain: 'form.example.com' } }); | ||
| setWindowLocation({ hostname: 'reform.example.com' }); | ||
|
|
||
| expect(identifyAppPartOnClient()).toBe(EAppPart.MainApp); | ||
| }); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.