Files
upstream-twenty/packages/twenty-server/test/integration/upgrade/suites/2-15-instance-command-slow-1781461753981-backfill-connection-security.integration-spec.ts
upstream-mirror e7da97194a
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
snapshot of https://github.com/twentyhq/twenty.git (main, 2026-09-17; blobs > 131072B omitted)
2026-09-17 23:28:13 +05:00

190 lines
5.3 KiB
TypeScript

import { config } from 'dotenv';
import { isDefined } from 'twenty-shared/utils';
import { DataSource } from 'typeorm';
import { BackfillConnectionSecuritySlowInstanceCommand } from 'src/database/commands/upgrade-version-command/2-15/2-15-instance-command-slow-1781461753981-backfill-connection-security';
jest.useRealTimers();
config({
path: process.env.NODE_ENV === 'test' ? '.env.test' : '.env',
override: true,
});
const TEST_ROW_HANDLE_PREFIX = 'backfill-connection-security-test-';
describe('BackfillConnectionSecuritySlowInstanceCommand (integration)', () => {
let dataSource: DataSource;
let command: BackfillConnectionSecuritySlowInstanceCommand;
let workspaceId: string;
let userWorkspaceId: string;
const seededRowIds: string[] = [];
const seedAccount = async (
connectionParameters: Record<string, unknown>,
): Promise<string> => {
const [row] = await dataSource.query(
`INSERT INTO "core"."connectedAccount"
("handle", "provider", "userWorkspaceId", "workspaceId", "visibility", "connectionParameters")
VALUES ($1, 'imap_smtp_caldav', $2, $3, 'user', $4)
RETURNING id`,
[
`${TEST_ROW_HANDLE_PREFIX}${seededRowIds.length}`,
userWorkspaceId,
workspaceId,
JSON.stringify(connectionParameters),
],
);
seededRowIds.push(row.id as string);
return row.id as string;
};
const getConnectionParameters = async (
id: string,
): Promise<Record<string, Record<string, unknown>>> => {
const [row] = await dataSource.query(
`SELECT "connectionParameters" FROM "core"."connectedAccount" WHERE id = $1`,
[id],
);
return row.connectionParameters;
};
beforeAll(async () => {
dataSource = new DataSource({
type: 'postgres',
url: process.env.PG_DATABASE_URL,
schema: 'core',
entities: [],
synchronize: false,
});
await dataSource.initialize();
command = new BackfillConnectionSecuritySlowInstanceCommand();
const [seedWorkspaceRow] = await dataSource.query(
`SELECT uw.id AS "userWorkspaceId", uw."workspaceId" AS "workspaceId"
FROM "core"."userWorkspace" uw
LIMIT 1`,
);
if (!isDefined(seedWorkspaceRow)) {
throw new Error(
'No seeded userWorkspace row found; run database:reset before the integration suite.',
);
}
userWorkspaceId = seedWorkspaceRow.userWorkspaceId;
workspaceId = seedWorkspaceRow.workspaceId;
}, 30000);
afterEach(async () => {
if (seededRowIds.length > 0) {
await dataSource.query(
`DELETE FROM "core"."connectedAccount" WHERE id = ANY($1::uuid[])`,
[seededRowIds],
);
seededRowIds.length = 0;
}
});
afterAll(async () => {
await dataSource?.destroy();
});
it('maps every legacy protocol to the mode matching its prior on-wire behavior and drops the secure key', async () => {
const id = await seedAccount({
IMAP: {
host: 'imap.example.com',
port: 993,
secure: true,
password: 'enc:v2:x',
},
SMTP: {
host: 'smtp.example.com',
port: 587,
secure: true,
password: 'enc:v2:x',
},
CALDAV: {
host: 'https://dav.example.com',
port: 443,
secure: true,
password: 'enc:v2:x',
},
});
await command.runDataMigration(dataSource);
const params = await getConnectionParameters(id);
expect(params.IMAP.connectionSecurity).toBe('SSL_TLS');
expect(params.SMTP.connectionSecurity).toBe('STARTTLS');
expect(params.CALDAV.connectionSecurity).toBe('SSL_TLS');
expect(params.IMAP.secure).toBeUndefined();
expect(params.SMTP.secure).toBeUndefined();
expect(params.CALDAV.secure).toBeUndefined();
});
it('maps implicit-TLS SMTP (port 465) and opportunistic IMAP (secure:false) correctly', async () => {
const implicitSmtpId = await seedAccount({
SMTP: {
host: 'smtp.example.com',
port: 465,
secure: true,
password: 'enc:v2:x',
},
});
const plaintextImapId = await seedAccount({
IMAP: {
host: 'imap.example.com',
port: 143,
secure: false,
password: 'enc:v2:x',
},
});
await command.runDataMigration(dataSource);
expect(
(await getConnectionParameters(implicitSmtpId)).SMTP.connectionSecurity,
).toBe('SSL_TLS');
expect(
(await getConnectionParameters(plaintextImapId)).IMAP.connectionSecurity,
).toBe('STARTTLS');
});
it('is idempotent and leaves already-migrated accounts untouched', async () => {
const legacyId = await seedAccount({
SMTP: {
host: 'smtp.example.com',
port: 587,
secure: true,
password: 'enc:v2:x',
},
});
const alreadyMigratedId = await seedAccount({
SMTP: {
host: 'smtp.example.com',
port: 465,
connectionSecurity: 'STARTTLS',
password: 'enc:v2:x',
},
});
await command.runDataMigration(dataSource);
await command.runDataMigration(dataSource);
expect(
(await getConnectionParameters(legacyId)).SMTP.connectionSecurity,
).toBe('STARTTLS');
// A pre-set connectionSecurity is never overwritten, even when it disagrees with the port.
expect(
(await getConnectionParameters(alreadyMigratedId)).SMTP
.connectionSecurity,
).toBe('STARTTLS');
});
});