fix(core): Normalize trailing slash when setting CORS headers for test webhooks (#15906)

This commit is contained in:
Iván Ovejero
2025-06-02 14:13:18 +02:00
committed by GitHub
parent 7ae67f016d
commit 61d0c6a6e7
2 changed files with 18 additions and 2 deletions

View File

@@ -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]);
});
});
});

View File

@@ -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