Hardens the upload path check and the deploy verification
A remote of . or .. could have made the cleanup pass delete the wrong folder, so such paths are refused before anything runs. A connection error now ends in the normal summary instead of aborting the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
} from 'node:http';
|
||||
import type { AddressInfo } from 'node:net';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { basename, delimiter, dirname, join, resolve } from 'node:path';
|
||||
import { gzipSync } from 'node:zlib';
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||
import { startPreviewServer } from '../config/previewServer.ts';
|
||||
@@ -81,12 +81,17 @@ function runScript(
|
||||
script: string,
|
||||
args: string[],
|
||||
env: Record<string, string> = {},
|
||||
cwd?: string,
|
||||
): Promise<Run> {
|
||||
return new Promise((done) => {
|
||||
execFile(
|
||||
bashBin ?? 'bash',
|
||||
[`${deployDir}/${script}`, ...args],
|
||||
{ env: { ...process.env, ...env }, maxBuffer: 16 * 1024 * 1024 },
|
||||
{
|
||||
cwd,
|
||||
env: { ...process.env, ...env },
|
||||
maxBuffer: 16 * 1024 * 1024,
|
||||
},
|
||||
(error, stdout, stderr) =>
|
||||
done({
|
||||
code: error ? Number(error.code ?? 1) : 0,
|
||||
@@ -195,6 +200,8 @@ interface StubOptions {
|
||||
omitHeader?: string;
|
||||
gzip?: boolean;
|
||||
robots?: boolean;
|
||||
// Pad waarvan de verbinding wordt verbroken, zonder antwoord
|
||||
drop?: string;
|
||||
}
|
||||
|
||||
async function startStub(
|
||||
@@ -240,6 +247,10 @@ async function startStub(
|
||||
|
||||
const server: Server = createServer((request, response) => {
|
||||
const path = (request.url ?? '/').split('?')[0];
|
||||
if (path === options.drop) {
|
||||
request.socket.destroy();
|
||||
return;
|
||||
}
|
||||
void (async () => {
|
||||
if (options.behaviour === 'old') {
|
||||
// Oude nginx: bestaand bestand, anders de homepage met 200
|
||||
@@ -418,6 +429,23 @@ describe.skipIf(toolsMissing)('verify-deployment.sh', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('telt een verbroken verbinding als fout en eindigt met de samenvatting', async () => {
|
||||
await withStub(
|
||||
{ behaviour: 'new', drop: '/over-mij' },
|
||||
async (origin) => {
|
||||
const run = await runScript('verify-deployment.sh', [
|
||||
origin,
|
||||
dist,
|
||||
]);
|
||||
expect(run.code).toBe(1);
|
||||
expect(run.stderr).toContain(
|
||||
'/over-mij: geen antwoord van de server',
|
||||
);
|
||||
expect(run.stderr).toContain('Controle mislukt');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it.each(['', 'ftp://example.nl', 'http://a b', 'example.nl'])(
|
||||
'weigert de ongeldige URL %j',
|
||||
async (url) => {
|
||||
@@ -529,3 +557,89 @@ describe.skipIf(toolsMissing || lftpMissing)('upload-production.sh', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// Pad-controle van upload-production.sh: een nep-lftp laat zien of er iets
|
||||
// gestart is. Ronde 3 verwijdert, dus '.' of '..' als doel mag nooit door.
|
||||
describe.skipIf(toolsMissing)('upload-production.sh (padcontrole)', () => {
|
||||
async function withFakeLftp<T>(
|
||||
action: (env: Record<string, string>, marker: string) => Promise<T>,
|
||||
) {
|
||||
const bin = await makeTemp('andreaslop-fakebin-');
|
||||
const marker = join(bin, 'gestart');
|
||||
await writeFile(
|
||||
join(bin, 'lftp'),
|
||||
`#!/bin/sh
|
||||
touch '${slash(marker)}'
|
||||
`,
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
return action(
|
||||
{
|
||||
PATH: `${bin}${delimiter}${process.env.PATH ?? ''}`,
|
||||
LFTP_OPEN: 'file:///',
|
||||
},
|
||||
marker,
|
||||
);
|
||||
}
|
||||
|
||||
it.each([
|
||||
'.',
|
||||
'..',
|
||||
'../x',
|
||||
'a/../b',
|
||||
'./x',
|
||||
'a/./b',
|
||||
'-x',
|
||||
'',
|
||||
'/',
|
||||
'a//b',
|
||||
])('weigert de doelmap %j en start niets', async (remote) => {
|
||||
const dist = await makeDist();
|
||||
await withFakeLftp(async (env, marker) => {
|
||||
const run = await runScript(
|
||||
'upload-production.sh',
|
||||
[slash(dist), remote],
|
||||
env,
|
||||
);
|
||||
expect(run.code).toBe(2);
|
||||
expect(run.stderr).toContain('Ongeldig pad');
|
||||
expect(existsSync(marker)).toBe(false);
|
||||
});
|
||||
expect(existsSync(join(dist, 'web.config'))).toBe(false);
|
||||
});
|
||||
|
||||
it.each(['.', '..', '-d', 'a/../dist'])(
|
||||
'weigert de dist-map %j en start niets',
|
||||
async (dist) => {
|
||||
await withFakeLftp(async (env, marker) => {
|
||||
const run = await runScript(
|
||||
'upload-production.sh',
|
||||
[dist, 'wwwroot'],
|
||||
env,
|
||||
);
|
||||
expect(run.code).toBe(2);
|
||||
expect(run.stderr).toContain('Ongeldig pad');
|
||||
expect(existsSync(marker)).toBe(false);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(['wwwroot', 'sites/andreaslop.nl', '/srv/site', 'wwwroot/'])(
|
||||
'laat de doelmap %j door',
|
||||
async (remote) => {
|
||||
const dist = await makeDist();
|
||||
await withFakeLftp(async (env, marker) => {
|
||||
// Relatief aan de map erboven: een Windows-pad met een
|
||||
// stationsletter haalt de padcontrole niet
|
||||
const run = await runScript(
|
||||
'upload-production.sh',
|
||||
[basename(dist), remote],
|
||||
env,
|
||||
dirname(dist),
|
||||
);
|
||||
expect(run.code).toBe(0);
|
||||
expect(existsSync(marker)).toBe(true);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user