Cover the guarded address writers, and cut what the code already says
Mirror / push (push) Successful in 5s
Test / lint (pull_request) Successful in 22s
Test / test (18) (pull_request) Successful in 29s
Test / test (20) (pull_request) Successful in 30s
Test / test (22) (pull_request) Successful in 37s
Test / test (24) (pull_request) Successful in 29s
Test / test (26) (pull_request) Successful in 30s
Mirror / push (push) Successful in 5s
Test / lint (pull_request) Successful in 22s
Test / test (18) (pull_request) Successful in 29s
Test / test (20) (pull_request) Successful in 30s
Test / test (22) (pull_request) Successful in 37s
Test / test (24) (pull_request) Successful in 29s
Test / test (26) (pull_request) Successful in 30s
This commit is contained in:
+2
-5
@@ -128,7 +128,6 @@ describe('parsing real PDUs', () => {
|
||||
assert.equal(pduObj.tlvs.message_state?.tagValue, 2);
|
||||
});
|
||||
|
||||
// 'ascii' masks bit 7 on the way in, so this address used to come back Kaffei.
|
||||
test('keeps an alphanumeric sender whole through the wire and back', () => {
|
||||
const pdu = encode({
|
||||
cmdName: 'deliver_sm',
|
||||
@@ -143,12 +142,9 @@ describe('parsing real PDUs', () => {
|
||||
|
||||
assert.ok(pdu.includes(Buffer.from('Kaffeé', 'latin1')));
|
||||
assert.equal(decode(pdu).params.source_addr, 'Kaffeé');
|
||||
assert.ok(objToPdu({ cmdName: 'deliver_sm', params: { source_addr: '一' } }).err instanceof Error);
|
||||
});
|
||||
|
||||
// The peer reads source_addr to the first NULL and every mandatory field behind it shifts, so an
|
||||
// application forwarding a customer's sender id could have a PDU rewritten under it.
|
||||
test('refuses an address carrying its own terminator', () => {
|
||||
test('refuses an address the field cannot carry rather than truncating it', () => {
|
||||
const smuggled = objToPdu({
|
||||
cmdName: 'submit_sm',
|
||||
params: { destination_addr: '46709771337', source_addr: '46701113311\u0000EVIL' },
|
||||
@@ -156,6 +152,7 @@ describe('parsing real PDUs', () => {
|
||||
|
||||
assert.ok(smuggled.err instanceof Error);
|
||||
assert.equal(smuggled.buffer, undefined);
|
||||
assert.ok(objToPdu({ cmdName: 'deliver_sm', params: { source_addr: '一' } }).err instanceof Error);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+11
-8
@@ -84,7 +84,6 @@ describe('string (Octet String)', () => {
|
||||
assert.ok(types.string.write('一', Buffer.alloc(4), 0).err instanceof Error);
|
||||
});
|
||||
|
||||
// Its length octet is what ends it, so unlike a C-Octet String it carries a NULL like any other.
|
||||
test('carries a NULL octet, which its length octet already bounds', () => {
|
||||
const target = Buffer.alloc(4);
|
||||
|
||||
@@ -122,8 +121,6 @@ describe('cstring (C-Octet String)', () => {
|
||||
assert.deepEqual(types.cstring.size(123), { size: 4 });
|
||||
});
|
||||
|
||||
// 'ascii' masks bit 7 on the way in and keeps it on the way out, so an address a peer wrote as
|
||||
// Kaffeé came back Kaffei and objToPdu(pduToObj(x)) stopped being idempotent.
|
||||
test('carries every latin1 octet, and refuses a character past it', () => {
|
||||
const address = Buffer.from([0x4B, 0x61, 0x66, 0x66, 0x65, 0xE9, 0x00]);
|
||||
const target = Buffer.alloc(7);
|
||||
@@ -136,9 +133,6 @@ describe('cstring (C-Octet String)', () => {
|
||||
assert.ok(types.cstring.write('一', Buffer.alloc(4), 0).err instanceof Error);
|
||||
});
|
||||
|
||||
// The field ends at its first NULL, so writing one smuggles a field boundary into the peer's
|
||||
// parse: every mandatory field behind it shifts, under a command_length that counted the whole
|
||||
// string.
|
||||
test('refuses a NULL of its own rather than ending the field early', () => {
|
||||
assert.ok(types.cstring.size('46701113311\u0000EVIL').err instanceof Error);
|
||||
assert.ok(types.cstring.write('46701113311\u0000EVIL', Buffer.alloc(17), 0).err instanceof Error);
|
||||
@@ -252,8 +246,6 @@ describe('buffer', () => {
|
||||
});
|
||||
|
||||
describe('paramText()', () => {
|
||||
// The one reader of a receipt body that arrived with no octets of its own, so masking bit 7
|
||||
// here loses the same characters the wire types used to.
|
||||
test('renders a Buffer parameter as the latin1 text its octets spell', () => {
|
||||
assert.equal(paramText(Buffer.from([0x4B, 0x61, 0x66, 0x66, 0x65, 0xE9])), 'Kaffeé');
|
||||
});
|
||||
@@ -293,6 +285,11 @@ describe('dest_address_array', () => {
|
||||
types.dest_address_array.write(expected, target, 0);
|
||||
|
||||
assert.deepEqual(target, encoded);
|
||||
|
||||
const smuggled: DestAddress[] = [{ dest_addr_npi: 1, dest_addr_ton: 1, destination_addr: '46\u0000EVIL' }];
|
||||
|
||||
assert.ok(types.dest_address_array.write(smuggled, Buffer.alloc(16), 0).err instanceof Error);
|
||||
assert.ok(types.dest_address_array.write([{ dl_name: '一' }], Buffer.alloc(16), 0).err instanceof Error);
|
||||
});
|
||||
|
||||
test('refuses a field value the wire cannot hold instead of throwing', () => {
|
||||
@@ -332,6 +329,12 @@ describe('unsuccess_sme_array', () => {
|
||||
types.unsuccess_sme_array.write(expected, target, 0);
|
||||
|
||||
assert.deepEqual(target, encoded);
|
||||
|
||||
const smuggled: UnsuccessSme[] = [
|
||||
{ dest_addr_npi: 1, dest_addr_ton: 1, destination_addr: 'a\u0000b', error_status_code: 0 },
|
||||
];
|
||||
|
||||
assert.ok(types.unsuccess_sme_array.write(smuggled, Buffer.alloc(16), 0).err instanceof Error);
|
||||
});
|
||||
|
||||
test('refuses a field value the wire cannot hold instead of throwing', () => {
|
||||
|
||||
@@ -345,6 +345,30 @@ describe('a body the PDU\'s own data_coding cannot carry', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('an address the field cannot carry', () => {
|
||||
test('refuses it through sendSms(), with nothing reaching the socket', async t => {
|
||||
const smsc = await dummySmsc(t);
|
||||
const session = await bindToSmsc(t, smsc.port, { reconnect: false });
|
||||
|
||||
const refusals: [string, RegExp][] = [
|
||||
['46701113311\u0000EVIL', /U\+0000 at index 11/],
|
||||
['Kaffe一', /U\+4E00 at index 5/],
|
||||
['😀', /U\+1F600 at index 0/],
|
||||
];
|
||||
|
||||
for (const [sender, names] of refusals) {
|
||||
const sent = await session.sendSms({ from: sender, message: 'Hello world', to });
|
||||
|
||||
assert.ok(sent.err instanceof Error, sender);
|
||||
assert.match(sent.err.message, /source_addr/);
|
||||
assert.match(sent.err.message, names);
|
||||
assert.deepEqual(sent.smsIds, [], sender);
|
||||
}
|
||||
|
||||
assert.deepEqual(smsc.octets, [], 'an address the field cannot carry never reaches the socket');
|
||||
});
|
||||
});
|
||||
|
||||
describe('a time no peer can read', () => {
|
||||
const invalid = new Date('nope');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user