Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s
356 lines
12 KiB
TypeScript
356 lines
12 KiB
TypeScript
import { gql } from 'graphql-tag';
|
|
import { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
|
|
import {
|
|
createWebhook,
|
|
createWebhookReceiver,
|
|
deleteWebhook,
|
|
getWebhook,
|
|
getWebhooks,
|
|
updateWebhook,
|
|
} from 'test/integration/metadata/suites/utils/webhook-test.util';
|
|
import { makeAdminPanelAPIRequest } from 'test/integration/twenty-config/utils/make-admin-panel-api-request.util';
|
|
import { expectEventually } from 'test/integration/utils/expect-eventually.util';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
import { type UpdateWebhookInput } from 'src/engine/metadata-modules/webhook/dtos/update-webhook.input';
|
|
|
|
const CREATE_CONFIG_VARIABLE_MUTATION = gql`
|
|
mutation CreateDatabaseConfigVariable($key: String!, $value: JSON!) {
|
|
createDatabaseConfigVariable(key: $key, value: $value)
|
|
}
|
|
`;
|
|
|
|
const GET_CONFIG_VARIABLE_QUERY = gql`
|
|
query GetDatabaseConfigVariable($key: String!) {
|
|
getDatabaseConfigVariable(key: $key) {
|
|
value
|
|
source
|
|
}
|
|
}
|
|
`;
|
|
|
|
const DELETE_CONFIG_VARIABLE_MUTATION = gql`
|
|
mutation DeleteDatabaseConfigVariable($key: String!) {
|
|
deleteDatabaseConfigVariable(key: $key)
|
|
}
|
|
`;
|
|
|
|
const DESTROY_PERSON_MUTATION = gql`
|
|
mutation DestroyPerson($id: ID!) {
|
|
destroyPerson(id: $id) {
|
|
id
|
|
}
|
|
}
|
|
`;
|
|
|
|
const CREATE_PERSON_MUTATION = gql`
|
|
mutation CreatePerson($data: PersonCreateInput!) {
|
|
createPerson(data: $data) {
|
|
id
|
|
name {
|
|
firstName
|
|
lastName
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
describe('webhooksResolver (e2e)', () => {
|
|
let createdWebhookId: string | undefined;
|
|
let createdPersonId: string | undefined;
|
|
|
|
afterEach(async () => {
|
|
if (createdPersonId) {
|
|
await makeGraphqlAPIRequest({
|
|
query: DESTROY_PERSON_MUTATION,
|
|
variables: { id: createdPersonId },
|
|
}).catch(() => {});
|
|
createdPersonId = undefined;
|
|
}
|
|
|
|
if (createdWebhookId) {
|
|
await deleteWebhook(createdWebhookId).catch(() => {});
|
|
createdWebhookId = undefined;
|
|
}
|
|
});
|
|
|
|
describe('webhooks query', () => {
|
|
it('should find many webhooks', async () => {
|
|
const response = await getWebhooks();
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.body.data).toBeDefined();
|
|
expect(response.body.errors).toBeUndefined();
|
|
expect(response.body.data.webhooks).toBeDefined();
|
|
expect(Array.isArray(response.body.data.webhooks)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('createWebhook mutation', () => {
|
|
it('should create a webhook successfully', async () => {
|
|
const webhookInput = {
|
|
targetUrl: 'https://example.com/webhook',
|
|
operations: ['person.created', 'company.updated'],
|
|
description: 'Test webhook',
|
|
secret: 'test-secret',
|
|
};
|
|
|
|
const response = await createWebhook(webhookInput);
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.body.data).toBeDefined();
|
|
expect(response.body.errors).toBeUndefined();
|
|
|
|
const createdWebhookData = response.body.data.createWebhook;
|
|
|
|
expect(createdWebhookData).toBeDefined();
|
|
expect(createdWebhookData.id).toBeDefined();
|
|
expect(createdWebhookData.targetUrl).toBe(webhookInput.targetUrl);
|
|
expect(createdWebhookData.operations).toEqual(webhookInput.operations);
|
|
expect(createdWebhookData.description).toBe(webhookInput.description);
|
|
expect(createdWebhookData.secret).toBe(webhookInput.secret);
|
|
|
|
createdWebhookId = createdWebhookData.id;
|
|
});
|
|
|
|
it('should fail to create webhook with invalid URL', async () => {
|
|
const webhookInput = {
|
|
targetUrl: 'invalid-url',
|
|
operations: ['person.created'],
|
|
description: 'Test webhook',
|
|
secret: 'test-secret',
|
|
};
|
|
|
|
const response = await createWebhook(webhookInput);
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.body.errors).toBeDefined();
|
|
expect(response.body.errors.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('updateWebhook mutation', () => {
|
|
it('should update a webhook successfully', async () => {
|
|
const createResponse = await createWebhook({
|
|
targetUrl: 'https://example.com/webhook',
|
|
operations: ['person.created'],
|
|
description: 'Test webhook',
|
|
secret: 'test-secret',
|
|
});
|
|
|
|
const createdWebhookData = createResponse.body.data.createWebhook;
|
|
|
|
createdWebhookId = createdWebhookData.id;
|
|
|
|
const updateInput: UpdateWebhookInput = {
|
|
id: createdWebhookData.id,
|
|
update: {
|
|
targetUrl: 'https://updated.com/webhook',
|
|
operations: ['person.updated', 'company.created'],
|
|
description: 'Updated webhook',
|
|
secret: 'updated-secret',
|
|
},
|
|
};
|
|
|
|
const updateResponse = await updateWebhook(updateInput);
|
|
|
|
expect(updateResponse.status).toBe(200);
|
|
expect(updateResponse.body.data).toBeDefined();
|
|
expect(updateResponse.body.errors).toBeUndefined();
|
|
|
|
const updatedWebhookData = updateResponse.body.data.updateWebhook;
|
|
|
|
expect(updatedWebhookData.id).toBe(createdWebhookData.id);
|
|
expect(updatedWebhookData.targetUrl).toBe(updateInput.update.targetUrl);
|
|
expect(updatedWebhookData.operations).toEqual(
|
|
updateInput.update.operations,
|
|
);
|
|
expect(updatedWebhookData.description).toBe(
|
|
updateInput.update.description,
|
|
);
|
|
expect(updatedWebhookData.secret).toBe(updateInput.update.secret);
|
|
});
|
|
});
|
|
|
|
describe('webhook query', () => {
|
|
it('should find a specific webhook', async () => {
|
|
const createResponse = await createWebhook({
|
|
targetUrl: 'https://example.com/webhook',
|
|
operations: ['person.created'],
|
|
description: 'Test webhook',
|
|
secret: 'test-secret',
|
|
});
|
|
|
|
const createdWebhookData = createResponse.body.data.createWebhook;
|
|
|
|
createdWebhookId = createdWebhookData.id;
|
|
|
|
const queryResponse = await getWebhook(createdWebhookData.id);
|
|
|
|
expect(queryResponse.status).toBe(200);
|
|
expect(queryResponse.body.data).toBeDefined();
|
|
expect(queryResponse.body.errors).toBeUndefined();
|
|
|
|
const webhookData = queryResponse.body.data.webhook;
|
|
|
|
expect(webhookData).toBeDefined();
|
|
expect(webhookData.id).toBe(createdWebhookData.id);
|
|
expect(webhookData.targetUrl).toBe(createdWebhookData.targetUrl);
|
|
expect(webhookData.operations).toEqual(createdWebhookData.operations);
|
|
expect(webhookData.description).toBe(createdWebhookData.description);
|
|
expect(webhookData.secret).toBe(createdWebhookData.secret);
|
|
});
|
|
});
|
|
|
|
describe('deleteWebhook mutation', () => {
|
|
it('should delete a webhook successfully', async () => {
|
|
const createResponse = await createWebhook({
|
|
targetUrl: 'https://example.com/webhook',
|
|
operations: ['person.created'],
|
|
description: 'Test webhook',
|
|
secret: 'test-secret',
|
|
});
|
|
|
|
const createdWebhookData = createResponse.body.data.createWebhook;
|
|
|
|
const deleteResponse = await deleteWebhook(createdWebhookData.id);
|
|
|
|
expect(deleteResponse.status).toBe(200);
|
|
expect(deleteResponse.body.data).toBeDefined();
|
|
expect(deleteResponse.body.errors).toBeUndefined();
|
|
|
|
const queryResponse = await getWebhook(createdWebhookData.id);
|
|
|
|
expect(queryResponse.status).toBe(200);
|
|
expect(queryResponse.body.data.webhook).toBeNull();
|
|
|
|
createdWebhookId = undefined;
|
|
});
|
|
});
|
|
|
|
describe('webhook delivery', () => {
|
|
const WEBHOOK_RECEIVER_PORT = 4317;
|
|
|
|
it('should block delivery to private IP when safe mode is enabled (SSRF protection)', async () => {
|
|
const receiver = await createWebhookReceiver(WEBHOOK_RECEIVER_PORT);
|
|
|
|
try {
|
|
const createWebhookResponse = await createWebhook({
|
|
targetUrl: `http://127.0.0.1:${WEBHOOK_RECEIVER_PORT}/webhook`,
|
|
operations: ['person.created'],
|
|
description: 'SSRF test webhook',
|
|
secret: 'test-secret',
|
|
});
|
|
|
|
expect(createWebhookResponse.body.errors).toBeUndefined();
|
|
createdWebhookId = createWebhookResponse.body.data.createWebhook.id;
|
|
|
|
const testId = uuidv4().slice(0, 8);
|
|
const createPersonResponse = await makeGraphqlAPIRequest({
|
|
query: CREATE_PERSON_MUTATION,
|
|
variables: {
|
|
data: {
|
|
name: {
|
|
firstName: 'SSRFTest',
|
|
lastName: `User-${testId}`,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(createPersonResponse.status).toBe(200);
|
|
expect(createPersonResponse.body.errors).toBeUndefined();
|
|
createdPersonId = createPersonResponse.body.data.createPerson.id;
|
|
|
|
jest.useRealTimers();
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
jest.useFakeTimers();
|
|
|
|
expect(receiver.receivedPayloads.length).toBe(0);
|
|
} finally {
|
|
await receiver.close();
|
|
}
|
|
});
|
|
|
|
it('should deliver webhook successfully when internal hosts are allowed', async () => {
|
|
jest.useRealTimers();
|
|
|
|
const receiver = await createWebhookReceiver(WEBHOOK_RECEIVER_PORT);
|
|
|
|
try {
|
|
const createConfigResponse = await makeAdminPanelAPIRequest({
|
|
query: CREATE_CONFIG_VARIABLE_MUTATION,
|
|
variables: {
|
|
key: 'OUTBOUND_HTTP_ALLOWED_INTERNAL_HOSTS',
|
|
value: ['*'],
|
|
},
|
|
});
|
|
|
|
expect(createConfigResponse.body.errors).toBeUndefined();
|
|
expect(
|
|
createConfigResponse.body.data.createDatabaseConfigVariable,
|
|
).toBe(true);
|
|
|
|
const verifyConfig = await makeAdminPanelAPIRequest({
|
|
query: GET_CONFIG_VARIABLE_QUERY,
|
|
variables: { key: 'OUTBOUND_HTTP_ALLOWED_INTERNAL_HOSTS' },
|
|
});
|
|
|
|
expect(verifyConfig.body.data.getDatabaseConfigVariable.value).toEqual([
|
|
'*',
|
|
]);
|
|
expect(verifyConfig.body.data.getDatabaseConfigVariable.source).toBe(
|
|
'DATABASE',
|
|
);
|
|
|
|
const createWebhookResponse = await createWebhook({
|
|
targetUrl: `http://127.0.0.1:${WEBHOOK_RECEIVER_PORT}/webhook`,
|
|
operations: ['person.created'],
|
|
description: 'Delivery test webhook',
|
|
secret: 'test-secret',
|
|
});
|
|
|
|
expect(createWebhookResponse.body.errors).toBeUndefined();
|
|
createdWebhookId = createWebhookResponse.body.data.createWebhook.id;
|
|
|
|
const testId = uuidv4().slice(0, 8);
|
|
const createPersonResponse = await makeGraphqlAPIRequest({
|
|
query: CREATE_PERSON_MUTATION,
|
|
variables: {
|
|
data: {
|
|
name: {
|
|
firstName: 'WebhookDelivery',
|
|
lastName: `Test-${testId}`,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(createPersonResponse.status).toBe(200);
|
|
expect(createPersonResponse.body.errors).toBeUndefined();
|
|
createdPersonId = createPersonResponse.body.data.createPerson.id;
|
|
|
|
// Delivery crosses two BullMQ hops behind a fire-and-forget event
|
|
// emit, so poll the receiver instead of guessing at the latency.
|
|
await expectEventually(
|
|
() => {
|
|
expect(receiver.receivedPayloads.length).toBe(1);
|
|
expect(receiver.receivedPayloads[0]).toMatchObject({
|
|
targetUrl: `http://127.0.0.1:${WEBHOOK_RECEIVER_PORT}/webhook`,
|
|
eventName: 'person.created',
|
|
});
|
|
},
|
|
{ timeoutMs: 30_000, intervalMs: 100 },
|
|
);
|
|
} finally {
|
|
await receiver.close();
|
|
await makeAdminPanelAPIRequest({
|
|
query: DELETE_CONFIG_VARIABLE_MUTATION,
|
|
variables: { key: 'OUTBOUND_HTTP_ALLOWED_INTERNAL_HOSTS' },
|
|
}).catch(() => {});
|
|
jest.useFakeTimers();
|
|
}
|
|
}, 60_000);
|
|
});
|
|
});
|