mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-03-14 05:03:49 +08:00
test(e2e): expand archive coverage to tar/tgz/7z/rar
This commit is contained in:
2
tests/e2e/.gitignore
vendored
2
tests/e2e/.gitignore
vendored
@@ -3,7 +3,7 @@ playwright-report/
|
||||
test-results/
|
||||
|
||||
__pycache__/
|
||||
fixtures/zip-tmp/
|
||||
fixtures/archive-tmp/
|
||||
fixtures/sample.docx
|
||||
fixtures/sample.xlsx
|
||||
fixtures/sample.pptx
|
||||
|
||||
@@ -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 check (zip)
|
||||
- Archive smoke checks (zip/tar/tgz/7z/rar)
|
||||
- Basic endpoint reachability
|
||||
- Security regression checks for blocked internal-network hosts (`10.*`) on:
|
||||
- `/onlinePreview`
|
||||
@@ -31,7 +31,7 @@ npx playwright install --with-deps chromium
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
> Prerequisite: ensure `zip` command is available in PATH (used for `sample.zip` fixture generation).
|
||||
> Prerequisite: ensure `zip`, `tar`, and `7z` (or `bsdtar` fallback) are available in PATH for archive fixtures.
|
||||
|
||||
3. Generate fixtures and start fixture server:
|
||||
|
||||
|
||||
BIN
tests/e2e/fixtures/sample.7z
Normal file
BIN
tests/e2e/fixtures/sample.7z
Normal file
Binary file not shown.
1
tests/e2e/fixtures/sample.rar
Normal file
1
tests/e2e/fixtures/sample.rar
Normal file
@@ -0,0 +1 @@
|
||||
Rar!u{1a}u{7}u{0}
|
||||
BIN
tests/e2e/fixtures/sample.tar
Normal file
BIN
tests/e2e/fixtures/sample.tar
Normal file
Binary file not shown.
BIN
tests/e2e/fixtures/sample.tgz
Normal file
BIN
tests/e2e/fixtures/sample.tgz
Normal file
Binary file not shown.
@@ -16,20 +16,42 @@ write('sample.xml', '<root><name>kkFileView</name><e2e>true</e2e></root>');
|
||||
write('sample.csv', 'name,value\nkkFileView,1\ne2e,1\n');
|
||||
write('sample.html', '<!doctype html><html><body><h1>kkFileView fixture</h1></body></html>');
|
||||
|
||||
// zip (contains txt) - only generate if missing to avoid noisy local diffs
|
||||
const zipPath = path.join(fixturesDir, 'sample.zip');
|
||||
if (!fs.existsSync(zipPath)) {
|
||||
const zipWork = path.join(fixturesDir, 'zip-tmp');
|
||||
fs.mkdirSync(zipWork, { recursive: true });
|
||||
fs.writeFileSync(path.join(zipWork, 'inner.txt'), 'kkFileView zip inner file');
|
||||
try {
|
||||
execFileSync('zip', ['-X', '-q', '-r', zipPath, 'inner.txt'], { cwd: zipWork });
|
||||
} catch (err) {
|
||||
console.error('Failed to create sample.zip fixture. Ensure "zip" is installed and available in PATH.');
|
||||
throw err instanceof Error ? err : new Error(String(err));
|
||||
} finally {
|
||||
fs.rmSync(zipWork, { recursive: true, force: true });
|
||||
}
|
||||
// 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 ensureArchive = (name, generator) => {
|
||||
const out = path.join(fixturesDir, name);
|
||||
if (fs.existsSync(out)) return;
|
||||
generator(out);
|
||||
};
|
||||
|
||||
try {
|
||||
ensureArchive('sample.zip', out => {
|
||||
execFileSync('zip', ['-X', '-q', '-r', out, 'inner.txt'], { cwd: archiveWork });
|
||||
});
|
||||
|
||||
ensureArchive('sample.tar', out => {
|
||||
execFileSync('tar', ['-cf', out, 'inner.txt'], { cwd: archiveWork });
|
||||
});
|
||||
|
||||
ensureArchive('sample.tgz', out => {
|
||||
execFileSync('tar', ['-czf', out, 'inner.txt'], { cwd: archiveWork });
|
||||
});
|
||||
|
||||
ensureArchive('sample.7z', out => {
|
||||
try {
|
||||
execFileSync('7z', ['a', '-bd', '-y', out, 'inner.txt'], { cwd: archiveWork, stdio: 'ignore' });
|
||||
} catch {
|
||||
execFileSync('bsdtar', ['-a', '-cf', out, 'inner.txt'], { cwd: archiveWork });
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to create archive fixtures. Ensure tar/zip/7z (or bsdtar) are available in PATH.');
|
||||
throw err instanceof Error ? err : new Error(String(err));
|
||||
} finally {
|
||||
fs.rmSync(archiveWork, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
// 1x1 png
|
||||
|
||||
@@ -25,6 +25,10 @@ test.beforeAll(async () => {
|
||||
'sample.xlsx',
|
||||
'sample.pptx',
|
||||
'sample.zip',
|
||||
'sample.tar',
|
||||
'sample.tgz',
|
||||
'sample.7z',
|
||||
'sample.rar',
|
||||
];
|
||||
|
||||
try {
|
||||
@@ -97,13 +101,33 @@ test('12 zip preview', async ({ request }) => {
|
||||
expect(resp.status()).toBe(200);
|
||||
});
|
||||
|
||||
test('13 security: block 10.x host in onlinePreview', async ({ request }) => {
|
||||
test('13 tar preview', async ({ request }) => {
|
||||
const resp = await openPreview(request, `${fixtureBase}/sample.tar`);
|
||||
expect(resp.status()).toBe(200);
|
||||
});
|
||||
|
||||
test('14 tgz preview', async ({ request }) => {
|
||||
const resp = await openPreview(request, `${fixtureBase}/sample.tgz`);
|
||||
expect(resp.status()).toBe(200);
|
||||
});
|
||||
|
||||
test('15 7z preview', async ({ request }) => {
|
||||
const resp = await openPreview(request, `${fixtureBase}/sample.7z`);
|
||||
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();
|
||||
expect(body).toContain('不受信任');
|
||||
});
|
||||
|
||||
test('14 security: block 10.x host in getCorsFile', async ({ request }) => {
|
||||
test('18 security: block 10.x host in getCorsFile', async ({ request }) => {
|
||||
const encoded = b64('http://10.1.2.3/a.pdf');
|
||||
const resp = await request.get(`/getCorsFile?urlPath=${encoded}`);
|
||||
const body = await resp.text();
|
||||
|
||||
Reference in New Issue
Block a user