Test that the session owns its bind state and keeps it through a reconnect's gap

This commit is contained in:
2026-09-28 03:55:40 +02:00
parent b0b7404477
commit ebc5db5a00
4 changed files with 33 additions and 5 deletions
+1 -1
View File
@@ -62,6 +62,6 @@ describe('smppload (blocked)', () => {
await waitFor(() => (closed ? true : undefined), 5000); await waitFor(() => (closed ? true : undefined), 5000);
assert.equal(closed, true); assert.equal(closed, true);
assert.ok(bound); assert.ok(bound);
assert.equal(bound.loggedIn, false); assert.equal(bound.boundAs, undefined);
}); });
}); });
+8 -2
View File
@@ -628,6 +628,10 @@ describe('reconnect', () => {
const reconnected = once<true>(resolve => { session.on('reconnected', () => { resolve(true); }); }); const reconnected = once<true>(resolve => { session.on('reconnected', () => { resolve(true); }); });
const halfPdu = once<true>(resolve => { session.on('data', () => { resolve(true); }); }); const halfPdu = once<true>(resolve => { session.on('data', () => { resolve(true); }); });
const boundBefore = [session.boundAs, session.peerInterfaceVersion];
const whileDown = once<unknown[]>(resolve => {
session.on('disconnected', () => { resolve([session.boundAs, session.peerInterfaceVersion]); });
});
// A PDU header promising 32 octets and sending 8: the next link must not continue it. // A PDU header promising 32 octets and sending 8: the next link must not continue it.
peerOf(smpp).sock.write(Buffer.from([0, 0, 0, 32, 0, 0, 0, 4])); peerOf(smpp).sock.write(Buffer.from([0, 0, 0, 32, 0, 0, 0, 4]));
@@ -640,7 +644,9 @@ describe('reconnect', () => {
await reconnected; await reconnected;
assert.ok(session.loggedIn); // The loop rebinds as before, so the gap keeps answering bindAllows() for the bind to come.
assert.deepEqual(await whileDown, boundBefore);
assert.equal(session.boundAs, 'transceiver');
// The session object survives the drop, so listeners stay attached and it is usable again. // The session object survives the drop, so listeners stay attached and it is usable again.
const sent = await session.sendSms({ const sent = await session.sendSms({
@@ -867,7 +873,7 @@ describe('reconnect from the first bind', () => {
assert.equal(err, undefined); assert.equal(err, undefined);
assert.ok(session); assert.ok(session);
assert.equal(session.loggedIn, true); assert.equal(session.boundAs, 'transceiver');
assert.ok(spy.delays.length >= 3, 'the SMSC was down for several attempts'); assert.ok(spy.delays.length >= 3, 'the SMSC was down for several attempts');
assert.deepEqual(spy.delays.slice(0, 3), [10, 20, 40], 'each wait doubles, up to maxDelay'); assert.deepEqual(spy.delays.slice(0, 3), [10, 20, 40], 'each wait doubles, up to maxDelay');
assert.ok( assert.ok(
+23 -1
View File
@@ -229,7 +229,7 @@ describe('bind', () => {
assert.equal(err, undefined); assert.equal(err, undefined);
assert.ok(session); assert.ok(session);
assert.ok(session.loggedIn); assert.equal(session.boundAs, 'transceiver');
assert.deepEqual(await session.unbind(), {}); assert.deepEqual(await session.unbind(), {});
}); });
@@ -448,6 +448,28 @@ describe('bind', () => {
assert.ok(session.acceptsOptionalParams()); assert.ok(session.acceptsOptionalParams());
}); });
test('records a hand-wired bind through bound(), and nothing else writes it', t => {
const session = new Session({ sock: new net.Socket() });
closeAfter(t, session);
assert.equal(session.boundAs, undefined);
assert.equal(session.peerInterfaceVersion, undefined);
session.bound('receiver', 0x34);
assert.equal(session.boundAs, 'receiver');
assert.equal(session.peerInterfaceVersion, 0x34);
assert.equal(session.bindAllows('submit_sm'), false);
session.bound('transmitter', undefined);
assert.equal(session.peerInterfaceVersion, 0x00, 'no declared version is pre-3.4');
assert.equal(Reflect.set(session, 'boundAs', 'transceiver'), false);
assert.equal(Reflect.set(session, 'peerInterfaceVersion', 0x50), false);
assert.equal(session.boundAs, 'transmitter');
assert.equal('loggedIn' in session, false);
});
// The spec: an absent sc_interface_version means the SMSC supports no optional parameters. // The spec: an absent sc_interface_version means the SMSC supports no optional parameters.
test('takes an SMSC that declares no version as older than 3.4', async t => { test('takes an SMSC that declares no version as older than 3.4', async t => {
const peer = await smscPeer(t); const peer = await smscPeer(t);
+1 -1
View File
@@ -135,7 +135,7 @@ describe('tls', () => {
assert.equal(err, undefined); assert.equal(err, undefined);
assert.ok(session); assert.ok(session);
assert.ok(session.loggedIn); assert.equal(session.boundAs, 'transceiver');
closeAfter(t, session); closeAfter(t, session);
const sock = session.sock; const sock = session.sock;