mirror of
https://github.com/kekingcn/kkFileView.git
synced 2026-03-30 04:53:33 +00:00
test: address copilot archive fixture review feedback
This commit is contained in:
@@ -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 checks (zip/tar/tgz/7z/rar)
|
- Archive smoke checks (zip/tar/tgz/7z)
|
||||||
- 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`
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -19,12 +19,43 @@ write('sample.html', '<!doctype html><html><body><h1>kkFileView fixture</h1></bo
|
|||||||
// archive fixtures (contains inner.txt) - generate if missing
|
// archive fixtures (contains inner.txt) - generate if missing
|
||||||
const archiveWork = path.join(fixturesDir, 'archive-tmp');
|
const archiveWork = path.join(fixturesDir, 'archive-tmp');
|
||||||
fs.mkdirSync(archiveWork, { recursive: true });
|
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 ensureArchive = (name, generator) => {
|
||||||
const out = path.join(fixturesDir, name);
|
const out = path.join(fixturesDir, name);
|
||||||
if (fs.existsSync(out)) return;
|
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 {
|
try {
|
||||||
@@ -33,11 +64,11 @@ try {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ensureArchive('sample.tar', out => {
|
ensureArchive('sample.tar', out => {
|
||||||
execFileSync('tar', ['-cf', out, 'inner.txt'], { cwd: archiveWork });
|
buildDeterministicTar(out, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
ensureArchive('sample.tgz', out => {
|
ensureArchive('sample.tgz', out => {
|
||||||
execFileSync('tar', ['-czf', out, 'inner.txt'], { cwd: archiveWork });
|
buildDeterministicTar(out, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
ensureArchive('sample.7z', out => {
|
ensureArchive('sample.7z', out => {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ test.beforeAll(async () => {
|
|||||||
'sample.tar',
|
'sample.tar',
|
||||||
'sample.tgz',
|
'sample.tgz',
|
||||||
'sample.7z',
|
'sample.7z',
|
||||||
'sample.rar',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -116,11 +115,6 @@ test('15 7z preview', async ({ request }) => {
|
|||||||
expect(resp.status()).toBe(200);
|
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 }) => {
|
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();
|
||||||
|
|||||||
Reference in New Issue
Block a user