test: address copilot archive fixture review feedback

This commit is contained in:
kl
2026-03-09 11:09:52 +08:00
parent 4690a5353b
commit 4ab383709c
6 changed files with 36 additions and 11 deletions

View File

@@ -6,7 +6,7 @@ This folder contains a first MVP of end-to-end automated tests.
- Basic preview smoke checks for common file types (txt/md/json/xml/csv/html/png)
- Office Phase-2 smoke checks (docx/xlsx/pptx)
- Archive smoke checks (zip/tar/tgz/7z/rar)
- Archive smoke checks (zip/tar/tgz/7z)
- Basic endpoint reachability
- Security regression checks for blocked internal-network hosts (`10.*`) on:
- `/onlinePreview`

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -19,12 +19,43 @@ write('sample.html', '<!doctype html><html><body><h1>kkFileView fixture</h1></bo
// archive fixtures (contains inner.txt) - generate if missing
const archiveWork = path.join(fixturesDir, 'archive-tmp');
fs.mkdirSync(archiveWork, { recursive: true });
fs.writeFileSync(path.join(archiveWork, 'inner.txt'), 'kkFileView archive inner file');
const innerFile = path.join(archiveWork, 'inner.txt');
fs.writeFileSync(innerFile, 'kkFileView archive inner file');
const ensureArchive = (name, generator) => {
const out = path.join(fixturesDir, name);
if (fs.existsSync(out)) return;
generator(out);
try {
generator(out);
} catch (err) {
try {
fs.rmSync(out, { force: true });
} catch {
// ignore cleanup errors; original error will be rethrown
}
throw err;
}
};
const buildDeterministicTar = (out, gzip = false) => {
const py = String.raw`import io, tarfile
from pathlib import Path
out = Path(r'''${out}''')
inner_path = Path(r'''${innerFile}''')
data = inner_path.read_bytes()
mode = 'w:gz' if ${gzip ? 'True' : 'False'} else 'w'
with tarfile.open(out, mode=mode, format=tarfile.USTAR_FORMAT) as tf:
info = tarfile.TarInfo('inner.txt')
info.size = len(data)
info.mtime = 946684800 # 2000-01-01 00:00:00 UTC
info.uid = 0
info.gid = 0
info.uname = 'root'
info.gname = 'root'
tf.addfile(info, io.BytesIO(data))
`;
execFileSync('python3', ['-c', py]);
};
try {
@@ -33,11 +64,11 @@ try {
});
ensureArchive('sample.tar', out => {
execFileSync('tar', ['-cf', out, 'inner.txt'], { cwd: archiveWork });
buildDeterministicTar(out, false);
});
ensureArchive('sample.tgz', out => {
execFileSync('tar', ['-czf', out, 'inner.txt'], { cwd: archiveWork });
buildDeterministicTar(out, true);
});
ensureArchive('sample.7z', out => {

View File

@@ -28,7 +28,6 @@ test.beforeAll(async () => {
'sample.tar',
'sample.tgz',
'sample.7z',
'sample.rar',
];
try {
@@ -116,11 +115,6 @@ test('15 7z preview', async ({ request }) => {
expect(resp.status()).toBe(200);
});
test('16 rar preview', async ({ request }) => {
const resp = await openPreview(request, `${fixtureBase}/sample.rar`);
expect(resp.status()).toBe(200);
});
test('17 security: block 10.x host in onlinePreview', async ({ request }) => {
const resp = await openPreview(request, `http://10.1.2.3/a.pdf`);
const body = await resp.text();