mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): Fix routing for waiting webhooks and forms (#14470)
This commit is contained in:
committed by
GitHub
parent
6c73d7ed81
commit
b5d5b57118
@@ -193,13 +193,13 @@ export abstract class AbstractServer {
|
||||
|
||||
// Register a handler for waiting forms
|
||||
this.app.all(
|
||||
`/${this.endpointFormWaiting}/:path/{:suffix}`,
|
||||
`/${this.endpointFormWaiting}/:path{/:suffix}`,
|
||||
createWebhookHandlerFor(Container.get(WaitingForms)),
|
||||
);
|
||||
|
||||
// Register a handler for waiting webhooks
|
||||
this.app.all(
|
||||
`/${this.endpointWebhookWaiting}/:path/{:suffix}`,
|
||||
`/${this.endpointWebhookWaiting}/:path{/:suffix}`,
|
||||
createWebhookHandlerFor(Container.get(WaitingWebhooks)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,23 +16,31 @@ import { mockInstance } from '@test/mocking';
|
||||
let agent: SuperAgentTest;
|
||||
|
||||
describe('WebhookServer', () => {
|
||||
const liveWebhooks = mockInstance(LiveWebhooks);
|
||||
const testWebhooks = mockInstance(TestWebhooks);
|
||||
const waitingWebhooks = mockInstance(WaitingWebhooks);
|
||||
mockInstance(WaitingForms);
|
||||
mockInstance(ExternalHooks);
|
||||
const globalConfig = Container.get(GlobalConfig);
|
||||
|
||||
const mockResponse = (data = {}, headers = {}, status = 200) => {
|
||||
const response = mock<IWebhookResponseCallbackData>();
|
||||
response.responseCode = status;
|
||||
response.data = data;
|
||||
response.headers = headers;
|
||||
return response;
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
const server = new WebhookServer();
|
||||
// @ts-expect-error: testWebhooksEnabled is private
|
||||
server.testWebhooksEnabled = true;
|
||||
await server.start();
|
||||
agent = testAgent(server.app);
|
||||
});
|
||||
|
||||
describe('CORS', () => {
|
||||
const corsOrigin = 'https://example.com';
|
||||
const liveWebhooks = mockInstance(LiveWebhooks);
|
||||
const testWebhooks = mockInstance(TestWebhooks);
|
||||
mockInstance(WaitingWebhooks);
|
||||
mockInstance(WaitingForms);
|
||||
|
||||
beforeAll(async () => {
|
||||
const server = new WebhookServer();
|
||||
// @ts-expect-error: testWebhooksEnabled is private
|
||||
server.testWebhooksEnabled = true;
|
||||
await server.start();
|
||||
agent = testAgent(server.app);
|
||||
});
|
||||
|
||||
const tests = [
|
||||
['webhook', liveWebhooks],
|
||||
['webhookTest', testWebhooks],
|
||||
@@ -43,8 +51,9 @@ describe('WebhookServer', () => {
|
||||
|
||||
for (const [key, manager] of tests) {
|
||||
describe(`for ${key}`, () => {
|
||||
const pathPrefix = globalConfig.endpoints[key];
|
||||
|
||||
it('should handle preflight requests', async () => {
|
||||
const pathPrefix = Container.get(GlobalConfig).endpoints[key];
|
||||
manager.getWebhookMethods.mockResolvedValueOnce(['GET']);
|
||||
|
||||
const response = await agent
|
||||
@@ -58,7 +67,6 @@ describe('WebhookServer', () => {
|
||||
});
|
||||
|
||||
it('should handle regular requests', async () => {
|
||||
const pathPrefix = Container.get(GlobalConfig).endpoints[key];
|
||||
manager.getWebhookMethods.mockResolvedValueOnce(['GET']);
|
||||
manager.executeWebhook.mockResolvedValueOnce(
|
||||
mockResponse({ test: true }, { key: 'value ' }),
|
||||
@@ -75,13 +83,37 @@ describe('WebhookServer', () => {
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const mockResponse = (data = {}, headers = {}, status = 200) => {
|
||||
const response = mock<IWebhookResponseCallbackData>();
|
||||
response.responseCode = status;
|
||||
response.data = data;
|
||||
response.headers = headers;
|
||||
return response;
|
||||
};
|
||||
describe('Routing for Waiting Webhooks', () => {
|
||||
const pathPrefix = globalConfig.endpoints.webhookWaiting;
|
||||
|
||||
waitingWebhooks.executeWebhook.mockImplementation(async (req) => {
|
||||
return {
|
||||
noWebhookResponse: false,
|
||||
responseCode: 200,
|
||||
data: {
|
||||
params: req.params,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should handle URLs without suffix', async () => {
|
||||
const response = await agent.get(`/${pathPrefix}/12345`);
|
||||
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(response.body).toEqual({
|
||||
params: { path: '12345' },
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle URLs with suffix', async () => {
|
||||
const response = await agent.get(`/${pathPrefix}/12345/suffix`);
|
||||
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(response.body).toEqual({
|
||||
params: { path: '12345', suffix: 'suffix' },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user