Stranger pass of 21 Oct: .gitignore for node_modules and the keys the examples write, Maven and Action rows in the table, one install line, temporary directories removed by the tests
This commit is contained in:
1 parent
c1909c2afb
commit
c3b3d99640
6 files changed
+51
-26
No files matched your search
@@ -7,11 +7,16 @@ import path from 'node:path';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { attest, verify, buildStatement, packNpmFromTree } from '../pos.mjs';
|
||||
import * as pq from '../../../sdk-pq-sign/index.mjs';
|
||||
// 2026-10-21 (the stranger pass): every temporary directory of this test is remembered and removed when the process exits, on every
|
||||
// path (the end, an exception, process.exit); until then each run left its directories in TEMP
|
||||
const facute = [];
|
||||
const tmp = (p) => { const d = fs.mkdtempSync(path.join(os.tmpdir(), p)); facute.push(d); return d; };
|
||||
process.on('exit', () => { for (const d of facute) { try { fs.rmSync(d, { recursive: true, force: true, maxRetries: 3 }); } catch { /* left for the system */ } } });
|
||||
|
||||
let treceri = 0; const esecuri = [];
|
||||
async function test(nume, fn) { try { await fn(); treceri++; console.log(' OK ' + nume); } catch (e) { esecuri.push(nume); console.log(' ESEC ' + nume + ' — ' + (e.message || e)); } }
|
||||
|
||||
const D = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-'));
|
||||
const D = tmp('aere-pos-');
|
||||
const A = path.join(D, 'app.tgz'), B = path.join(D, 'app.sha'), S = path.join(D, 'sbom.json');
|
||||
fs.writeFileSync(A, Buffer.from('binary artifact bytes 12345')); fs.writeFileSync(B, 'checksums'); fs.writeFileSync(S, JSON.stringify({ bomFormat: 'CycloneDX', components: [] }));
|
||||
const keys = pq.generateKeyPair({ alg: 'secp256k1+ml-dsa-65' });
|
||||
@@ -22,7 +27,7 @@ await test('statement: artifacts with sha256 + size, sbom hashed, builder, time'
|
||||
assert.strictEqual(s.sbom.name, 'sbom.json'); assert.strictEqual(s.subject.version, '1.0.0'); assert.ok(s.createdAt);
|
||||
});
|
||||
await test('two artifacts with the same name are refused (verification matches by name)', () => {
|
||||
const D2 = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-')); fs.mkdirSync(path.join(D2, 'x')); fs.writeFileSync(path.join(D2, 'x', 'app.tgz'), 'a');
|
||||
const D2 = tmp('aere-pos-'); fs.mkdirSync(path.join(D2, 'x')); fs.writeFileSync(path.join(D2, 'x', 'app.tgz'), 'a');
|
||||
assert.throws(() => buildStatement({ artifacts: [A, path.join(D2, 'x', 'app.tgz')], cwd: D }), /share the name/);
|
||||
});
|
||||
|
||||
@@ -69,14 +74,14 @@ await test('CLI: keygen, attest, verify round trip through files; tampered file
|
||||
});
|
||||
|
||||
// ---- legarea de ARBORELE git si verificarea prin RECONSTRUCTIE (1.1.0). Un depozit de proba cu un pachet npm mic.
|
||||
const G = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-git-'));
|
||||
const G = tmp('aere-pos-git-');
|
||||
const g = (args, cwd = G) => execFileSync('git', ['-c', 'core.autocrlf=false', '-c', 'user.name=proba', '-c', '[email protected]', ...args], { cwd, stdio: 'pipe' }).toString().trim();
|
||||
g(['init', '-q']); fs.mkdirSync(path.join(G, 'pkg', 'lib'), { recursive: true }); fs.mkdirSync(path.join(G, 'altceva'));
|
||||
fs.writeFileSync(path.join(G, 'pkg', 'package.json'), JSON.stringify({ name: 'proba-pos', version: '0.0.1', main: 'lib/index.js', files: ['lib', 'LICENSE'] }, null, 1) + '\n');
|
||||
fs.writeFileSync(path.join(G, 'pkg', 'lib', 'index.js'), 'module.exports = 1;\n'); fs.writeFileSync(path.join(G, 'pkg', 'LICENSE'), 'line one\nline two\n');
|
||||
fs.writeFileSync(path.join(G, 'altceva', 'x.txt'), 'nu face parte din pachet\n');
|
||||
g(['add', '-A']); g(['commit', '-q', '-m', 'pachet de proba']);
|
||||
const OUT1 = path.join(G, '..', path.basename(G) + '-out'); fs.mkdirSync(OUT1);
|
||||
const OUT1 = path.join(G, '..', path.basename(G) + '-out'); fs.mkdirSync(OUT1); facute.push(OUT1);
|
||||
const TGZ = packNpmFromTree(G, 'HEAD:pkg', OUT1);
|
||||
|
||||
await test('source tree: --source-path records path, tree and pathDirty; build records npm-pack and the npm version', () => {
|
||||
@@ -86,13 +91,13 @@ await test('source tree: --source-path records path, tree and pathDirty; build r
|
||||
assert.throws(() => buildStatement({ artifacts: [TGZ], sourcePath: 'nu-exista', cwd: G }), /not tracked at HEAD/);
|
||||
});
|
||||
await test('the listing of a tree does not depend on the directory it is asked from (ls-tree --full-tree)', () => {
|
||||
const o = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-sub-'));
|
||||
const o = tmp('aere-pos-sub-');
|
||||
const t2 = packNpmFromTree(path.join(G, 'altceva'), 'HEAD:pkg', o);
|
||||
assert.strictEqual(fs.readFileSync(t2).equals(fs.readFileSync(TGZ)), true, 'same tree asked from a subdirectory gave other bytes');
|
||||
});
|
||||
await test('the artifact is a function of the COMMITTED tree: CRLF in the working copy changes a working-copy pack, not this one', () => {
|
||||
fs.writeFileSync(path.join(G, 'pkg', 'LICENSE'), 'line one\r\nline two\r\n');
|
||||
const o = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-crlf-'));
|
||||
const o = tmp('aere-pos-crlf-');
|
||||
const again = packNpmFromTree(G, 'HEAD:pkg', o);
|
||||
assert.strictEqual(fs.readFileSync(again).equals(fs.readFileSync(TGZ)), true);
|
||||
const wc = execFileSync('npm pack --silent --pack-destination "' + o + '"', { cwd: path.join(G, 'pkg'), shell: true, stdio: 'pipe' }).toString().trim().split(/\r?\n/).pop();
|
||||
@@ -102,7 +107,7 @@ await test('the artifact is a function of the COMMITTED tree: CRLF in the workin
|
||||
});
|
||||
const attG = await attest({ artifacts: [TGZ], name: 'proba-pos', version: '0.0.1', sourcePath: 'pkg', build: 'npm-pack', keys, cwd: G });
|
||||
await test('verify --rebuild-from: a clone chosen by the verifier reproduces the attested artifact byte for byte', async () => {
|
||||
const C = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-clona-')); g(['clone', '-q', G, C], os.tmpdir());
|
||||
const C = tmp('aere-pos-clona-'); g(['clone', '-q', G, C], os.tmpdir());
|
||||
const r = await verify(attG, [TGZ], { rebuildFrom: C });
|
||||
assert.strictEqual(r.valid, true, JSON.stringify(r.checks));
|
||||
assert.ok(r.checks.find((c) => c.name.startsWith('rebuild: npm pack of the attested tree reproduces') && c.pass === true));
|
||||
@@ -110,7 +115,7 @@ await test('verify --rebuild-from: a clone chosen by the verifier reproduces the
|
||||
});
|
||||
await test('an artifact that did NOT come from the attested tree fails the rebuild (digest differs), though its own digest matches', async () => {
|
||||
fs.writeFileSync(path.join(G, 'pkg', 'lib', 'index.js'), 'module.exports = 2; // schimbat si necomis\n');
|
||||
const o = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-strain-'));
|
||||
const o = tmp('aere-pos-strain-');
|
||||
const wc = execFileSync('npm pack --silent --pack-destination "' + o + '"', { cwd: path.join(G, 'pkg'), shell: true, stdio: 'pipe' }).toString().trim().split(/\r?\n/).pop();
|
||||
const strain = path.join(o, wc);
|
||||
const a = await attest({ artifacts: [strain], sourcePath: 'pkg', build: 'npm-pack', cwd: G });
|
||||
@@ -121,7 +126,7 @@ await test('an artifact that did NOT come from the attested tree fails the rebui
|
||||
g(['checkout', '-q', '--', 'pkg/lib/index.js']);
|
||||
});
|
||||
await test('a clone that does not hold the attested commit fails on the SOURCE check, before any build', async () => {
|
||||
const E = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-gol-')); g(['init', '-q'], E); fs.writeFileSync(path.join(E, 'a'), 'a'); g(['add', '-A'], E); g(['commit', '-q', '-m', 'alt depozit'], E);
|
||||
const E = tmp('aere-pos-gol-'); g(['init', '-q'], E); fs.writeFileSync(path.join(E, 'a'), 'a'); g(['add', '-A'], E); g(['commit', '-q', '-m', 'alt depozit'], E);
|
||||
const r = await verify(attG, [TGZ], { rebuildFrom: E }); assert.strictEqual(r.valid, false);
|
||||
assert.ok(r.checks.find((c) => c.name.startsWith('source:') && c.pass === false && /not in this clone/.test(c.detail)));
|
||||
assert.ok(!r.checks.find((c) => c.name.startsWith('rebuild: npm pack')), 'no build was attempted');
|
||||
|
||||
@@ -7,6 +7,11 @@ import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { attest, verify, packNpmFromTree, sbomSemantica, sbomNpmFromTree } from '../pos.mjs';
|
||||
// 2026-10-21 (the stranger pass): every temporary directory of this test is remembered and removed when the process exits, on every
|
||||
// path (the end, an exception, process.exit); until then each run left its directories in TEMP
|
||||
const facute = [];
|
||||
const tmp = (p) => { const d = fs.mkdtempSync(path.join(os.tmpdir(), p)); facute.push(d); return d; };
|
||||
process.on('exit', () => { for (const d of facute) { try { fs.rmSync(d, { recursive: true, force: true, maxRetries: 3 }); } catch { /* left for the system */ } } });
|
||||
|
||||
let treceri = 0; const esecuri = [];
|
||||
async function test(nume, fn) { try { await fn(); treceri++; console.log(' OK ' + nume); } catch (e) { esecuri.push(nume); console.log(' ESEC ' + nume + ' — ' + (e.message || e)); } }
|
||||
@@ -14,7 +19,7 @@ const cere = (c, m) => { if (!c) throw new Error(m); };
|
||||
const g = (args, cwd) => execFileSync('git', args, { cwd, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
|
||||
const check = (r, re) => r.checks.find((c) => re.test(c.name));
|
||||
|
||||
const G = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-sbom-g-'));
|
||||
const G = tmp('aere-pos-sbom-g-');
|
||||
g(['init', '-q'], G); g(['config', 'user.email', '[email protected]'], G); g(['config', 'user.name', 'proba'], G); g(['config', 'core.autocrlf', 'false'], G);
|
||||
const P = path.join(G, 'pkg'); fs.mkdirSync(path.join(P, 'lib'), { recursive: true });
|
||||
fs.writeFileSync(path.join(P, 'package.json'), JSON.stringify({ name: 'proba-sbom', version: '0.1.0', license: 'MIT', main: 'lib/index.js', dependencies: { 'dep-a': '1.0.0', 'dep-b': '2.0.0' } }, null, 2) + '\n');
|
||||
@@ -34,9 +39,9 @@ fs.writeFileSync(path.join(P, 'package-lock.json'), JSON.stringify(lock, null, 2
|
||||
fs.mkdirSync(path.join(G, 'fara'), { recursive: true });
|
||||
fs.writeFileSync(path.join(G, 'fara', 'package.json'), JSON.stringify({ name: 'fara-lock', version: '0.0.1', license: 'MIT' }) + '\n');
|
||||
g(['add', '-A'], G); g(['commit', '-q', '-m', 'pachet de proba'], G);
|
||||
const C = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-sbom-c-')); g(['clone', '-q', G, C], os.tmpdir());
|
||||
const C = tmp('aere-pos-sbom-c-'); g(['clone', '-q', G, C], os.tmpdir());
|
||||
|
||||
const OUT = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-sbom-o-'));
|
||||
const OUT = tmp('aere-pos-sbom-o-');
|
||||
const TGZ = packNpmFromTree(G, 'HEAD:pkg', OUT);
|
||||
const scrieSbom = (nume, bom) => { const f = path.join(OUT, nume); fs.writeFileSync(f, JSON.stringify(bom, null, 2)); return f; };
|
||||
const r1 = sbomNpmFromTree(G, 'HEAD:pkg'); const r2 = sbomNpmFromTree(G, 'HEAD:pkg');
|
||||
@@ -60,7 +65,7 @@ await test('un SBOM regenerat (alt numar de serie, alt timp) si re-atestat trece
|
||||
});
|
||||
async function editat(nume, schimba) {
|
||||
const bom = JSON.parse(JSON.stringify(r1.bom)); schimba(bom);
|
||||
const d = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-sbom-e-')); const f = path.join(d, 'proba-sbom.sbom.cdx.json'); fs.writeFileSync(f, JSON.stringify(bom, null, 2));
|
||||
const d = tmp('aere-pos-sbom-e-'); const f = path.join(d, 'proba-sbom.sbom.cdx.json'); fs.writeFileSync(f, JSON.stringify(bom, null, 2));
|
||||
const a = await attest({ artifacts: [TGZ], sbom: f, name: 'proba-sbom', version: '0.1.0', sourcePath: 'pkg', build: 'npm-pack', cwd: G });
|
||||
const simplu = await verify(a, [TGZ, f]);
|
||||
const r = await verify(a, [TGZ, f], { rebuildFrom: C });
|
||||
@@ -76,7 +81,7 @@ async function deAltFel(din) {
|
||||
const bom = JSON.parse(JSON.stringify(r1.bom));
|
||||
bom.components = bom.components.filter((c) => !/dep-c/.test(c.name));
|
||||
bom.metadata.properties = [...(bom.metadata.properties || []), { name: 'aere:derived-from', value: din }];
|
||||
const d = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-sbom-e-')); const f = path.join(d, 'proba-sbom.sbom.cdx.json'); fs.writeFileSync(f, JSON.stringify(bom, null, 2));
|
||||
const d = tmp('aere-pos-sbom-e-'); const f = path.join(d, 'proba-sbom.sbom.cdx.json'); fs.writeFileSync(f, JSON.stringify(bom, null, 2));
|
||||
const a = await attest({ artifacts: [TGZ], sbom: f, name: 'proba-sbom', version: '0.1.0', sourcePath: 'pkg', build: 'npm-pack', cwd: G });
|
||||
const r = await verify(a, [TGZ, f], { rebuildFrom: C }); fs.rmSync(d, { recursive: true, force: true });
|
||||
const rand = check(r, /file the attested SBOM says it was derived from is in the committed tree/);
|
||||
@@ -88,7 +93,7 @@ await test('CONTROL B-21: un SBOM npm editat care numeste un fisier AL arborelui
|
||||
const bom = JSON.parse(JSON.stringify(r1.bom));
|
||||
bom.components = bom.components.filter((c) => !/dep-c/.test(c.name));
|
||||
bom.metadata.properties = [...(bom.metadata.properties || []), { name: 'aere:derived-from', value: 'package.json' }];
|
||||
const d = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-pos-sbom-e-')); const f = path.join(d, 'proba-sbom.sbom.cdx.json'); fs.writeFileSync(f, JSON.stringify(bom, null, 2));
|
||||
const d = tmp('aere-pos-sbom-e-'); const f = path.join(d, 'proba-sbom.sbom.cdx.json'); fs.writeFileSync(f, JSON.stringify(bom, null, 2));
|
||||
const a = await attest({ artifacts: [TGZ], sbom: f, name: 'proba-sbom', version: '0.1.0', sourcePath: 'pkg', build: 'npm-pack', cwd: G });
|
||||
const r = await verify(a, [TGZ, f], { rebuildFrom: C }); fs.rmSync(d, { recursive: true, force: true });
|
||||
cere(!r.valid && check(r, /attested SBOM says what the committed lockfile says/) && check(r, /attested SBOM says/).pass === false, JSON.stringify(r.checks.filter((c) => c.pass !== true)));
|
||||
|
||||
Reference in new issue
Block a user