0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
CI / Shell Format Check (push) Waiting to run
CI / Check Ruby (3.4) (push) Waiting to run
CI / CI Config (push) Waiting to run
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Blocked by required conditions
CI / Build on Node ${{ matrix.node }} (push) Blocked by required conditions
CI / Style Check (push) Waiting to run
CI / Generate Assets (push) Waiting to run
CI / Check Python (3.14) (push) Waiting to run
CI / Check Python (3.9) (push) Waiting to run
CI / Build Docs (push) Waiting to run
CI / Code Scan Action (push) Waiting to run
CI / Site tests (push) Waiting to run
CI / webui tests (push) Waiting to run
CI / Run Integration Tests (push) Waiting to run
CI / Run Smoke Tests (push) Waiting to run
CI / Go Tests (push) Waiting to run
CI / Share Test (push) Waiting to run
CI / Redteam (Production API) (push) Waiting to run
CI / Redteam (Staging API) (push) Waiting to run
CI / GitHub Actions Lint (push) Waiting to run
CI / Check Ruby (3.0) (push) Waiting to run
release-please / release-please (push) Waiting to run
release-please / build (push) Blocked by required conditions
release-please / publish-npm (push) Blocked by required conditions
release-please / publish-npm-backfill (push) Waiting to run
release-please / docker (push) Blocked by required conditions
release-please / publish-code-scan-action (push) Blocked by required conditions
release-please / attest-code-scan-action (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
import fs from 'fs/promises';
|
|
import path from 'path';
|
|
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
import {
|
|
createSecureTempDirectory,
|
|
removeSecureTempDirectory,
|
|
writeSecureTempFile,
|
|
} from '../../src/util/secureTempFiles';
|
|
|
|
describe('secure temporary files', () => {
|
|
let tempDirectory: string | undefined;
|
|
|
|
afterEach(async () => {
|
|
if (tempDirectory) {
|
|
await removeSecureTempDirectory(tempDirectory);
|
|
tempDirectory = undefined;
|
|
}
|
|
});
|
|
|
|
it('creates private directories and exclusively writes restricted files', async () => {
|
|
tempDirectory = await createSecureTempDirectory('promptfoo-secure-temp-test-');
|
|
const filePath = await writeSecureTempFile(tempDirectory, 'payload.json', '{"ok":true}');
|
|
|
|
if (process.platform !== 'win32') {
|
|
expect((await fs.stat(tempDirectory)).mode & 0o777).toBe(0o700);
|
|
expect((await fs.stat(filePath)).mode & 0o777).toBe(0o600);
|
|
}
|
|
|
|
await expect(
|
|
writeSecureTempFile(tempDirectory, 'payload.json', 'replacement'),
|
|
).rejects.toMatchObject({ code: 'EEXIST' });
|
|
});
|
|
|
|
it('rejects filenames that are not simple leaf names', async () => {
|
|
tempDirectory = await createSecureTempDirectory('promptfoo-secure-temp-test-');
|
|
|
|
for (const filename of ['../payload.json', path.resolve('payload.json'), '.', '..', '']) {
|
|
await expect(writeSecureTempFile(tempDirectory, filename, 'data')).rejects.toThrow(
|
|
'Secure temporary file names must be simple leaf names',
|
|
);
|
|
}
|
|
});
|
|
|
|
it('rejects directory prefixes that are not simple leaf names', async () => {
|
|
for (const prefix of ['../promptfoo-', path.resolve('promptfoo-'), '.', '..', '']) {
|
|
await expect(createSecureTempDirectory(prefix)).rejects.toThrow(
|
|
'Secure temporary directory prefixes must be simple leaf names',
|
|
);
|
|
}
|
|
});
|
|
|
|
it('removes the temporary directory recursively', async () => {
|
|
tempDirectory = await createSecureTempDirectory('promptfoo-secure-temp-test-');
|
|
await writeSecureTempFile(tempDirectory, 'payload.json', 'data');
|
|
|
|
await removeSecureTempDirectory(tempDirectory);
|
|
await expect(fs.access(tempDirectory)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
tempDirectory = undefined;
|
|
});
|
|
});
|