mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +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(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('needsWebhook()', () => {
|
describe('needsWebhook()', () => {
|
||||||
@@ -192,4 +192,19 @@ describe('TestWebhooks', () => {
|
|||||||
expect(mockedAdditionalData.getBase).toHaveBeenCalledWith(userId);
|
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);
|
if (timeout) clearTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getWebhookMethods(path: string) {
|
async getWebhookMethods(rawPath: string) {
|
||||||
|
const path = removeTrailingSlash(rawPath);
|
||||||
const allKeys = await this.registrations.getAllKeys();
|
const allKeys = await this.registrations.getAllKeys();
|
||||||
|
|
||||||
const webhookMethods = allKeys
|
const webhookMethods = allKeys
|
||||||
|
|||||||
Reference in New Issue
Block a user