poad 2.38.0 → 2.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/global/cli.js +2 -1
- package/global/create.js +286 -0
- package/global/init.js +17 -5
- package/global/run.js +17 -10
- package/package.json +4 -2
- package/poad.js +26 -1
- package/project/cli.js +3 -3
- package/project/client/index.js +2 -2
- package/project/client/init.js +43 -59
- package/project/info.js +22 -2
- package/test/create.e2e.test.js +73 -0
- package/test/create.test.js +95 -0
- package/test/help-stub.js +29 -0
- package/test/help.test.js +124 -0
- package/test/helpers.js +53 -0
- package/test/offline-stub.js +5 -0
- package/test/registry.test.js +95 -0
- package/test/secrets.test.js +94 -0
- package/test/starter.test.js +122 -0
- package/test/tar.test.js +101 -0
- package/utils/engine.js +10 -5
- package/utils/git.js +1 -1
- package/utils/help.js +80 -0
- package/utils/registry.js +145 -0
- package/utils/report.js +23 -12
- package/utils/services.js +2 -2
- package/utils/starter.js +214 -0
- package/utils/tar.js +180 -0
package/project/info.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
// poad info : le projet (URL, base, clés, migrations), puis un panneau à part
|
|
2
2
|
// pour les services qui tournent à côté de l'engine (Mailpit, Keycloak, Valkey).
|
|
3
3
|
// poad start affiche la même chose à la fin du démarrage.
|
|
4
|
-
|
|
4
|
+
// Les secrets (secret JWT, clé service_role, mot de passe admin de Keycloak…)
|
|
5
|
+
// sont masqués ; poad info --secrets les montre.
|
|
6
|
+
|
|
7
|
+
/** --secrets, secrets : montrer les secrets */
|
|
8
|
+
const wantsSecrets = (args = {}) => Boolean(args.secrets || args['--secrets']);
|
|
9
|
+
|
|
10
|
+
function help() {
|
|
11
|
+
const chalk = require('chalk-v2');
|
|
12
|
+
console.log(`${chalk.bold(' Usage :')} ${chalk.cyanBright('poad info')} ${chalk.cyan('[--secrets]')}`);
|
|
13
|
+
console.log(' ');
|
|
14
|
+
console.log(' State of the running project: URLs, database, keys, migrations, then the services next to the engine.');
|
|
15
|
+
console.log(' The JWT secret, the service_role key, the S3 secret key and the Keycloak admin password are hidden.');
|
|
16
|
+
console.log(' ');
|
|
17
|
+
console.log(` ${chalk.cyanBright('--secrets')} show them too (not in a shared screen, a recording or a ticket)`);
|
|
18
|
+
console.log(' ');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = async (args = {}) => {
|
|
5
22
|
const chalk = require('chalk-v2');
|
|
6
23
|
const { findPoadDir } = require('../utils/findpoad');
|
|
7
24
|
const { isDockerExist } = require('../utils/docker');
|
|
@@ -12,5 +29,8 @@ module.exports = async () => {
|
|
|
12
29
|
if (!(await isDockerExist(config.project_uuid))) {
|
|
13
30
|
return console.log(chalk.redBright('The project is not started: "poad start".'));
|
|
14
31
|
}
|
|
15
|
-
await require('../utils/report').printReport(root, config);
|
|
32
|
+
await require('../utils/report').printReport(root, config, { secrets: wantsSecrets(args) });
|
|
16
33
|
};
|
|
34
|
+
|
|
35
|
+
module.exports.help = help;
|
|
36
|
+
module.exports.wantsSecrets = wantsSecrets;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Bout en bout, contre le vrai registre npm (sans Docker, sans poad start) :
|
|
2
|
+
// POAD_E2E=1 node --test test/create.e2e.test.js
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const assert = require('node:assert');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
const { tmpdir } = require('./helpers');
|
|
9
|
+
|
|
10
|
+
const CLI = path.join(__dirname, '..', 'poad.js');
|
|
11
|
+
const e2e = process.env.POAD_E2E === '1';
|
|
12
|
+
|
|
13
|
+
test('poad create my-app --template angular --no-install --yes', { skip: !e2e && 'POAD_E2E=1 to run it (network)', timeout: 120000 }, async (t) => {
|
|
14
|
+
const cwd = tmpdir(t, 'poad-create-');
|
|
15
|
+
const r = spawnSync(process.execPath, [CLI, 'create', 'my-app', '--template', 'angular', '--no-install', '--yes'], {
|
|
16
|
+
cwd,
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
input: '',
|
|
19
|
+
env: { ...process.env, GIT_AUTHOR_NAME: 'poad test', GIT_AUTHOR_EMAIL: 'test@example.invalid', GIT_COMMITTER_NAME: 'poad test', GIT_COMMITTER_EMAIL: 'test@example.invalid' },
|
|
20
|
+
});
|
|
21
|
+
const out = r.stdout + r.stderr;
|
|
22
|
+
assert.strictEqual(r.status, 0, out);
|
|
23
|
+
assert.match(out, /integrity verified/);
|
|
24
|
+
const app = path.join(cwd, 'my-app');
|
|
25
|
+
|
|
26
|
+
// package.json renommé, sans champs de publication
|
|
27
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(app, 'package.json'), 'utf8'));
|
|
28
|
+
assert.strictEqual(pkg.name, 'my-app');
|
|
29
|
+
assert.strictEqual(pkg.version, '0.1.0');
|
|
30
|
+
assert.strictEqual(pkg.private, true);
|
|
31
|
+
for (const k of ['files', 'repository', 'publishConfig']) assert.ok(!(k in pkg), `${k} dropped`);
|
|
32
|
+
assert.match(pkg.poad.from, /^@poadio\/starter-angular@\d+\.\d+\.\d+/);
|
|
33
|
+
assert.strictEqual(pkg.scripts.start, 'node scripts/dev.mjs');
|
|
34
|
+
|
|
35
|
+
// poad init : config.toml avec l'engine recommandé par permalink
|
|
36
|
+
const config = fs.readFileSync(path.join(app, 'poad', 'config.toml'), 'utf8');
|
|
37
|
+
assert.match(config, /^project_id = "my-app"$/m);
|
|
38
|
+
const engine = /^engine = "([^"]+)"$/m.exec(config);
|
|
39
|
+
assert.ok(engine, config);
|
|
40
|
+
const permalink = await fetch('https://raw.githubusercontent.com/poadio/permalink/main/poad.json', { signal: AbortSignal.timeout(5000) })
|
|
41
|
+
.then((res) => res.json())
|
|
42
|
+
.catch(() => null);
|
|
43
|
+
if (permalink && permalink.engine && permalink.engine.stable) assert.strictEqual(engine[1], permalink.engine.stable);
|
|
44
|
+
assert.ok(fs.existsSync(path.join(app, 'poad', 'secrets.toml')));
|
|
45
|
+
assert.ok(fs.existsSync(path.join(app, 'poad', 'migrations')));
|
|
46
|
+
|
|
47
|
+
// .gitignore : lignes du modèle et de poad init
|
|
48
|
+
const gitignore = fs.readFileSync(path.join(app, '.gitignore'), 'utf8');
|
|
49
|
+
for (const line of ['poad/secrets.toml', 'poad/data/', 'node_modules/', '/public/env.json']) assert.ok(gitignore.split('\n').includes(line), line);
|
|
50
|
+
|
|
51
|
+
// Premier commit, sans secret
|
|
52
|
+
const log = spawnSync('git', ['log', '--format=%s'], { cwd: app, encoding: 'utf8' });
|
|
53
|
+
assert.match(log.stdout.trim(), /^Initial commit from @poadio\/starter-angular@/);
|
|
54
|
+
const files = spawnSync('git', ['ls-files'], { cwd: app, encoding: 'utf8' }).stdout.split('\n');
|
|
55
|
+
assert.ok(files.includes('package.json') && files.includes('poad/config.toml'));
|
|
56
|
+
assert.ok(!files.some((f) => f.startsWith('poad/secrets') || f.startsWith('poad/data/') || f === '.npmignore'));
|
|
57
|
+
|
|
58
|
+
// Aucune clé dans la sortie
|
|
59
|
+
const secrets = fs.readFileSync(path.join(app, 'poad', 'secrets.toml'), 'utf8');
|
|
60
|
+
for (const [, value] of secrets.matchAll(/=\s*"([^"]{16,})"/g)) assert.ok(!out.includes(value), 'a secret was printed');
|
|
61
|
+
|
|
62
|
+
// Dossier non vide : refusé, rien n'est touché
|
|
63
|
+
const again = spawnSync(process.execPath, [CLI, 'create', 'my-app', '--template', 'angular', '--yes'], { cwd, encoding: 'utf8', input: '' });
|
|
64
|
+
assert.match(again.stdout, /is not empty/);
|
|
65
|
+
assert.notStrictEqual(again.status, 0);
|
|
66
|
+
|
|
67
|
+
// Modèle pas encore publié : « coming soon »
|
|
68
|
+
const soon = spawnSync(process.execPath, [CLI, 'create', 'other', '--template', 'vanilla', '--yes'], { cwd, encoding: 'utf8', input: '' });
|
|
69
|
+
if (/coming soon/.test(soon.stdout)) {
|
|
70
|
+
assert.notStrictEqual(soon.status, 0);
|
|
71
|
+
assert.ok(!fs.existsSync(path.join(cwd, 'other')));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { parseCreateArgs, checkTarget } = require('../global/create');
|
|
6
|
+
const { tmpdir } = require('./helpers');
|
|
7
|
+
|
|
8
|
+
test('create arguments: flags, --key value, --key=value and key=value', () => {
|
|
9
|
+
assert.deepStrictEqual(parseCreateArgs(['app', '--template', 'Nuxt', '--yes', '--no-install', '--no-git', '--pm=pnpm']), {
|
|
10
|
+
dir: 'app', template: 'nuxt', pm: 'pnpm', from: null, yes: true, noInstall: true, noGit: true, help: false,
|
|
11
|
+
});
|
|
12
|
+
assert.strictEqual(parseCreateArgs(['template=vanilla', 'x']).template, 'vanilla');
|
|
13
|
+
assert.throws(() => parseCreateArgs(['a', 'b']), /unexpected argument/);
|
|
14
|
+
assert.throws(() => parseCreateArgs(['a', '--pm', 'yarn']), /--pm must be/);
|
|
15
|
+
assert.throws(() => parseCreateArgs(['a', '--template']), /needs a value/);
|
|
16
|
+
assert.throws(() => parseCreateArgs(['a', '--force']), /unknown option/);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('target folder: new or empty only', (t) => {
|
|
20
|
+
const dir = tmpdir(t);
|
|
21
|
+
assert.strictEqual(checkTarget(path.join(dir, 'new')), 'new');
|
|
22
|
+
fs.writeFileSync(path.join(dir, '.DS_Store'), '');
|
|
23
|
+
assert.strictEqual(checkTarget(dir), 'empty');
|
|
24
|
+
fs.writeFileSync(path.join(dir, 'x'), '');
|
|
25
|
+
assert.throws(() => checkTarget(dir), /not empty/);
|
|
26
|
+
assert.throws(() => checkTarget(path.join(dir, 'x')), /not a folder/);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('poad create --from <malicious.tgz>: refused, nothing left behind', (t) => {
|
|
30
|
+
const { spawnSync } = require('child_process');
|
|
31
|
+
const { tgz } = require('./helpers');
|
|
32
|
+
const cwd = tmpdir(t);
|
|
33
|
+
fs.writeFileSync(
|
|
34
|
+
path.join(cwd, 'evil.tgz'),
|
|
35
|
+
tgz([
|
|
36
|
+
{ name: 'package/package.json', data: '{"name":"evil","version":"1.0.0"}' },
|
|
37
|
+
{ name: 'package/../../escaped.txt', data: 'evil' },
|
|
38
|
+
])
|
|
39
|
+
);
|
|
40
|
+
const r = spawnSync(process.execPath, [path.join(__dirname, '..', 'poad.js'), 'create', 'app', '--from', 'evil.tgz', '--yes', '--no-install', '--no-git'], { cwd, encoding: 'utf8', input: '' });
|
|
41
|
+
assert.match(r.stdout + r.stderr, /Template unavailable: refused entry .*"\.\."/);
|
|
42
|
+
assert.notStrictEqual(r.status, 0);
|
|
43
|
+
assert.deepStrictEqual(fs.readdirSync(cwd), ['evil.tgz']);
|
|
44
|
+
assert.ok(!fs.existsSync(path.join(cwd, '..', 'escaped.txt')));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('created title: framework label, never "Application application"', () => {
|
|
48
|
+
const { createdTitle } = require('../global/create');
|
|
49
|
+
const { templateByValue } = require('../utils/starter');
|
|
50
|
+
assert.strictEqual(createdTitle(null, {}), 'Application created');
|
|
51
|
+
assert.strictEqual(createdTitle(null, { label: 'Next.js' }), 'Next.js application created');
|
|
52
|
+
assert.strictEqual(createdTitle(templateByValue('angular'), { label: 'Angular' }), 'Angular application created');
|
|
53
|
+
assert.strictEqual(createdTitle(templateByValue('vanilla'), { label: null }), 'Vanilla application created');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// poad create --from <archive locale> jusqu'au bout (sans réseau, sans
|
|
57
|
+
// installation ni git) : titre et URL du front selon le framework du modèle
|
|
58
|
+
function createFrom(t, pkg, extra = []) {
|
|
59
|
+
const { spawnSync } = require('child_process');
|
|
60
|
+
const { tgz } = require('./helpers');
|
|
61
|
+
const cwd = tmpdir(t);
|
|
62
|
+
const home = path.join(cwd, 'home');
|
|
63
|
+
fs.mkdirSync(home);
|
|
64
|
+
// version déjà vérifiée : pas de npm view
|
|
65
|
+
fs.writeFileSync(path.join(home, '.poad_last_check.json'), JSON.stringify({ date: new Date(), version: require('../package.json').version }));
|
|
66
|
+
fs.writeFileSync(path.join(cwd, 'tpl.tgz'), tgz([{ name: 'package/package.json', data: JSON.stringify(pkg) }, ...extra]));
|
|
67
|
+
const r = spawnSync(process.execPath, ['--require', path.join(__dirname, 'offline-stub.js'), path.join(__dirname, '..', 'poad.js'), 'create', 'app', '--from', 'tpl.tgz', '--yes', '--no-install', '--no-git'], {
|
|
68
|
+
cwd,
|
|
69
|
+
encoding: 'utf8',
|
|
70
|
+
input: '',
|
|
71
|
+
timeout: 30000,
|
|
72
|
+
env: { ...process.env, HOME: home, NODE_OPTIONS: '' },
|
|
73
|
+
});
|
|
74
|
+
return { r, out: r.stdout + r.stderr, app: path.join(cwd, 'app') };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
test('poad create --from a Next.js template: "Next.js application created", URL from poad.port, poad.port kept', (t) => {
|
|
78
|
+
const pkg = { name: '@poadio/starter-next', version: '0.1.0', dependencies: { next: '16.4.6' }, poad: { port: 3300, template: { framework: 'next', label: 'Next.js + @poadio/ui-react', port: 3300 } } };
|
|
79
|
+
const { r, out, app } = createFrom(t, pkg);
|
|
80
|
+
assert.strictEqual(r.status, 0, out);
|
|
81
|
+
assert.match(out, /Next\.js application created/);
|
|
82
|
+
assert.doesNotMatch(out, /Application application/);
|
|
83
|
+
assert.match(out, /front-end on http:\/\/localhost:3300/);
|
|
84
|
+
const written = JSON.parse(fs.readFileSync(path.join(app, 'package.json'), 'utf8'));
|
|
85
|
+
assert.strictEqual(written.poad.port, 3300);
|
|
86
|
+
assert.ok(!('template' in written.poad));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('poad create --from an unknown template: "Application created", no URL', (t) => {
|
|
90
|
+
const { r, out } = createFrom(t, { name: 'custom', version: '1.0.0' });
|
|
91
|
+
assert.strictEqual(r.status, 0, out);
|
|
92
|
+
assert.match(out, /✔ Application created in app/);
|
|
93
|
+
assert.doesNotMatch(out, /Application application|localhost:\d+ *$/m);
|
|
94
|
+
assert.doesNotMatch(out, /front-end on/);
|
|
95
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Chargé avec node --require par test/help.test.js : tout appel à Docker, à un
|
|
2
|
+
// processus ou au réseau est noté dans POAD_TEST_CALLS, puis refusé. Une aide
|
|
3
|
+
// (--help, -h) ne doit rien noter.
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const Module = require('module');
|
|
6
|
+
const childProcess = require('child_process');
|
|
7
|
+
|
|
8
|
+
const file = process.env.POAD_TEST_CALLS;
|
|
9
|
+
const note = (what) => {
|
|
10
|
+
fs.appendFileSync(file, what + '\n');
|
|
11
|
+
throw new Error(`blocked by the test: ${what}`);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class FakeDocker {
|
|
15
|
+
constructor() {
|
|
16
|
+
note('new Docker()');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const load = Module._load;
|
|
21
|
+
Module._load = function (request, ...rest) {
|
|
22
|
+
if (request === 'dockerode') return FakeDocker;
|
|
23
|
+
return load.call(this, request, ...rest);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
for (const fn of ['spawn', 'spawnSync', 'exec', 'execSync', 'execFile', 'execFileSync', 'fork']) {
|
|
27
|
+
childProcess[fn] = (cmd, args) => note(`child_process.${fn}(${cmd} ${Array.isArray(args) ? args.join(' ') : ''})`);
|
|
28
|
+
}
|
|
29
|
+
globalThis.fetch = async (url) => note(`fetch(${url})`);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// --help et -h sur toutes les commandes : l'aide s'affiche, rien ne s'exécute.
|
|
2
|
+
// Le CLI tourne dans un projet poad factice avec test/help-stub.js chargé :
|
|
3
|
+
// Docker, processus et réseau y sont refusés et notés. Aucune note attendue.
|
|
4
|
+
const test = require('node:test');
|
|
5
|
+
const assert = require('node:assert');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { spawnSync } = require('child_process');
|
|
9
|
+
const { tmpdir } = require('./helpers');
|
|
10
|
+
const { helpRequested, resolveCommand } = require('../utils/help');
|
|
11
|
+
|
|
12
|
+
const POAD = path.join(__dirname, '..', 'poad.js');
|
|
13
|
+
const STUB = path.join(__dirname, 'help-stub.js');
|
|
14
|
+
|
|
15
|
+
/** Projet poad factice (conteneur inexistant) et HOME à part */
|
|
16
|
+
function sandbox(t) {
|
|
17
|
+
const dir = tmpdir(t);
|
|
18
|
+
fs.mkdirSync(path.join(dir, 'poad'));
|
|
19
|
+
const config = 'project_id = "helptest"\nproject_uuid = "poad-help-test-not-a-container"\nengine = "0.28.0"\n[web]\nport = 1\n[db]\nport = 1\n[auth]\nsecret = "s"\nanon = "a"\nservice = "x"\n';
|
|
20
|
+
fs.writeFileSync(path.join(dir, 'poad', 'config.toml'), config);
|
|
21
|
+
fs.mkdirSync(path.join(dir, 'home'));
|
|
22
|
+
return { dir, config, calls: path.join(dir, 'calls.log') };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function poad(box, args) {
|
|
26
|
+
return spawnSync(process.execPath, ['--require', STUB, POAD, ...args], {
|
|
27
|
+
cwd: box.dir,
|
|
28
|
+
encoding: 'utf8',
|
|
29
|
+
input: '',
|
|
30
|
+
timeout: 15000,
|
|
31
|
+
env: { ...process.env, HOME: path.join(box.dir, 'home'), POAD_TEST_CALLS: box.calls, NODE_OPTIONS: '' },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Toutes les commandes des deux tables, sous-commandes comprises */
|
|
36
|
+
function allCommands() {
|
|
37
|
+
const out = [];
|
|
38
|
+
const walk = (node, prefix) => {
|
|
39
|
+
for (const [k, v] of Object.entries(node)) {
|
|
40
|
+
if (k === 'description') continue;
|
|
41
|
+
out.push([...prefix, k]);
|
|
42
|
+
if (v && typeof v === 'object') walk(v, [...prefix, k]);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
walk(require('../global/cli'), []);
|
|
46
|
+
walk(require('../project/cli'), []);
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
test('help flag detection', () => {
|
|
51
|
+
assert.strictEqual(helpRequested(['stop', '--help']), true);
|
|
52
|
+
assert.strictEqual(helpRequested(['db', 'reset', '-h']), true);
|
|
53
|
+
assert.strictEqual(helpRequested(['flows', 'run', 'x', 'msg=--help']), false);
|
|
54
|
+
assert.strictEqual(helpRequested(['stop']), false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('command resolution: deepest known command, global first', () => {
|
|
58
|
+
assert.deepStrictEqual(resolveCommand(['db', 'reset', '--yes', '--help']).dir, ['db', 'reset']);
|
|
59
|
+
assert.strictEqual(resolveCommand(['db', 'reset', '--help']).scope, 'project');
|
|
60
|
+
assert.deepStrictEqual(resolveCommand(['upgrade', '--rollback', '-h']).dir, ['upgrade']);
|
|
61
|
+
assert.strictEqual(resolveCommand(['stop', 'kc', '--help']).scope, 'global');
|
|
62
|
+
assert.strictEqual(resolveCommand(['nope', '--help']), null);
|
|
63
|
+
// une clé héritée d'Object n'est pas une commande
|
|
64
|
+
assert.strictEqual(resolveCommand(['constructor', '--help']), null);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('destructive commands with --help or -h: usage shown, nothing run (no Docker, no process, no network)', (t) => {
|
|
68
|
+
const box = sandbox(t);
|
|
69
|
+
const cases = [
|
|
70
|
+
['stop', '--help'],
|
|
71
|
+
['stop', '-h'],
|
|
72
|
+
['stop', 'kc', '--help'],
|
|
73
|
+
['db', 'reset', '--help'],
|
|
74
|
+
['db', 'reset', '--yes', '-h'],
|
|
75
|
+
['clean', '--yes', '--help'],
|
|
76
|
+
['upgrade', '--rollback', '--help'],
|
|
77
|
+
['upgrade', '--yes', '-h'],
|
|
78
|
+
['start', '--help'],
|
|
79
|
+
['run', '--all', '--help'],
|
|
80
|
+
['init', '--help'],
|
|
81
|
+
['install', '--help'],
|
|
82
|
+
['setup', '--none', '--help'],
|
|
83
|
+
['migrate', '--help'],
|
|
84
|
+
['flows', 'run', 'x', '--help'],
|
|
85
|
+
['help', 'stop'],
|
|
86
|
+
];
|
|
87
|
+
for (const args of cases) {
|
|
88
|
+
const r = poad(box, args);
|
|
89
|
+
assert.strictEqual(r.status, 0, `${args.join(' ')}: exit ${r.status}\n${r.stdout}${r.stderr}`);
|
|
90
|
+
assert.match(r.stdout, /Usage :/, args.join(' '));
|
|
91
|
+
assert.ok(!fs.existsSync(box.calls), `${args.join(' ')} called: ${fs.existsSync(box.calls) && fs.readFileSync(box.calls, 'utf8')}`);
|
|
92
|
+
}
|
|
93
|
+
// rien n'a bougé dans le projet
|
|
94
|
+
assert.deepStrictEqual(fs.readdirSync(box.dir).sort(), ['home', 'poad']);
|
|
95
|
+
assert.deepStrictEqual(fs.readdirSync(path.join(box.dir, 'poad')), ['config.toml']);
|
|
96
|
+
assert.strictEqual(fs.readFileSync(path.join(box.dir, 'poad', 'config.toml'), 'utf8'), box.config);
|
|
97
|
+
assert.deepStrictEqual(fs.readdirSync(path.join(box.dir, 'home')), []);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('every command answers --help with its usage and runs nothing', (t) => {
|
|
101
|
+
const box = sandbox(t);
|
|
102
|
+
for (const cmd of allCommands()) {
|
|
103
|
+
const r = poad(box, [...cmd, '--help']);
|
|
104
|
+
assert.strictEqual(r.status, 0, `${cmd.join(' ')}: exit ${r.status}\n${r.stdout}${r.stderr}`);
|
|
105
|
+
assert.match(r.stdout, /Usage :/, cmd.join(' '));
|
|
106
|
+
assert.ok(!fs.existsSync(box.calls), `${cmd.join(' ')} called: ${fs.existsSync(box.calls) && fs.readFileSync(box.calls, 'utf8')}`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('the stub does catch a real call (poad stop without --help reaches Docker)', (t) => {
|
|
111
|
+
const box = sandbox(t);
|
|
112
|
+
// version déjà vérifiée : pas de npm view avant la commande
|
|
113
|
+
fs.writeFileSync(path.join(box.dir, 'home', '.poad_last_check.json'), JSON.stringify({ date: new Date(), version: require('../package.json').version }));
|
|
114
|
+
poad(box, ['stop']);
|
|
115
|
+
assert.match(fs.readFileSync(box.calls, 'utf8'), /new Docker\(\)/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('unknown command with --help: error and command list, exit 1', (t) => {
|
|
119
|
+
const box = sandbox(t);
|
|
120
|
+
const r = poad(box, ['nope', '--help']);
|
|
121
|
+
assert.strictEqual(r.status, 1);
|
|
122
|
+
assert.match(r.stdout + r.stderr, /Unknown command : nope/);
|
|
123
|
+
assert.ok(!fs.existsSync(box.calls));
|
|
124
|
+
});
|
package/test/helpers.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Fabrication d'archives tar/tgz pour les tests (en-têtes ustar écrits à la main,
|
|
2
|
+
// pour pouvoir y mettre ce qu'un outil tar refuserait : « .. », chemins absolus, liens)
|
|
3
|
+
const zlib = require('zlib');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const octal = (n, len) => n.toString(8).padStart(len - 1, '0') + '\0';
|
|
9
|
+
|
|
10
|
+
/** entries : [{ name, type: '0'|'2'|'1'|'5'|'x'..., data, linkname, mode }] */
|
|
11
|
+
function tar(entries) {
|
|
12
|
+
const blocks = [];
|
|
13
|
+
for (const e of entries) {
|
|
14
|
+
const data = Buffer.isBuffer(e.data) ? e.data : Buffer.from(e.data || '');
|
|
15
|
+
const h = Buffer.alloc(512);
|
|
16
|
+
h.write(e.name, 0, 100, 'utf8');
|
|
17
|
+
h.write(octal(e.mode || 0o644, 8), 100);
|
|
18
|
+
h.write(octal(0, 8), 108);
|
|
19
|
+
h.write(octal(0, 8), 116);
|
|
20
|
+
h.write(octal(data.length, 12), 124);
|
|
21
|
+
h.write(octal(0, 12), 136);
|
|
22
|
+
h.write(' '.repeat(8), 148);
|
|
23
|
+
h.write(e.type || '0', 156);
|
|
24
|
+
if (e.linkname) h.write(e.linkname, 157, 100);
|
|
25
|
+
h.write('ustar\0', 257);
|
|
26
|
+
h.write('00', 263);
|
|
27
|
+
let sum = 0;
|
|
28
|
+
for (const b of h) sum += b;
|
|
29
|
+
h.write(octal(sum, 7) + ' ', 148);
|
|
30
|
+
blocks.push(h, data, Buffer.alloc((512 - (data.length % 512)) % 512));
|
|
31
|
+
}
|
|
32
|
+
blocks.push(Buffer.alloc(1024));
|
|
33
|
+
return Buffer.concat(blocks);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const tgz = (entries) => zlib.gzipSync(tar(entries));
|
|
37
|
+
|
|
38
|
+
/** Enregistrement pax « longueur clé=valeur\n » */
|
|
39
|
+
function paxRecord(key, value) {
|
|
40
|
+
const body = ` ${key}=${value}\n`;
|
|
41
|
+
let len = body.length + 1;
|
|
42
|
+
while (String(len).length + body.length !== len) len = String(len).length + body.length;
|
|
43
|
+
return `${len}${body}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Dossier temporaire (sous TMPDIR) supprimé à la fin du test */
|
|
47
|
+
function tmpdir(t, prefix = 'poad-test-') {
|
|
48
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
49
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
50
|
+
return dir;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { tar, tgz, paxRecord, tmpdir };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert');
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const { verifyIntegrity, parseIntegrity, latestDist, metadataUrl, RegistryError } = require('../utils/registry');
|
|
5
|
+
|
|
6
|
+
const sri = (buf) => `sha512-${crypto.createHash('sha512').update(buf).digest('base64')}`;
|
|
7
|
+
|
|
8
|
+
test('accepts content matching its sha512 integrity', () => {
|
|
9
|
+
const buf = Buffer.from('template archive');
|
|
10
|
+
assert.doesNotThrow(() => verifyIntegrity(buf, sri(buf)));
|
|
11
|
+
// plusieurs empreintes SRI : une seule doit correspondre
|
|
12
|
+
assert.doesNotThrow(() => verifyIntegrity(buf, `${sri(Buffer.from('other'))} ${sri(buf)}`));
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('refuses content whose sha512 does not match (integrity mismatch)', () => {
|
|
16
|
+
const buf = Buffer.from('template archive');
|
|
17
|
+
const tampered = Buffer.from('template archivE');
|
|
18
|
+
assert.throws(() => verifyIntegrity(tampered, sri(buf), 'x@1.0.0'), (err) => err instanceof RegistryError && /integrity check failed/.test(err.message));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('refuses a missing or non-sha512 integrity', () => {
|
|
22
|
+
const buf = Buffer.from('a');
|
|
23
|
+
assert.throws(() => verifyIntegrity(buf, undefined), /no sha512 integrity/);
|
|
24
|
+
assert.throws(() => verifyIntegrity(buf, `sha1-${crypto.createHash('sha1').update(buf).digest('base64')}`), /no sha512 integrity/);
|
|
25
|
+
assert.strictEqual(parseIntegrity('sha512-short'), null);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('latest version: HTTPS tarball and sha512 integrity are required', () => {
|
|
29
|
+
const data = (dist) => ({ 'dist-tags': { latest: '1.0.0' }, versions: { '1.0.0': { dist } } });
|
|
30
|
+
const integrity = sri(Buffer.from('x'));
|
|
31
|
+
assert.deepStrictEqual(latestDist('p', data({ tarball: 'https://r/p.tgz', integrity })), { version: '1.0.0', tarball: 'https://r/p.tgz', integrity });
|
|
32
|
+
assert.throws(() => latestDist('p', data({ tarball: 'http://r/p.tgz', integrity })), /not HTTPS/);
|
|
33
|
+
assert.throws(() => latestDist('p', data({ tarball: 'https://r/p.tgz', shasum: 'abc' })), /no sha512 integrity/);
|
|
34
|
+
assert.throws(() => latestDist('p', { 'dist-tags': {} }), /no "latest"/);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('scoped package metadata URL', () => {
|
|
38
|
+
assert.strictEqual(metadataUrl('@poadio/starter-next'), 'https://registry.npmjs.org/@poadio%2fstarter-next');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Téléchargement complet, fetch remplacé : ni réseau ni ~/.poad touchés
|
|
42
|
+
const fs = require('fs');
|
|
43
|
+
const os = require('os');
|
|
44
|
+
const path = require('path');
|
|
45
|
+
const { fetchLatestTarball } = require('../utils/registry');
|
|
46
|
+
const { tmpdir } = require('./helpers');
|
|
47
|
+
|
|
48
|
+
const withHome = (t) => {
|
|
49
|
+
const home = tmpdir(t, 'poad-home-');
|
|
50
|
+
const old = process.env.HOME;
|
|
51
|
+
process.env.HOME = home;
|
|
52
|
+
t.after(() => (process.env.HOME = old));
|
|
53
|
+
return home;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const stubFetch = (t, body) => {
|
|
57
|
+
const old = globalThis.fetch;
|
|
58
|
+
globalThis.fetch = async (url) => {
|
|
59
|
+
const res = new Response(body, { status: 200 });
|
|
60
|
+
Object.defineProperty(res, 'url', { value: url });
|
|
61
|
+
return res;
|
|
62
|
+
};
|
|
63
|
+
t.after(() => (globalThis.fetch = old));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const metadataFor = (integrity) => ({
|
|
67
|
+
status: 'ok',
|
|
68
|
+
data: { 'dist-tags': { latest: '1.2.3' }, versions: { '1.2.3': { dist: { tarball: 'https://registry.example/p-1.2.3.tgz', integrity } } } },
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('download: a tarball that does not match the registry integrity is refused and not cached', async (t) => {
|
|
72
|
+
const home = withHome(t);
|
|
73
|
+
assert.strictEqual(os.homedir(), home);
|
|
74
|
+
stubFetch(t, Buffer.from('tampered tarball'));
|
|
75
|
+
await assert.rejects(fetchLatestTarball('@poadio/starter-x', { metadata: metadataFor(sri(Buffer.from('genuine tarball'))) }), /integrity check failed/);
|
|
76
|
+
assert.strictEqual(fs.existsSync(path.join(home, '.poad', 'starters')), false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('download: verified tarball is cached, then used offline; a tampered cache is ignored', async (t) => {
|
|
80
|
+
const home = withHome(t);
|
|
81
|
+
const buf = Buffer.from('genuine tarball');
|
|
82
|
+
stubFetch(t, buf);
|
|
83
|
+
const got = await fetchLatestTarball('@poadio/starter-x', { metadata: metadataFor(sri(buf)) });
|
|
84
|
+
assert.strictEqual(got.source, 'registry');
|
|
85
|
+
assert.strictEqual(got.version, '1.2.3');
|
|
86
|
+
const offline = await fetchLatestTarball('@poadio/starter-x', { metadata: { status: 'offline', error: 'timeout' } });
|
|
87
|
+
assert.strictEqual(offline.source, 'cache');
|
|
88
|
+
assert.ok(offline.buf.equals(buf));
|
|
89
|
+
fs.writeFileSync(path.join(home, '.poad', 'starters', 'poadio__starter-x.tgz'), 'tampered');
|
|
90
|
+
await assert.rejects(fetchLatestTarball('@poadio/starter-x', { metadata: { status: 'offline', error: 'timeout' } }), /not in the cache/);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('unpublished package: not published on npm', async () => {
|
|
94
|
+
await assert.rejects(fetchLatestTarball('@poadio/starter-x', { metadata: { status: 'missing' } }), /not published/);
|
|
95
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Secrets jamais affichés par défaut : poad info / poad start montrent
|
|
2
|
+
// « hidden · poad info --secrets » à la place du secret JWT, de la clé
|
|
3
|
+
// service_role, de la clé secrète S3 et du mot de passe admin de Keycloak ;
|
|
4
|
+
// poad info --secrets les montre. La clé anon (faite pour le navigateur) reste.
|
|
5
|
+
const test = require('node:test');
|
|
6
|
+
const assert = require('node:assert');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { tmpdir } = require('./helpers');
|
|
10
|
+
|
|
11
|
+
const JWT = 'jwt-secret-value-for-test-0123456789';
|
|
12
|
+
const SERVICE = 'service-role-key-for-test-abcdef';
|
|
13
|
+
const ANON = 'anon-key-for-test-public';
|
|
14
|
+
const S3_SECRET = 's3-secret-key-for-test';
|
|
15
|
+
const KC_ADMIN = 'KcAdminPassForTest';
|
|
16
|
+
|
|
17
|
+
// Port 1 : rien n'écoute, la ligne des migrations échoue tout de suite
|
|
18
|
+
const config = (engine = '0.20.0') => ({
|
|
19
|
+
project_id: 'demo',
|
|
20
|
+
project_uuid: 'poad-test-not-a-container',
|
|
21
|
+
engine,
|
|
22
|
+
web: { port: 1 },
|
|
23
|
+
db: { port: 1 },
|
|
24
|
+
auth: { secret: JWT, anon: ANON, service: SERVICE },
|
|
25
|
+
s3: { port: 1, access_key: 'access', secret_key: S3_SECRET },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** Sortie console d'une fonction asynchrone */
|
|
29
|
+
async function capture(fn) {
|
|
30
|
+
const lines = [];
|
|
31
|
+
const log = console.log;
|
|
32
|
+
console.log = (...a) => lines.push(a.join(' '));
|
|
33
|
+
try {
|
|
34
|
+
await fn();
|
|
35
|
+
} finally {
|
|
36
|
+
console.log = log;
|
|
37
|
+
}
|
|
38
|
+
return lines.join('\n');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function project(t) {
|
|
42
|
+
const dir = tmpdir(t);
|
|
43
|
+
fs.mkdirSync(path.join(dir, 'poad'));
|
|
44
|
+
const root = path.join(dir, 'poad', 'config.toml');
|
|
45
|
+
fs.writeFileSync(root, 'project_id = "demo"\n');
|
|
46
|
+
return root;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
test('poad info: JWT secret, service_role key and the key in the admin docs URL hidden by default; anon key shown', async (t) => {
|
|
50
|
+
const { printProject } = require('../utils/report');
|
|
51
|
+
const out = await capture(() => printProject(project(t), config()));
|
|
52
|
+
assert.ok(!out.includes(JWT), 'JWT secret not printed');
|
|
53
|
+
assert.ok(!out.includes(SERVICE), 'service_role key not printed');
|
|
54
|
+
assert.ok(out.includes(ANON), 'anon key printed');
|
|
55
|
+
assert.match(out, /hidden · poad info --secrets/);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('poad info --secrets: every value shown', async (t) => {
|
|
59
|
+
const { printProject } = require('../utils/report');
|
|
60
|
+
const out = await capture(() => printProject(project(t), config(), { secrets: true }));
|
|
61
|
+
assert.ok(out.includes(JWT));
|
|
62
|
+
assert.ok(out.includes(SERVICE));
|
|
63
|
+
assert.ok(out.includes(`#apikey=${SERVICE}`));
|
|
64
|
+
assert.ok(out.includes(ANON));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('old engines (MinIO): the S3 secret key is hidden by default', () => {
|
|
68
|
+
const { storageInfo } = require('../utils/engine');
|
|
69
|
+
const hidden = JSON.stringify(storageInfo(config('0.5.0')));
|
|
70
|
+
assert.ok(!hidden.includes(S3_SECRET));
|
|
71
|
+
assert.ok(JSON.stringify(storageInfo(config('0.5.0'), { secrets: true })).includes(S3_SECRET));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('Keycloak panel: the admin password is hidden by default, test users stay (versioned test set)', (t) => {
|
|
75
|
+
const root = project(t);
|
|
76
|
+
const poadDir = path.dirname(root);
|
|
77
|
+
fs.mkdirSync(path.join(poadDir, 'data', 'keycloak'), { recursive: true });
|
|
78
|
+
fs.writeFileSync(path.join(poadDir, 'data', 'keycloak', 'users.json'), JSON.stringify({ admin_password: KC_ADMIN, signing_key: 'x', client_secret: 'y', ids: { alice: 'id-a' }, passwords: {} }));
|
|
79
|
+
fs.writeFileSync(path.join(poadDir, 'keycloak.json'), JSON.stringify({ realm: 'demo', roles: ['user'], groups: [], users: [{ username: 'alice', email: 'alice@poad.test', password: 'alicepass', emailVerified: true, roles: ['user'], groups: [], attributes: {} }] }));
|
|
80
|
+
const kc = require('../utils/services').SERVICES.find((s) => s.id === 'keycloak');
|
|
81
|
+
const cfg = { ...config(), keycloak: { port: 1 } };
|
|
82
|
+
const hidden = JSON.stringify(kc.info(cfg, root));
|
|
83
|
+
assert.ok(!hidden.includes(KC_ADMIN), 'admin password not printed');
|
|
84
|
+
assert.match(hidden, /hidden · poad info --secrets/);
|
|
85
|
+
assert.ok(hidden.includes('alicepass'), 'test user password shown');
|
|
86
|
+
assert.ok(JSON.stringify(kc.info(cfg, root, { secrets: true })).includes(KC_ADMIN));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('poad info flag: --secrets or secrets', () => {
|
|
90
|
+
const { wantsSecrets } = require('../project/info');
|
|
91
|
+
assert.strictEqual(wantsSecrets({}), false);
|
|
92
|
+
assert.strictEqual(wantsSecrets({ '--secrets': true }), true);
|
|
93
|
+
assert.strictEqual(wantsSecrets({ secrets: true }), true);
|
|
94
|
+
});
|