var to let or const, better lints, code style and more
This commit is contained in:
+249
-249
@@ -1,41 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
var larvitsmpp = require('../larvitsmpp'),
|
||||
portfinder = require('portfinder'),
|
||||
assert = require('assert'),
|
||||
net = require('net');
|
||||
const larvitsmpp = require(__dirname + '/../index.js'),
|
||||
portfinder = require('portfinder'),
|
||||
assert = require('assert'),
|
||||
net = require('net');
|
||||
|
||||
// Very advanced auth system
|
||||
function checkuserpass(username, password, callback) {
|
||||
function checkuserpass(username, password, cb) {
|
||||
if (username === 'foo' && password === 'bar') {
|
||||
callback(null, true);
|
||||
cb(null, true);
|
||||
} else {
|
||||
callback(null, false);
|
||||
cb(null, false);
|
||||
}
|
||||
}
|
||||
|
||||
describe('Sessions', function() {
|
||||
describe('Sessions', function () {
|
||||
this.slow(200);
|
||||
|
||||
it('should setup a basic server and client and then directly unbinding again', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should setup a basic server and client and then directly unbinding again', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -45,17 +45,17 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should setup a server with auth and client trying to connect with wrong username and password', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should setup a server with auth and client trying to connect with wrong username and password', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort,
|
||||
'checkuserpass': checkuserpass
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort,
|
||||
'checkuserpass': checkuserpass
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -63,7 +63,7 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err) {
|
||||
}, function (err) {
|
||||
assert(err, 'Error should be set since login should have failed');
|
||||
|
||||
done();
|
||||
@@ -71,28 +71,28 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should setup a server with auth and client trying to connect with correct username and password', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should setup a server with auth and client trying to connect with correct username and password', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort,
|
||||
'checkuserpass': checkuserpass
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort,
|
||||
'checkuserpass': checkuserpass
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort,
|
||||
'username': 'foo',
|
||||
'password': 'bar'
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort,
|
||||
'username': 'foo',
|
||||
'password': 'bar'
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -102,54 +102,54 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should try sending a simple sms', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should try sending a simple sms', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2343;
|
||||
|
||||
assert(sms.from === 'foo', 'SMS from should be "foo"');
|
||||
assert(sms.to === '46709771337', 'SMS to should be "46709771337"');
|
||||
assert(sms.message === 'hello world', 'SMS message should be "hello world"');
|
||||
assert(sms.dlr === false, 'DLR should be boolean false');
|
||||
assert(sms.pduObjs[0].pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||
assert.strictEqual(sms.from, 'foo');
|
||||
assert.strictEqual(sms.to, '46709771337');
|
||||
assert.strictEqual(sms.message, 'hello world');
|
||||
assert.strictEqual(sms.dlr, false);
|
||||
assert.strictEqual(sms.pduObjs[0].pduObj.cmdId, 4);
|
||||
|
||||
sms.sendResp(function(err, retPdus) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err, retPdus) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPdus[0].toString('hex') === '000000158000000400000000000000023233343300', 'The return PDU should be "000000158000000400000000000000023233343300"');
|
||||
assert.strictEqual(retPdus[0].toString('hex'), '000000158000000400000000000000023233343300');
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.sendSms({
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'hello world'
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'hello world'
|
||||
}, function (err, smsIds, retPduObjs) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2343', 'Given smsId should be "2343"');
|
||||
assert(retPduObjs instanceof Array, 'retPduObjs should be an Array');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(retPduObjs instanceof Array, 'retPduObjs should be an Array');
|
||||
assert.strictEqual(smsIds[0], '2343');
|
||||
assert.strictEqual(retPduObjs[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[0].cmdName, 'submit_sm_resp');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -160,62 +160,62 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should try sending a long sms', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should try sending a long sms', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
sms.smsId = 2343;
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2343;
|
||||
|
||||
assert(sms.from === 'foo', 'SMS from should be "foo"');
|
||||
assert(sms.to === '46709771337', 'SMS to should be "46709771337"');
|
||||
assert(sms.message === 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.', 'SMS message should be correct');
|
||||
assert(sms.dlr === false, 'DLR should be boolean false');
|
||||
assert(sms.pduObjs[0].pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||
assert.strictEqual(sms.from, 'foo');
|
||||
assert.strictEqual(sms.to, '46709771337');
|
||||
assert.strictEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.');
|
||||
assert.strictEqual(sms.dlr, false);
|
||||
assert.strictEqual(sms.pduObjs[0].pduObj.cmdId, 4);
|
||||
|
||||
sms.sendResp(function(err, retPdus) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err, retPdus) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPdus[0].toString('hex') === '00000017800000040000000000000002323334332d3100', 'Return PDU 0 is wrong');
|
||||
assert(retPdus[1].toString('hex') === '00000017800000040000000000000003323334332d3200', 'Return PDU 1 is wrong');
|
||||
assert(retPdus[2].toString('hex') === '00000017800000040000000000000004323334332d3300', 'Return PDU 2 is wrong');
|
||||
assert.strictEqual(retPdus[0].toString('hex'), '00000017800000040000000000000002323334332d3100');
|
||||
assert.strictEqual(retPdus[1].toString('hex'), '00000017800000040000000000000003323334332d3200');
|
||||
assert.strictEqual(retPdus[2].toString('hex'), '00000017800000040000000000000004323334332d3300');
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.sendSms({
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.'
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.'
|
||||
}, function (err, smsIds, retPduObjs) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2343-1', 'First smsId should be "2343-1"');
|
||||
assert(smsIds[1] === '2343-2', 'Second smsId should be "2343-2"');
|
||||
assert(smsIds[2] === '2343-3', 'Third smsId should be "2343-3"');
|
||||
assert(smsIds[3] === undefined, 'Fourth smsId should be undefined');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[1].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[1].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[2].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[2].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert.strictEqual(smsIds[0], '2343-1');
|
||||
assert.strictEqual(smsIds[1], '2343-2');
|
||||
assert.strictEqual(smsIds[2], '2343-3');
|
||||
assert.strictEqual(smsIds[3], undefined);
|
||||
assert.strictEqual(retPduObjs[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[0].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[1].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[1].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[2].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[2].cmdName, 'submit_sm_resp');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -226,62 +226,62 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should try sending a weirder long sms', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should try sending a weirder long sms', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
sms.smsId = 2344;
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2344;
|
||||
|
||||
assert(sms.from === 'foo', 'SMS from should be "foo"');
|
||||
assert(sms.to === '46709771337', 'SMS to should be "46709771337"');
|
||||
assert(sms.message === 'K sKM8NYUuoVbORtCn€swWsvTZjbtYM1TceGJJouolLk4cOtlk7j dxWMI56Domdx2W!dHKjGBR5UsynmUnbp1ysRDCktBri WW2pxIWHv0P7H OVRZNw 6 DBzAqpnd7ZPslwNyi»x OuiNH0R!WM2DTo8ItysNDNe1eNnpLvahhRgv»TC y lvgFrmv4OiUTOP', 'SMS message should be correct');
|
||||
assert(sms.dlr === false, 'DLR should be boolean false');
|
||||
assert(sms.pduObjs[0].pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||
assert.strictEqual(sms.from, 'foo');
|
||||
assert.strictEqual(sms.to, '46709771337');
|
||||
assert.strictEqual(sms.message, 'K sKM8NYUuoVbORtCn€swWsvTZjbtYM1TceGJJouolLk4cOtlk7j dxWMI56Domdx2W!dHKjGBR5UsynmUnbp1ysRDCktBri WW2pxIWHv0P7H OVRZNw 6 DBzAqpnd7ZPslwNyi»x OuiNH0R!WM2DTo8ItysNDNe1eNnpLvahhRgv»TC y lvgFrmv4OiUTOP');
|
||||
assert.strictEqual(sms.dlr, false);
|
||||
assert.strictEqual(sms.pduObjs[0].pduObj.cmdId, 4);
|
||||
|
||||
sms.sendResp(function(err, retPdus) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err, retPdus) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPdus[0].toString('hex') === '00000017800000040000000000000002323334342d3100', 'Return PDU 0 is wrong');
|
||||
assert(retPdus[1].toString('hex') === '00000017800000040000000000000003323334342d3200', 'Return PDU 1 is wrong');
|
||||
assert(retPdus[2].toString('hex') === '00000017800000040000000000000004323334342d3300', 'Return PDU 2 is wrong');
|
||||
assert.strictEqual(retPdus[0].toString('hex'), '00000017800000040000000000000002323334342d3100');
|
||||
assert.strictEqual(retPdus[1].toString('hex'), '00000017800000040000000000000003323334342d3200');
|
||||
assert.strictEqual(retPdus[2].toString('hex'), '00000017800000040000000000000004323334342d3300');
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.sendSms({
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'K sKM8NYUuoVbORtCn€swWsvTZjbtYM1TceGJJouolLk4cOtlk7j dxWMI56Domdx2W!dHKjGBR5UsynmUnbp1ysRDCktBri WW2pxIWHv0P7H OVRZNw 6 DBzAqpnd7ZPslwNyi»x OuiNH0R!WM2DTo8ItysNDNe1eNnpLvahhRgv»TC y lvgFrmv4OiUTOP'
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'K sKM8NYUuoVbORtCn€swWsvTZjbtYM1TceGJJouolLk4cOtlk7j dxWMI56Domdx2W!dHKjGBR5UsynmUnbp1ysRDCktBri WW2pxIWHv0P7H OVRZNw 6 DBzAqpnd7ZPslwNyi»x OuiNH0R!WM2DTo8ItysNDNe1eNnpLvahhRgv»TC y lvgFrmv4OiUTOP'
|
||||
}, function (err, smsIds, retPduObjs) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2344-1', 'First smsId should be "2344-1"');
|
||||
assert(smsIds[1] === '2344-2', 'Second smsId should be "2344-2"');
|
||||
assert(smsIds[2] === '2344-3', 'Third smsId should be "2344-3"');
|
||||
assert(smsIds[3] === undefined, 'Fourth smsId should be undefined');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[1].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[1].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[2].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[2].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert.strictEqual(smsIds[0], '2344-1');
|
||||
assert.strictEqual(smsIds[1], '2344-2');
|
||||
assert.strictEqual(smsIds[2], '2344-3');
|
||||
assert.strictEqual(smsIds[3], undefined);
|
||||
assert.strictEqual(retPduObjs[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[0].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[1].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[1].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[2].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[2].cmdName, 'submit_sm_resp');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -292,44 +292,44 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a long sms and receive dlrs for it', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should send a long sms and receive dlrs for it', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
sms.smsId = 2343;
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2343;
|
||||
|
||||
sms.sendResp(function(err) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(sms.dlr === true, 'sms.dlr should be true');
|
||||
assert.strictEqual(sms.dlr, true);
|
||||
|
||||
// Send the DLR(s)
|
||||
sms.sendDlr(true);
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
var sentSmsId;
|
||||
'port': freePort
|
||||
}, function (err, clientSession) {
|
||||
let sentSmsId;
|
||||
|
||||
assert( ! err, 'Error should not be negative');
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.on('dlr', function(dlr) {
|
||||
assert(dlr.statusMsg === 'DELIVERED', 'DLR statusMsg should be "DELIVERED"');
|
||||
assert(dlr.smsId.toString() === sentSmsId.toString(), 'SmsId should be "' + sentSmsId.toString() + '"');
|
||||
clientSession.on('dlr', function (dlr) {
|
||||
assert.strictEqual(dlr.statusMsg, 'DELIVERED');
|
||||
assert.strictEqual(dlr.smsId.toString(), sentSmsId.toString());
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -338,55 +338,55 @@ describe('Sessions', function() {
|
||||
});
|
||||
|
||||
clientSession.sendSms({
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.',
|
||||
'dlr': true
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.',
|
||||
'dlr': true
|
||||
}, function (err, smsIds, retPduObjs) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2343-1', 'First smsId should be "2343-1"');
|
||||
assert(smsIds[1] === '2343-2', 'Second smsId should be "2343-2"');
|
||||
assert(smsIds[2] === '2343-3', 'Third smsId should be "2343-3"');
|
||||
assert(smsIds[3] === undefined, 'Fourth smsId should be undefined');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[1].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[1].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[2].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[2].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert.strictEqual(smsIds[0], '2343-1');
|
||||
assert.strictEqual(smsIds[1], '2343-2');
|
||||
assert.strictEqual(smsIds[2], '2343-3');
|
||||
assert.strictEqual(smsIds[3], undefined);
|
||||
assert.strictEqual(retPduObjs[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[0].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[1].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[1].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[2].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[2].cmdName, 'submit_sm_resp');
|
||||
|
||||
// Save the SMS id to match the DLR for
|
||||
sentSmsId = smsIds[0].split('-')[0];
|
||||
sentSmsId = smsIds[0].split('-')[0];
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should verify dlr on readme example', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should verify dlr on readme example', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
sms.smsId = 2343; // Random integer
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2343; // Random integer
|
||||
|
||||
sms.sendResp(function(err) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(sms.dlr === true, 'sms.dlr should be true');
|
||||
assert.strictEqual(sms.dlr, true);
|
||||
|
||||
// Send the DLR(s)
|
||||
sms.sendDlr(true);
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
done();
|
||||
@@ -394,57 +394,57 @@ describe('Sessions', function() {
|
||||
});
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.on('dlr', function(dlr, dlrPduObj) {
|
||||
assert.deepEqual(dlr.statusMsg, 'DELIVERED');
|
||||
assert.deepEqual(dlr.statusId, 2);
|
||||
assert.deepEqual(parseInt(dlr.smsId), 2343);
|
||||
clientSession.on('dlr', function (dlr, dlrPduObj) {
|
||||
assert.strictEqual(dlr.statusMsg, 'DELIVERED');
|
||||
assert.strictEqual(dlr.statusId, 2);
|
||||
assert.strictEqual(parseInt(dlr.smsId), 2343);
|
||||
|
||||
assert.deepEqual(dlrPduObj.params.short_message.substring(0, 36), 'id:2343 sub:001 dlvrd:1 submit date:');
|
||||
assert.deepEqual(dlrPduObj.params.short_message.substring(68), 'stat:DELIVRD err:0 text:xxx');
|
||||
assert.deepEqual(dlrPduObj.cmdStatus, 'ESME_ROK');
|
||||
assert.deepEqual(dlrPduObj.cmdName, 'deliver_sm');
|
||||
assert.strictEqual(dlrPduObj.params.short_message.substring(0, 36), 'id:2343 sub:001 dlvrd:1 submit date:');
|
||||
assert.strictEqual(dlrPduObj.params.short_message.substring(68), 'stat:DELIVRD err:0 text:xxx');
|
||||
assert.strictEqual(dlrPduObj.cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(dlrPduObj.cmdName, 'deliver_sm');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
});
|
||||
|
||||
clientSession.sendSms({
|
||||
'from': '46701113311',
|
||||
'to': '46709771337',
|
||||
'message': '«baff»',
|
||||
'dlr': true
|
||||
}, function(err, smsId, retPduObj) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
assert.deepEqual(parseInt(smsId[0]), 2343);
|
||||
assert.deepEqual(smsId[1], undefined);
|
||||
assert.deepEqual(retPduObj[0].cmdStatus, 'ESME_ROK');
|
||||
assert.deepEqual(retPduObj[0].cmdName, 'submit_sm_resp');
|
||||
'from': '46701113311',
|
||||
'to': '46709771337',
|
||||
'message': '«baff»',
|
||||
'dlr': true
|
||||
}, function (err, smsId, retPduObj) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(parseInt(smsId[0]), 2343);
|
||||
assert.strictEqual(smsId[1], undefined);
|
||||
assert.strictEqual(retPduObj[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObj[0].cmdName, 'submit_sm_resp');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should test a session fetched from Kannel on long messages with large UDH', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
var sock = new net.Socket(),
|
||||
sockInLog = []; // Log incomming socket messages
|
||||
it('should test a session fetched from Kannel on long messages with large UDH', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
const sockInLog = [], // Log incomming socket messages
|
||||
sock = new net.Socket();
|
||||
|
||||
assert( ! err, 'Error should not be negative');
|
||||
if (err) throw err;
|
||||
|
||||
sock.connect(freePort, 'localhost', function() {
|
||||
sock.connect(freePort, 'localhost', function () {
|
||||
// bind_transceiver - initial call. Subsequent calls should be made on the sock.on('data') thingie
|
||||
sock.write(new Buffer('0000002100000009000000000000002f666f6f0062617200736d70700034000000', 'hex'));
|
||||
});
|
||||
|
||||
sock.on('data', function(data) {
|
||||
sock.on('data', function (data) {
|
||||
sockInLog.push(data.toString('hex'));
|
||||
|
||||
if (sockInLog.length === 1) {
|
||||
assert.deepEqual(data.toString('hex'), '0000001480000009000000000000002f666f6f00');
|
||||
assert.strictEqual(data.toString('hex'), '0000001480000009000000000000002f666f6f00');
|
||||
|
||||
// Send all 4 parts at the same time
|
||||
sock.write(new Buffer('000000de00000004000000000000003000050074657374000201313233343500430000003136303630373136333031333030302b00000000009f0500030204014c6f72656d20497073756d2069732073696d706c792064756d6d792074657874206f6620746865207072696e74696e6720616e64207479706573657474696e6720696e6475737472792e204c6f72656d20497073756d20686173206265656e2074686520696e6475737472792773207374616e646172642064756d6d79207465787420657665722073696e6365207468652031353030732c200426000101', 'hex'));
|
||||
@@ -452,10 +452,10 @@ describe('Sessions', function() {
|
||||
sock.write(new Buffer('000000de00000004000000000000003200050074657374000201313233343500430000003136303630373136333031333030302b00000000009f0500030204036e746f20656c656374726f6e6963207479706573657474696e672c2072656d61696e696e6720657373656e7469616c6c7920756e6368616e6765642e2049742077617320706f70756c61726973656420696e207468652031393630732077697468207468652072656c65617365206f66204c657472617365742073686565747320636f6e7461696e696e67204c6f72656d20497073756d20700426000101', 'hex'));
|
||||
sock.write(new Buffer('000000b200000004000000000000003300050074657374000201313233343500430000003136303630373136333031333030302b000000000078050003020404617373616765732c20616e64206d6f726520726563656e746c792077697468206465736b746f70207075626c697368696e6720736f667477617265206c696b6520416c64757320506167654d616b657220696e636c7564696e672076657273696f6e73206f66204c6f72656d20497073756d', 'hex'));
|
||||
} else if (sockInLog.length === 2) {
|
||||
assert.deepEqual(data.toString('hex'), '000000158000000400000000000000303233343300');
|
||||
assert.strictEqual(data.toString('hex'), '000000158000000400000000000000303233343300');
|
||||
} else if (sockInLog.length === 3) {
|
||||
// This is actually four different PDUs at the same time, marking the response on all four parts above
|
||||
assert.deepEqual(data.toString('hex'), '000000158000000400000000000000313233343300000000158000000400000000000000323233343300000000158000000400000000000000333233343300');
|
||||
assert.strictEqual(data.toString('hex'), '000000158000000400000000000000313233343300000000158000000400000000000000323233343300000000158000000400000000000000333233343300');
|
||||
done();
|
||||
} else {
|
||||
throw new Error('To much data received');
|
||||
@@ -464,20 +464,20 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
assert.deepEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum');
|
||||
serverSession.on('sms', function (sms) {
|
||||
assert.strictEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum');
|
||||
|
||||
sms.smsId = 2343;
|
||||
sms.smsId = 2343;
|
||||
|
||||
sms.sendResp(function(err) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -485,23 +485,23 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should test a session can recreate SMS with random sequence', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
var sock = new net.Socket(),
|
||||
sockInLog = []; // Log incomming socket messages
|
||||
it('should test a session can recreate SMS with random sequence', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
const sockInLog = [], // Log incomming socket messages
|
||||
sock = new net.Socket();
|
||||
|
||||
assert( ! err, 'Error should not be negative');
|
||||
if (err) throw err;
|
||||
|
||||
sock.connect(freePort, 'localhost', function() {
|
||||
sock.connect(freePort, 'localhost', function () {
|
||||
// bind_transceiver - initial call. Subsequent calls should be made on the sock.on('data') thingie
|
||||
sock.write(new Buffer('0000002100000009000000000000002f666f6f0062617200736d70700034000000', 'hex'));
|
||||
});
|
||||
|
||||
sock.on('data', function(data) {
|
||||
sock.on('data', function (data) {
|
||||
sockInLog.push(data.toString('hex'));
|
||||
|
||||
if (sockInLog.length === 1) {
|
||||
assert.deepEqual(data.toString('hex'), '0000001480000009000000000000002f666f6f00');
|
||||
assert.strictEqual(data.toString('hex'), '0000001480000009000000000000002f666f6f00');
|
||||
|
||||
// Send all 4 parts at the same time but random order
|
||||
// Message Part 2
|
||||
@@ -513,10 +513,10 @@ describe('Sessions', function() {
|
||||
// Message Part 3
|
||||
sock.write(new Buffer('000000de00000004000000000000003200050074657374000201313233343500430000003136303630373136333031333030302b00000000009f0500030204036e746f20656c656374726f6e6963207479706573657474696e672c2072656d61696e696e6720657373656e7469616c6c7920756e6368616e6765642e2049742077617320706f70756c61726973656420696e207468652031393630732077697468207468652072656c65617365206f66204c657472617365742073686565747320636f6e7461696e696e67204c6f72656d20497073756d20700426000101', 'hex'));
|
||||
} else if (sockInLog.length === 2) {
|
||||
assert.deepEqual(data.toString('hex'), '000000158000000400000000000000303233343300');
|
||||
assert.strictEqual(data.toString('hex'), '000000158000000400000000000000303233343300');
|
||||
} else if (sockInLog.length === 3) {
|
||||
// This is actually four different PDUs at the same time, marking the response on all four parts above
|
||||
assert.deepEqual(data.toString('hex'), '000000158000000400000000000000313233343300000000158000000400000000000000323233343300000000158000000400000000000000333233343300');
|
||||
assert.strictEqual(data.toString('hex'), '000000158000000400000000000000313233343300000000158000000400000000000000323233343300000000158000000400000000000000333233343300');
|
||||
done();
|
||||
} else {
|
||||
throw new Error('To much data received');
|
||||
@@ -524,21 +524,21 @@ describe('Sessions', function() {
|
||||
});
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
'port': freePort
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
assert.deepEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum');
|
||||
serverSession.on('sms', function (sms) {
|
||||
assert.strictEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum');
|
||||
|
||||
sms.smsId = 2343;
|
||||
sms.smsId = 2343;
|
||||
|
||||
sms.sendResp(function(err) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user