Leave an unknown notation alone and read a receipt's TLV as the id the submit answered

This commit is contained in:
2026-08-30 23:01:39 +02:00
parent 696e018b77
commit 706b61d6ca
11 changed files with 70 additions and 39 deletions
+14 -7
View File
@@ -208,28 +208,35 @@ describe('dlrFromPdu()', () => {
});
test('reads the id in the notation the peer writes receipts in', () => {
const hex = dlrFromPdu(deliverSm('id:1a2B stat:DELIVRD err:000 text:'), 'hex');
const hex = dlrFromPdu(deliverSm('id:1a2B stat:DELIVRD err:000 text:'), { receipt: 'hex' });
assert.ok(hex);
assert.equal(hex.smsId, '6699');
assert.equal(hex.receipt?.id, '1a2B', 'the receipt itself keeps the id as it arrived');
assert.equal(dlrFromPdu(deliverSm('id:0000123 stat:DELIVRD'), 'decimal')?.smsId, '123');
assert.equal(dlrFromPdu(deliverSm('nothing scrapable here', {
assert.equal(dlrFromPdu(deliverSm('id:0000123 stat:DELIVRD'), { receipt: 'decimal' })?.smsId, '123');
});
// SMPP 3.4 5.3.2.26 makes the TLV the id the submit_sm_resp carried, not the body's rendering.
test('reads the receipted_message_id TLV in the notation the peer answers a submit in', () => {
const marked = deliverSm('nothing scrapable here', {
receipted_message_id: { tagValue: 'FF' },
}, 0), 'hex')?.smsId, '255');
}, 0);
assert.equal(dlrFromPdu(marked, { submitResp: 'hex' })?.smsId, '255');
assert.equal(dlrFromPdu(marked, { receipt: 'hex' })?.smsId, 'FF');
});
test('leaves an id the notation cannot read as it arrived', () => {
assert.equal(dlrFromPdu(deliverSm('id:beef-1 stat:DELIVRD'), 'hex')?.smsId, 'beef-1');
assert.equal(dlrFromPdu(deliverSm('id:1a2b stat:DELIVRD'), 'decimal')?.smsId, '1a2b');
assert.equal(dlrFromPdu(deliverSm('id:beef-1 stat:DELIVRD'), { receipt: 'hex' })?.smsId, 'beef-1');
assert.equal(dlrFromPdu(deliverSm('id:1a2b stat:DELIVRD'), { receipt: 'decimal' })?.smsId, '1a2b');
assert.equal(dlrFromPdu(deliverSm('id:0195f0c7 stat:DELIVRD'))?.smsId, '0195f0c7');
});
// Number() reads 9007199254740993 as ...92, which correlates a receipt to the wrong send.
test('reads an id past the safe integer range without losing a digit', () => {
assert.equal(
dlrFromPdu(deliverSm('id:9007199254740993 stat:DELIVRD'), 'decimal')?.smsId,
dlrFromPdu(deliverSm('id:9007199254740993 stat:DELIVRD'), { receipt: 'decimal' })?.smsId,
'9007199254740993',
);
});
+16 -5
View File
@@ -79,7 +79,7 @@ function peerOf(smpp: SmppServer): Session {
return peer;
}
async function sendReceipt(peer: Session, smsId: string): Promise<void> {
async function sendReceipt(peer: Session, smsId: string, tlvSmsId = smsId): Promise<void> {
const sent = await peer.send({
cmdName: 'deliver_sm',
params: {
@@ -90,7 +90,7 @@ async function sendReceipt(peer: Session, smsId: string): Promise<void> {
},
tlvs: {
message_state: { tagValue: consts.MESSAGE_STATE.DELIVERED },
receipted_message_id: { tagValue: smsId },
receipted_message_id: { tagValue: tlvSmsId },
},
});
@@ -831,15 +831,21 @@ describe('message id notation', () => {
assert.ok(session);
const reported = once<Dlr>(resolve => { session.on('dlr', resolve); });
const reported = once<[Dlr, PduObject]>(resolve => {
session.on('dlr', (dlr, pduObj) => { resolve([dlr, pduObj]); });
});
const sent = await sendOne(session, 'one segment');
assert.deepEqual(sent.smsIds, ['6699']);
assert.equal(paramText(sent.pduObjs[0]?.params.message_id), '1a2b', 'the PDU keeps the id it carried');
await sendReceipt(peerOf(smpp), '6699');
// The receipt renders the id in decimal and mirrors the answered one in its TLV, as the spec has it.
await sendReceipt(peerOf(smpp), '6699', '1a2b');
assert.equal((await reported).smsId, sent.smsIds[0]);
const [dlr, pduObj] = await reported;
assert.equal(dlr.smsId, sent.smsIds[0]);
assert.equal(paramText(pduObj.tlvs.receipted_message_id?.tagValue), '1a2b');
});
test('leaves the segment ids of a multipart send to merge as they are', async t => {
@@ -874,6 +880,11 @@ describe('message id notation', () => {
assert.match(checked.err.message, /smsIdFormat\.receipt/);
// The shape todo.md sketched, which a caller without types would otherwise pass unnoticed.
assert.ok(checkSessionOptions({ smsIdFormat: 'hex' }).err instanceof Error);
assert.match(
checkSessionOptions({ smsIdFormat: { receipts: 'decimal' } }).err?.message ?? '',
/receipts/,
'a misspelled place is the same silent no-op',
);
assert.equal(checkSessionOptions({ smsIdFormat: { submitResp: 'hex' } }).err, undefined);
});
});