Compare commits

...

9 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
4592d0881f fix(e2e): regenerate sample.tgz with deterministic gzip header (mtime=0, no FNAME)
Co-authored-by: klboke <18591662+klboke@users.noreply.github.com>
2026-03-09 03:49:31 +00:00
copilot-swe-agent[bot]
45d38310ac Initial plan 2026-03-09 03:46:03 +00:00
kl
b5c95b261d test(e2e): keep legacy zip temp dir ignored 2026-03-09 11:36:37 +08:00
kl
21be47f560 test(e2e): make tgz fixture gzip header deterministic 2026-03-09 11:29:52 +08:00
kl
8dd9b78c48 test(e2e): add rar smoke coverage and align archive deps 2026-03-09 11:19:27 +08:00
kl
4ab383709c test: address copilot archive fixture review feedback 2026-03-09 11:09:52 +08:00
kl
4690a5353b test(e2e): expand archive coverage to tar/tgz/7z/rar 2026-03-09 10:12:48 +08:00
kl
b10e14899d test(e2e): unify E2E CI command and align preview URL encoding (#719)
* test(e2e): follow-up fixes for post-merge copilot review feedback

* test(e2e): guard E2E_MAX_PREVIEW_MS against sub-second values

* test(e2e): align preview URL encoding and docs
2026-03-04 17:39:41 +08:00
kl
eee3a2ed38 test(e2e): follow-up fixes after post-merge copilot findings (#718)
* test(e2e): follow-up fixes for post-merge copilot review feedback

* test(e2e): guard E2E_MAX_PREVIEW_MS against sub-second values
2026-03-04 15:45:04 +08:00
12 changed files with 125 additions and 37 deletions

View File

@@ -36,10 +36,10 @@ jobs:
with:
python-version: '3.11'
- name: Install LibreOffice + zip
- name: Install LibreOffice + archive tools
run: |
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
run: |
@@ -55,10 +55,6 @@ jobs:
npm ci
npx playwright install --with-deps chromium
- name: Generate E2E fixtures
working-directory: tests/e2e
run: npm run gen:all
- name: Start fixture server
run: |
cd tests/e2e/fixtures
@@ -97,20 +93,13 @@ jobs:
exit 1
fi
- name: Run smoke suite
working-directory: tests/e2e
env:
KK_BASE_URL: http://127.0.0.1:8012
FIXTURE_BASE_URL: http://127.0.0.1:18080
run: npm run test:smoke
- name: Run perf suite
- name: Run nightly E2E suites
working-directory: tests/e2e
env:
KK_BASE_URL: http://127.0.0.1:8012
FIXTURE_BASE_URL: http://127.0.0.1:18080
E2E_MAX_PREVIEW_MS: 20000
run: npm run test:perf
run: npm run test:ci
- name: Upload Playwright report
if: always()

View File

@@ -36,10 +36,10 @@ jobs:
with:
python-version: '3.11'
- name: Install LibreOffice + zip
- name: Install LibreOffice + archive tools
run: |
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
run: |

View File

@@ -3,6 +3,7 @@ playwright-report/
test-results/
__pycache__/
fixtures/archive-tmp/
fixtures/zip-tmp/
fixtures/sample.docx
fixtures/sample.xlsx

View File

@@ -6,12 +6,13 @@ 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`
- `/getCorsFile`
- Basic performance smoke checks (configurable threshold): txt/docx/xlsx preview response time
- CI combined run command available via `npm run test:ci`
## Local run
@@ -30,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 `python3`, `zip`, and `7z` (or `bsdtar` as a fallback) are available in PATH for archive fixtures.
3. Generate fixtures and start fixture server:
@@ -62,4 +63,7 @@ npm run test:smoke
# perf smoke (self-contained; default threshold 15000ms)
E2E_MAX_PREVIEW_MS=15000 npm run test:perf
# CI-style combined run (single fixture generation)
E2E_MAX_PREVIEW_MS=20000 npm run test:ci
```

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -13,7 +13,8 @@
"pretest:smoke": "npm run gen:all",
"test:smoke": "playwright test specs/preview-smoke.spec.ts",
"pretest:perf": "npm run gen:all",
"test:perf": "playwright test specs/perf-smoke.spec.ts"
"test:perf": "playwright test specs/perf-smoke.spec.ts",
"test:ci": "npm run gen:all && playwright test specs/preview-smoke.spec.ts specs/perf-smoke.spec.ts"
},
"devDependencies": {
"@playwright/test": "^1.55.0"

View File

@@ -16,20 +16,87 @@ 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');
// archive fixtures (contains inner.txt) - generate if missing
const archiveWork = path.join(fixturesDir, 'archive-tmp');
fs.mkdirSync(archiveWork, { recursive: true });
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;
try {
execFileSync('zip', ['-X', '-q', '-r', zipPath, 'inner.txt'], { cwd: zipWork });
generator(out);
} 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 });
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, gzip
from pathlib import Path
out = Path(r'''${out}''')
inner_path = Path(r'''${innerFile}''')
data = inner_path.read_bytes()
use_gzip = ${gzip ? 'True' : 'False'}
if use_gzip:
with out.open('wb') as f:
with gzip.GzipFile(filename='', mode='wb', fileobj=f, mtime=0) as gz:
with tarfile.open(fileobj=gz, mode='w', 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))
else:
with tarfile.open(out, mode='w', 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 {
ensureArchive('sample.zip', out => {
execFileSync('zip', ['-X', '-q', '-r', out, 'inner.txt'], { cwd: archiveWork });
});
ensureArchive('sample.tar', out => {
buildDeterministicTar(out, false);
});
ensureArchive('sample.tgz', out => {
buildDeterministicTar(out, true);
});
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 python3, 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

View File

@@ -1,16 +1,18 @@
import { test, expect, request as playwrightRequest } from '@playwright/test';
import type { APIRequestContext } from '@playwright/test';
const fixtureBase = process.env.FIXTURE_BASE_URL || 'http://127.0.0.1:18080';
const DEFAULT_MAX_MS = 15000;
const envMaxMs = Number(process.env.E2E_MAX_PREVIEW_MS);
const maxMs = Number.isFinite(envMaxMs) ? envMaxMs : 15000;
const maxMs = Number.isFinite(envMaxMs) && envMaxMs >= 1 ? Math.floor(envMaxMs) : DEFAULT_MAX_MS;
function b64(v: string): string {
return Buffer.from(v).toString('base64');
}
async function timedPreview(request: any, fileUrl: string) {
async function timedPreview(request: APIRequestContext, fileUrl: string) {
const started = Date.now();
const resp = await request.get(`/onlinePreview?url=${b64(fileUrl)}`);
const resp = await request.get(`/onlinePreview?url=${encodeURIComponent(b64(fileUrl))}`);
const elapsed = Date.now() - started;
return { resp, elapsed };
}

View File

@@ -7,7 +7,7 @@ function b64(v: string): string {
}
async function openPreview(request: any, fileUrl: string) {
const encoded = b64(fileUrl);
const encoded = encodeURIComponent(b64(fileUrl));
return request.get(`/onlinePreview?url=${encoded}`);
}
@@ -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();