mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): Normalize trailing slash when setting CORS headers for test webhooks (#15906)
This commit is contained in:
@@ -56,7 +56,7 @@ describe('TestWebhooks', () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
describe('needsWebhook()', () => {
|
||||
@@ -192,4 +192,19 @@ describe('TestWebhooks', () => {
|
||||
expect(mockedAdditionalData.getBase).toHaveBeenCalledWith(userId);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getWebhookMethods()', () => {
|
||||
test('should normalize trailing slash', async () => {
|
||||
const METHOD = 'POST';
|
||||
const PATH_WITH_SLASH = 'register/';
|
||||
const PATH_WITHOUT_SLASH = 'register';
|
||||
registrations.getAllKeys.mockResolvedValue([`${METHOD}|${PATH_WITHOUT_SLASH}`]);
|
||||
|
||||
const resultWithSlash = await testWebhooks.getWebhookMethods(PATH_WITH_SLASH);
|
||||
const resultWithoutSlash = await testWebhooks.getWebhookMethods(PATH_WITHOUT_SLASH);
|
||||
|
||||
expect(resultWithSlash).toEqual([METHOD]);
|
||||
expect(resultWithoutSlash).toEqual([METHOD]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -174,7 +174,8 @@ export class TestWebhooks implements IWebhookManager {
|
||||
if (timeout) clearTimeout(timeout);
|
||||
}
|
||||
|
||||
async getWebhookMethods(path: string) {
|
||||
async getWebhookMethods(rawPath: string) {
|
||||
const path = removeTrailingSlash(rawPath);
|
||||
const allKeys = await this.registrations.getAllKeys();
|
||||
|
||||
const webhookMethods = allKeys
|
||||
|
||||
Reference in New Issue
Block a user