fix: support internal AgentBus attachments
This commit is contained in:
1 parent
cd45ce17d0
commit
161f90d09d
12 files changed
+96
-86
No files matched your search
@@ -6,8 +6,8 @@ import {
|
||||
InputAttachmentError,
|
||||
decodeInlineInputAttachment,
|
||||
downloadAgentBusInputAttachment,
|
||||
isPrivateOrReservedIp,
|
||||
parseAgentBusInputAttachment,
|
||||
resolveAgentBusAttachmentAddresses,
|
||||
validateAgentBusAttachmentUrl
|
||||
} from '../src/input-attachment.js';
|
||||
|
||||
@@ -46,26 +46,23 @@ test('manual roster attachment rejects unsupported names, invalid base64 and mis
|
||||
}, 1_000)), 'roster_file_sha256_mismatch');
|
||||
});
|
||||
|
||||
test('AgentBus attachment URLs require public HTTPS endpoints', () => {
|
||||
test('AgentBus attachment URLs allow private HTTPS endpoints but reject unsafe URL syntax', () => {
|
||||
for (const value of [
|
||||
'http://files.example.test/list.xlsx',
|
||||
'https://localhost/list.xlsx',
|
||||
'https://127.0.0.1/list.xlsx',
|
||||
'https://10.0.0.8/list.xlsx',
|
||||
'https://[::1]/list.xlsx',
|
||||
'ftp://files.example.test/list.xlsx',
|
||||
'https://user:secret@files.example.test/list.xlsx'
|
||||
]) {
|
||||
assert.equal(codeOf(() => validateAgentBusAttachmentUrl(value)), 'roster_attachment_url_unsafe');
|
||||
}
|
||||
assert.equal(validateAgentBusAttachmentUrl('https://files.example.com/list.xlsx').protocol, 'https:');
|
||||
});
|
||||
|
||||
test('private and documentation address ranges are rejected', () => {
|
||||
for (const address of ['0.0.0.1', '10.1.2.3', '100.64.0.1', '127.0.0.1', '169.254.1.1', '172.31.0.1', '192.168.1.1', '198.51.100.1', '203.0.113.8', '::1', 'fc00::1', 'fe80::1', '2001:db8::1']) {
|
||||
assert.equal(isPrivateOrReservedIp(address), true, address);
|
||||
for (const value of [
|
||||
'https://files.example.com/list.xlsx',
|
||||
'https://localhost/list.xlsx',
|
||||
'https://127.0.0.1/list.xlsx',
|
||||
'https://10.0.0.8/list.xlsx',
|
||||
'https://[::1]/list.xlsx'
|
||||
]) {
|
||||
assert.equal(validateAgentBusAttachmentUrl(value).protocol, 'https:', value);
|
||||
}
|
||||
assert.equal(isPrivateOrReservedIp('8.8.8.8'), false);
|
||||
assert.equal(isPrivateOrReservedIp('2606:4700:4700::1111'), false);
|
||||
});
|
||||
|
||||
test('AgentBus attachment metadata is normalized without exposing URL credentials', () => {
|
||||
@@ -81,6 +78,18 @@ test('AgentBus attachment metadata is normalized without exposing URL credential
|
||||
assert.equal(reference.sha256, 'a'.repeat(64));
|
||||
});
|
||||
|
||||
test('AgentBus attachment DNS accepts internal names and private literal addresses', async () => {
|
||||
assert.deepEqual(await resolveAgentBusAttachmentAddresses('10.0.0.8'), [
|
||||
{ address: '10.0.0.8', family: 4 }
|
||||
]);
|
||||
assert.deepEqual(await resolveAgentBusAttachmentAddresses('fd00::8'), [
|
||||
{ address: 'fd00::8', family: 6 }
|
||||
]);
|
||||
const localhost = await resolveAgentBusAttachmentAddresses('localhost');
|
||||
assert.ok(localhost.length > 0);
|
||||
assert.ok(localhost.every((entry) => entry.family === 4 || entry.family === 6));
|
||||
});
|
||||
|
||||
test('AgentBus attachment diagnostics expose stages and codes without URL data', async () => {
|
||||
const events: Array<{ event: string; metadata: Record<string, unknown> }> = [];
|
||||
await assert.rejects(
|
||||
@@ -88,7 +97,7 @@ test('AgentBus attachment diagnostics expose stages and codes without URL data',
|
||||
name: 'synthetic.xls',
|
||||
contentType: 'application/vnd.ms-excel',
|
||||
size: 128,
|
||||
url: 'https://127.0.0.1/private-roster.xls?token=secret'
|
||||
url: 'https://user:secret@127.0.0.1/private-roster.xls?token=secret'
|
||||
}, 1_000, (event, metadata) => events.push({ event, metadata })),
|
||||
(error: unknown) => error instanceof InputAttachmentError
|
||||
&& error.code === 'roster_attachment_url_unsafe'
|
||||
|
||||
Reference in new issue
Block a user