open-design/apps/daemon/tests/project-plugin-manifest.test.ts
999axel999 db90cb0bdb
fix(daemon): reject unsafe plugin manifest names (#2757)
Co-authored-by: Zerocracy Assistant <zerocracy-assistant@example.com>
2026-05-23 12:53:39 +08:00

33 lines
1.2 KiB
TypeScript

import { mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { __forTestReadProjectPluginManifest } from '../src/server.js';
describe('readProjectPluginManifest', () => {
async function withManifest(name: string, fn: (folder: string) => Promise<void>) {
const folder = await mkdtemp(path.join(tmpdir(), 'od-plugin-manifest-'));
try {
await writeFile(path.join(folder, 'open-design.json'), JSON.stringify({ name }), 'utf8');
await fn(folder);
} finally {
await rm(folder, { recursive: true, force: true });
}
}
it.each(['../evil', '..\\\\evil', '.', '..'])('rejects unsafe manifest name %s', async (name) => {
await withManifest(name, async (folder) => {
await expect(__forTestReadProjectPluginManifest(folder)).rejects.toThrow(
/must not contain path separators or consist only of dots/,
);
});
});
it('allows ordinary plugin names with dots', async () => {
await withManifest('my-plugin.v2', async (folder) => {
await expect(__forTestReadProjectPluginManifest(folder)).resolves.toMatchObject({
name: 'my-plugin.v2',
});
});
});
});