Files
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

389 lines
11 KiB
TypeScript

import crypto from 'crypto';
import { promises as fs } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
import request from 'supertest';
import * as tar from 'tar';
import { type DataSource } from 'typeorm';
import { uploadAppTarball } from 'test/integration/metadata/suites/application/utils/upload-app-tarball.util';
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
const TEST_WORKSPACE_ID = SEED_APPLE_WORKSPACE_ID;
const createTestTarball = async (
files: Record<string, string>,
): Promise<Buffer> => {
const tempId = crypto.randomUUID();
const sourceDir = join(tmpdir(), `test-tarball-src-${tempId}`);
const tarballPath = join(tmpdir(), `test-tarball-${tempId}.tar.gz`);
await fs.mkdir(sourceDir, { recursive: true });
for (const [name, content] of Object.entries(files)) {
const filePath = join(sourceDir, name);
const dir = filePath.substring(0, filePath.lastIndexOf('/'));
if (dir !== sourceDir) {
await fs.mkdir(dir, { recursive: true });
}
await fs.writeFile(filePath, content);
}
await tar.create(
{
file: tarballPath,
gzip: true,
cwd: sourceDir,
},
Object.keys(files),
);
const buffer = await fs.readFile(tarballPath);
await fs.rm(sourceDir, { recursive: true, force: true });
await fs.rm(tarballPath, { force: true });
return buffer;
};
const createValidManifest = (universalIdentifier: string) =>
JSON.stringify({
application: {
universalIdentifier,
displayName: 'Test Tarball App',
description: 'A test app',
icon: 'IconTestPipe',
defaultRoleUniversalIdentifier: crypto.randomUUID(),
applicationVariables: {},
packageJsonChecksum: null,
yarnLockChecksum: null,
},
roles: [],
skills: [],
objects: [],
fields: [],
logicFunctions: [],
frontComponents: [],
publicAssets: [],
views: [],
navigationMenuItems: [],
pageLayouts: [],
pageLayoutTabs: [],
pageLayoutWidgets: [],
});
const insertRegistrationWithSource = async (
ds: DataSource,
params: {
universalIdentifier: string;
name: string;
sourceType: 'npm' | 'tarball' | 'local';
sourcePackage?: string;
},
): Promise<string> => {
const id = crypto.randomUUID();
const oAuthClientId = crypto.randomUUID();
await ds.query(
`INSERT INTO core."applicationRegistration"
(id, "universalIdentifier", name, "oAuthClientId",
"oAuthRedirectUris", "oAuthScopes", "workspaceId",
"sourceType", "sourcePackage")
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
[
id,
params.universalIdentifier,
params.name,
oAuthClientId,
[],
[],
TEST_WORKSPACE_ID,
params.sourceType,
params.sourcePackage ?? null,
],
);
return id;
};
describe('App Distribution (integration)', () => {
let ds: DataSource;
const createdRegistrationIds: string[] = [];
beforeAll(() => {
jest.useRealTimers();
ds = global.testDataSource;
});
afterAll(async () => {
for (const id of createdRegistrationIds) {
await ds.query(
`DELETE FROM core."applicationRegistration" WHERE id = $1`,
[id],
);
}
jest.useFakeTimers();
});
describe('Upload tarball via GraphQL', () => {
it('should reject tarball without manifest.json', async () => {
const tarball = await createTestTarball({
'readme.txt': 'no manifest here',
});
const { errors } = await uploadAppTarball({
tarballBuffer: tarball,
expectToFail: true,
});
expect(errors).toBeDefined();
expect(
errors?.some((error: { message: string }) =>
error.message.includes('manifest.json'),
),
).toBe(true);
});
it('should successfully upload a valid tarball and create registration', async () => {
const uid = crypto.randomUUID();
const manifest = createValidManifest(uid);
const tarball = await createTestTarball({
'manifest.json': manifest,
'package.json': JSON.stringify({
name: 'test-app',
version: '1.0.0',
}),
});
const { data, errors } = await uploadAppTarball({
tarballBuffer: tarball,
universalIdentifier: uid,
});
expect(errors).toBeUndefined();
expect(data?.uploadAppTarball.id).toBeDefined();
expect(data?.uploadAppTarball.universalIdentifier).toBe(uid);
createdRegistrationIds.push(data!.uploadAppTarball.id);
const rows = await ds.query(
`SELECT "sourceType" FROM core."applicationRegistration"
WHERE id = $1`,
[data!.uploadAppTarball.id],
);
expect(rows[0].sourceType).toBe('tarball');
});
it('should reject a tarball whose manifest identifier is not a valid UUID', async () => {
const tarball = await createTestTarball({
'manifest.json': createValidManifest('not-a-uuid'),
'package.json': JSON.stringify({ name: 'test-app', version: '1.0.0' }),
});
const { errors } = await uploadAppTarball({
tarballBuffer: tarball,
expectToFail: true,
});
expect(errors).toBeDefined();
});
it('should reject a tarball whose manifest has no application identifier', async () => {
const tarball = await createTestTarball({
'manifest.json': JSON.stringify({
application: {
displayName: 'App Without Identifier',
description: 'A test app',
applicationVariables: {},
packageJsonChecksum: null,
yarnLockChecksum: null,
},
}),
'package.json': JSON.stringify({ name: 'test-app', version: '1.0.0' }),
});
const { errors } = await uploadAppTarball({
tarballBuffer: tarball,
expectToFail: true,
});
expect(errors).toBeDefined();
});
it('should fail to update existing version', async () => {
const uid = crypto.randomUUID();
const manifest = createValidManifest(uid);
const tarball = await createTestTarball({
'manifest.json': manifest,
'package.json': JSON.stringify({
name: 'test-app',
version: '1.0.0',
}),
});
const firstResult = await uploadAppTarball({
tarballBuffer: tarball,
universalIdentifier: uid,
});
createdRegistrationIds.push(firstResult.data!.uploadAppTarball.id);
const { errors } = await uploadAppTarball({
tarballBuffer: tarball,
universalIdentifier: uid,
expectToFail: true,
});
expect(errors).toBeDefined();
expect(
errors?.some((error: { message: string }) =>
error.message.includes(
'version must be higher than the currently deployed version',
),
),
).toBe(true);
});
it('should update existing tarball registration on re-upload', async () => {
const uid = crypto.randomUUID();
const manifest = createValidManifest(uid);
const firstTarball = await createTestTarball({
'manifest.json': manifest,
'package.json': JSON.stringify({
name: 'test-app',
version: '1.1.0',
}),
});
const firstResult = await uploadAppTarball({
tarballBuffer: firstTarball,
universalIdentifier: uid,
});
createdRegistrationIds.push(firstResult.data!.uploadAppTarball.id);
const secondTarball = await createTestTarball({
'manifest.json': manifest,
'package.json': JSON.stringify({
name: 'test-app',
version: '1.2.0',
}),
});
const secondResult = await uploadAppTarball({
tarballBuffer: secondTarball,
universalIdentifier: uid,
});
expect(secondResult.data?.uploadAppTarball.id).toBe(
firstResult.data?.uploadAppTarball.id,
);
});
});
describe('Source channel enforcement', () => {
it('should reject tarball upload for npm-sourced registration', async () => {
const uid = crypto.randomUUID();
const regId = await insertRegistrationWithSource(ds, {
universalIdentifier: uid,
name: 'NPM App',
sourceType: 'npm',
sourcePackage: '@test/npm-app',
});
createdRegistrationIds.push(regId);
const manifest = createValidManifest(uid);
const tarball = await createTestTarball({
'manifest.json': manifest,
'package.json': JSON.stringify({
name: 'test-app',
version: '1.0.0',
}),
});
const { errors } = await uploadAppTarball({
tarballBuffer: tarball,
universalIdentifier: uid,
expectToFail: true,
});
expect(errors).toBeDefined();
expect(
errors?.some((error: { message: string }) =>
error.message.includes('registered as npm'),
),
).toBe(true);
});
it('should allow tarball upload for local-sourced registration', async () => {
const uid = crypto.randomUUID();
const regId = await insertRegistrationWithSource(ds, {
universalIdentifier: uid,
name: 'Local Source App',
sourceType: 'local',
});
createdRegistrationIds.push(regId);
const manifest = createValidManifest(uid);
const tarball = await createTestTarball({
'manifest.json': manifest,
'package.json': JSON.stringify({
name: 'test-app',
version: '1.0.0',
}),
});
const { data, errors } = await uploadAppTarball({
tarballBuffer: tarball,
universalIdentifier: uid,
});
expect(errors).toBeUndefined();
expect(data?.uploadAppTarball.id).toBe(regId);
const rows = await ds.query(
`SELECT "sourceType" FROM core."applicationRegistration"
WHERE id = $1`,
[regId],
);
expect(rows[0].sourceType).toBe('tarball');
});
});
describe('Authentication', () => {
it('should reject unauthenticated requests', async () => {
const baseUrl = `http://localhost:${APP_PORT}`;
const response = await request(baseUrl)
.post('/metadata')
.field(
'operations',
JSON.stringify({
query: `mutation UploadAppTarball($file: Upload!) {
uploadAppTarball(file: $file) { id }
}`,
variables: { file: null },
}),
)
.field('map', JSON.stringify({ '0': ['variables.file'] }))
.attach('0', Buffer.from('test'), {
filename: 'app.tar.gz',
contentType: 'application/gzip',
});
expect(response.body.errors).toBeDefined();
});
});
});