24 lines
1.5 KiB
JavaScript
24 lines
1.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { consoleCall } from '../src/bus.mjs';
|
|
import { CONSOLE_VERBS } from '../../bus/src/broker.mjs';
|
|
|
|
test('only the artifact Console verb permits a full 2 MiB response, and oversized output is refused', async t => {
|
|
const root = mkdtempSync(join(tmpdir(), 'artifact-transport-')); t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
const cli = join(root, 'console.mjs');
|
|
writeFileSync(cli, `import {readFileSync} from 'node:fs';const {args}=JSON.parse(readFileSync(0,'utf8'));process.stdout.write(JSON.stringify('x'.repeat(args.bytes)));`);
|
|
const call = consoleCall({ dataRoot: root, socket: 'fake', business: 'demo', cli, timeoutMs: 15000 });
|
|
const subject = { provider: 'test', iss: 'test', sub: 'owner' };
|
|
const artifact = 'request.artifact.console', max = 2 * 1024 * 1024;
|
|
assert.ok(CONSOLE_VERBS.includes(artifact));
|
|
assert.equal((await call(artifact, { bytes: max - 2 }, { subject })).length, max - 2);
|
|
await assert.rejects(call(artifact, { bytes: max - 1 }, { subject }), { code: 'response-too-large' });
|
|
for (const verb of CONSOLE_VERBS.filter(v => v !== artifact)) {
|
|
assert.equal((await call(verb, { bytes: 1024 * 1024 - 2 }, { subject })).length, 1024 * 1024 - 2, verb);
|
|
await assert.rejects(call(verb, { bytes: 1024 * 1024 - 1 }, { subject }), { code: 'response-too-large' }, verb);
|
|
}
|
|
});
|