mirror of
https://github.com/kekingcn/kkFileView.git
synced 2026-03-30 04:33:53 +00:00
test(e2e): expand archive coverage to tar/tgz/7z/rar
This commit is contained in:
4
.github/workflows/nightly-e2e.yml
vendored
4
.github/workflows/nightly-e2e.yml
vendored
@@ -36,10 +36,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
python-version: '3.11'
|
python-version: '3.11'
|
||||||
|
|
||||||
- name: Install LibreOffice + zip
|
- name: Install LibreOffice + archive tools
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y libreoffice zip
|
sudo apt-get install -y libreoffice zip p7zip-full
|
||||||
|
|
||||||
- name: Setup Python deps for office fixtures
|
- name: Setup Python deps for office fixtures
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
4
.github/workflows/pr-e2e-mvp.yml
vendored
4
.github/workflows/pr-e2e-mvp.yml
vendored
@@ -36,10 +36,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
python-version: '3.11'
|
python-version: '3.11'
|
||||||
|
|
||||||
- name: Install LibreOffice + zip
|
- name: Install LibreOffice + archive tools
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y libreoffice zip
|
sudo apt-get install -y libreoffice zip p7zip-full
|
||||||
|
|
||||||
- name: Setup Python deps for office fixtures
|
- name: Setup Python deps for office fixtures
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
2
tests/e2e/.gitignore
vendored
2
tests/e2e/.gitignore
vendored
@@ -3,7 +3,7 @@ playwright-report/
|
|||||||
test-results/
|
test-results/
|
||||||
|
|
||||||
__pycache__/
|
__pycache__/
|
||||||
fixtures/zip-tmp/
|
fixtures/archive-tmp/
|
||||||
fixtures/sample.docx
|
fixtures/sample.docx
|
||||||
fixtures/sample.xlsx
|
fixtures/sample.xlsx
|
||||||
fixtures/sample.pptx
|
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)
|
- Basic preview smoke checks for common file types (txt/md/json/xml/csv/html/png)
|
||||||
- Office Phase-2 smoke checks (docx/xlsx/pptx)
|
- Office Phase-2 smoke checks (docx/xlsx/pptx)
|
||||||
- Archive smoke check (zip)
|
- Archive smoke checks (zip/tar/tgz/7z/rar)
|
||||||
- Basic endpoint reachability
|
- Basic endpoint reachability
|
||||||
- Security regression checks for blocked internal-network hosts (`10.*`) on:
|
- Security regression checks for blocked internal-network hosts (`10.*`) on:
|
||||||
- `/onlinePreview`
|
- `/onlinePreview`
|
||||||
@@ -31,7 +31,7 @@ npx playwright install --with-deps chromium
|
|||||||
pip3 install -r requirements.txt
|
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:
|
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.csv', 'name,value\nkkFileView,1\ne2e,1\n');
|
||||||
write('sample.html', '<!doctype html><html><body><h1>kkFileView fixture</h1></body></html>');
|
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
|
// archive fixtures (contains inner.txt) - generate if missing
|
||||||
const zipPath = path.join(fixturesDir, 'sample.zip');
|
const archiveWork = path.join(fixturesDir, 'archive-tmp');
|
||||||
if (!fs.existsSync(zipPath)) {
|
fs.mkdirSync(archiveWork, { recursive: true });
|
||||||
const zipWork = path.join(fixturesDir, 'zip-tmp');
|
fs.writeFileSync(path.join(archiveWork, 'inner.txt'), 'kkFileView archive inner file');
|
||||||
fs.mkdirSync(zipWork, { recursive: true });
|
|
||||||
fs.writeFileSync(path.join(zipWork, 'inner.txt'), 'kkFileView zip inner file');
|
const ensureArchive = (name, generator) => {
|
||||||
try {
|
const out = path.join(fixturesDir, name);
|
||||||
execFileSync('zip', ['-X', '-q', '-r', zipPath, 'inner.txt'], { cwd: zipWork });
|
if (fs.existsSync(out)) return;
|
||||||
} catch (err) {
|
generator(out);
|
||||||
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 {
|
try {
|
||||||
fs.rmSync(zipWork, { recursive: true, force: true });
|
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
|
// 1x1 png
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ test.beforeAll(async () => {
|
|||||||
'sample.xlsx',
|
'sample.xlsx',
|
||||||
'sample.pptx',
|
'sample.pptx',
|
||||||
'sample.zip',
|
'sample.zip',
|
||||||
|
'sample.tar',
|
||||||
|
'sample.tgz',
|
||||||
|
'sample.7z',
|
||||||
|
'sample.rar',
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -97,13 +101,33 @@ test('12 zip preview', async ({ request }) => {
|
|||||||
expect(resp.status()).toBe(200);
|
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 resp = await openPreview(request, `http://10.1.2.3/a.pdf`);
|
||||||
const body = await resp.text();
|
const body = await resp.text();
|
||||||
expect(body).toContain('不受信任');
|
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 encoded = b64('http://10.1.2.3/a.pdf');
|
||||||
const resp = await request.get(`/getCorsFile?urlPath=${encoded}`);
|
const resp = await request.get(`/getCorsFile?urlPath=${encoded}`);
|
||||||
const body = await resp.text();
|
const body = await resp.text();
|
||||||
|
|||||||
Reference in New Issue
Block a user