var to let or const, better lints, code style and more

This commit is contained in:
2017-06-25 02:10:26 +02:00
parent a3d253994f
commit 7cc0f4f94d
16 changed files with 2887 additions and 2682 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
'use strict';
var log = require('winston');
const log = require('winston');
// Remove log output to the console
log.remove(log.transports.Console);
log.remove(log.transports.Console);
+55 -73
View File
@@ -1,21 +1,19 @@
'use strict';
var assert = require('assert'),
encodings = require('../lib/defs').encodings;
const encodings = require(__dirname + '/../lib/defs.js').encodings,
assert = require('assert');
describe('encodings', function() {
describe('ASCII', function() {
var ASCII = encodings.ASCII,
samples;
describe('encodings', function () {
describe('ASCII', function () {
const samples = {},
ASCII = encodings.ASCII;
samples = {
'@£$¥': [0, 1, 2, 3],
' 1a=': [0x20, 0x31, 0x61, 0x3D],
'~^€': [0x1B, 0x3D, 0x1B, 0x14, 0x1B, 0x65]
};
samples['@£$¥'] = [0, 1, 2, 3];
samples[' 1a='] = [0x20, 0x31, 0x61, 0x3D];
samples['~^€'] = [0x1B, 0x3D, 0x1B, 0x14, 0x1B, 0x65];
describe('#match()', function() {
it('should return true for strings that can be encoded using GSM 03.38 ASCII charset', function() {
describe('#match()', function () {
it('should return true for strings that can be encoded using GSM 03.38 ASCII charset', function () {
assert(ASCII.match(''));
assert(ASCII.match('@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BÆæßÉ !"#¤%&\''));
assert(ASCII.match('()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZ'));
@@ -23,88 +21,76 @@ describe('encodings', function() {
assert(ASCII.match('\f^{}\\[~]|€'));
});
it('should return false for strings that can not be encoded using GSM 03.38 ASCII charset', function() {
it('should return false for strings that can not be encoded using GSM 03.38 ASCII charset', function () {
assert( ! ASCII.match('`'));
assert( ! ASCII.match('ÁáçÚUÓO'));
assert( ! ASCII.match('تست'));
});
});
describe('#encode', function() {
it('should properly encode the given string using GSM 03.38 ASCII charset', function() {
var str;
for (str in samples) {
describe('#encode', function () {
it('should properly encode the given string using GSM 03.38 ASCII charset', function () {
for (const str in samples) {
assert.deepEqual(ASCII.encode(str), new Buffer(samples[str]));
}
});
});
describe('#decode', function() {
it('should properly decode the given buffer using GSM 03.38 ASCII charset', function() {
var str;
for (str in samples) {
describe('#decode', function () {
it('should properly decode the given buffer using GSM 03.38 ASCII charset', function () {
for (const str in samples) {
assert.deepEqual(ASCII.decode(samples[str]), str);
}
});
});
});
describe('LATIN1', function() {
var LATIN1 = encodings.LATIN1,
samples;
describe('LATIN1', function () {
const samples = {},
LATIN1 = encodings.LATIN1;
samples = {
'@$`Á': [0x40, 0x24, 0x60, 0xC1],
'áçÚ': [0xE1, 0xE7, 0xDA],
'UÓO': [0x55, 0xD3, 0x4F]
};
samples['@$`Á'] = [0x40, 0x24, 0x60, 0xC1];
samples['áçÚ'] = [0xE1, 0xE7, 0xDA];
samples['UÓO'] = [0x55, 0xD3, 0x4F];
describe('#match()', function() {
it('should return false for strings that can be encoded using LATIN1 charset', function() {
describe('#match()', function () {
it('should return false for strings that can be encoded using LATIN1 charset', function () {
assert( ! LATIN1.match('`ÁáçÚUÓO'));
});
it('should return false for strings that can not be encoded using LATIN1 charset', function() {
it('should return false for strings that can not be encoded using LATIN1 charset', function () {
assert( ! LATIN1.match('تست'));
assert( ! LATIN1.match('۱۲۳۴۵۶۷۸۹۰'));
assert( ! LATIN1.match('ʹʺʻʼʽ`'));
});
});
describe('#encode', function() {
it('should properly encode the given string using LATIN1 charset', function() {
var str;
for (str in samples) {
describe('#encode', function () {
it('should properly encode the given string using LATIN1 charset', function () {
for (const str in samples) {
assert.deepEqual(LATIN1.encode(str), new Buffer(samples[str]));
}
});
});
describe('#decode', function() {
it('should properly decode the given buffer using LATIN1 charset', function() {
var str;
for (str in samples) {
describe('#decode', function () {
it('should properly decode the given buffer using LATIN1 charset', function () {
for (const str in samples) {
assert.deepEqual(LATIN1.decode(new Buffer(samples[str])), str);
}
});
});
});
describe('UCS2', function() {
var UCS2 = encodings.UCS2,
samples;
describe('UCS2', function () {
const samples = {},
UCS2 = encodings.UCS2;
samples = {
' 1a': [0x00, 0x20, 0x00, 0x31, 0x00, 0x61],
'۱۲۳': [0x06, 0xF1, 0x06, 0xF2, 0x06, 0xF3]
};
samples[' 1a'] = [0x00, 0x20, 0x00, 0x31, 0x00, 0x61];
samples['۱۲۳'] = [0x06, 0xF1, 0x06, 0xF2, 0x06, 0xF3];
describe('#match()', function() {
it('should always return true', function() {
describe('#match()', function () {
it('should always return true', function () {
assert(UCS2.match(''));
assert(UCS2.match('`ÁáçÚUÓO'));
assert(UCS2.match('تست'));
@@ -113,36 +99,32 @@ describe('encodings', function() {
});
});
describe('#encode', function() {
it('should properly encode the given string using UCS2 charset', function() {
var str;
for (str in samples) {
describe('#encode', function () {
it('should properly encode the given string using UCS2 charset', function () {
for (const str in samples) {
assert.deepEqual(UCS2.encode(str), new Buffer(samples[str]));
}
});
});
describe('#decode', function() {
it('should properly decode the given buffer using UCS2 charset', function() {
var str;
for (str in samples) {
describe('#decode', function () {
it('should properly decode the given buffer using UCS2 charset', function () {
for (const str in samples) {
assert.deepEqual(UCS2.decode(samples[str]), str);
}
});
});
});
describe('#detect()', function() {
it('should return proper encoding for the given string', function() {
assert.equal(encodings.detect(''), 'ASCII');
assert.equal(encodings.detect('ÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà(){}[]'), 'ASCII');
assert.equal(encodings.detect('`ÁáçÚUÓO'), 'UCS2');
assert.equal(encodings.detect('«©®µ¶±»'), 'UCS2');
assert.equal(encodings.detect('ʹʺʻʼʽ`'), 'UCS2');
assert.equal(encodings.detect('تست'), 'UCS2');
assert.equal(encodings.detect('۱۲۳۴۵۶۷۸۹۰'), 'UCS2');
describe('#detect()', function () {
it('should return proper encoding for the given string', function () {
assert.equal(encodings.detect(''), 'ASCII');
assert.equal(encodings.detect('ÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà(){}[]'), 'ASCII');
assert.equal(encodings.detect('`ÁáçÚUÓO'), 'UCS2');
assert.equal(encodings.detect('«©®µ¶±»'), 'UCS2');
assert.equal(encodings.detect('ʹʺʻʼʽ`'), 'UCS2');
assert.equal(encodings.detect('تست'), 'UCS2');
assert.equal(encodings.detect('۱۲۳۴۵۶۷۸۹۰'), 'UCS2');
});
});
});
+113 -120
View File
@@ -1,242 +1,235 @@
'use strict';
var assert = require('assert'),
types = require('../lib/defs').types;
const assert = require('assert'),
types = require(__dirname + '/../lib/defs.js').types;
describe('int8', function() {
var b = new Buffer([0, 0x65]), expected = 0x65;
describe('int8', function () {
const expected = 0x65,
b = new Buffer([0, 0x65]);
describe('#read()', function() {
it('should read one byte as integer', function() {
var result = types.int8.read(b, 1);
describe('#read()', function () {
it('should read one byte as integer', function () {
const result = types.int8.read(b, 1);
assert.equal(result, expected);
});
});
describe('#size()', function() {
it('should return 1', function() {
assert.equal(types.int8.size(expected), 1);
describe('#size()', function () {
it('should return 1', function () {
assert.equal(types.int8.size(expected), 1);
});
});
describe('#write()', function() {
it('should write one byte to the buffer', function() {
describe('#write()', function () {
it('should write one byte to the buffer', function () {
types.int8.write(expected, b, 0);
assert.deepEqual(new Buffer([0x65]), b.slice(0, 1));
});
});
});
describe('int16', function() {
var b = new Buffer([0, 0x05, 0x65]), expected = 0x0565;
describe('int16', function () {
const expected = 0x0565,
b = new Buffer([0, 0x05, 0x65]);
describe('#read()', function() {
it('should read 2 bytes as integer', function() {
var result = types.int16.read(b, 1);
describe('#read()', function () {
it('should read 2 bytes as integer', function () {
const result = types.int16.read(b, 1);
assert.equal(result, expected);
});
});
describe('#size()', function() {
it('should return 2', function() {
assert.equal(types.int16.size(expected), 2);
describe('#size()', function () {
it('should return 2', function () {
assert.equal(types.int16.size(expected), 2);
});
});
describe('#write()', function() {
it('should write 2 bytes to the buffer', function() {
describe('#write()', function () {
it('should write 2 bytes to the buffer', function () {
types.int16.write(expected, b, 0);
assert.deepEqual(new Buffer([0x05, 0x65]), b.slice(0, 2));
assert.deepEqual(new Buffer([0x05, 0x65]), b.slice(0, 2));
});
});
});
describe('int32', function() {
var b = new Buffer([0, 0x10, 0x02, 0x40, 0x45]), expected = 0x10024045;
describe('int32', function () {
const expected = 0x10024045,
b = new Buffer([0, 0x10, 0x02, 0x40, 0x45]);
describe('#read()', function() {
it('should read 4 bytes as integer', function() {
var result = types.int32.read(b, 1);
describe('#read()', function () {
it('should read 4 bytes as integer', function () {
const result = types.int32.read(b, 1);
assert.equal(result, expected);
});
});
describe('#size()', function() {
it('should return 4', function() {
describe('#size()', function () {
it('should return 4', function () {
assert.equal(types.int32.size(expected), 4);
});
});
describe('#write()', function() {
it('should write 4 bytes to the buffer', function() {
describe('#write()', function () {
it('should write 4 bytes to the buffer', function () {
types.int32.write(expected, b, 0);
assert.deepEqual(new Buffer([0x10, 0x02, 0x40, 0x45]), b.slice(0, 4));
});
});
});
describe('string', function() {
var b = new Buffer(9), expected = 'abcd1234';
b[0] = 8;
describe('string', function () {
const expected = 'abcd1234',
b = new Buffer(9);
b[0] = 8;
b.write(expected, 1);
describe('#read()', function() {
it('should read an Octet String from the buffer', function() {
var result = types.string.read(b, 0);
describe('#read()', function () {
it('should read an Octet String from the buffer', function () {
const result = types.string.read(b, 0);
assert.equal(result, expected);
});
});
describe('#size()', function() {
it('should return the length of an Octet String from its first byte', function() {
describe('#size()', function () {
it('should return the length of an Octet String from its first byte', function () {
assert.equal(9, types.string.size(expected));
});
});
describe('#write()', function() {
it('should write an Octet String to the buffer', function() {
var b2 = new Buffer(9);
describe('#write()', function () {
it('should write an Octet String to the buffer', function () {
const b2 = new Buffer(9);
types.string.write(expected, b2, 0);
assert.deepEqual(b, b2);
});
});
});
describe('cstring', function() {
var b = new Buffer(9), expected = 'abcd1234';
b[8] = 0;
describe('cstring', function () {
const expected = 'abcd1234',
b = new Buffer(9);
b[8] = 0;
b.write(expected, 0);
describe('#read()', function() {
it('should read a C-Octet String (null-terminated string) from the buffer', function() {
var result = types.cstring.read(b, 0);
describe('#read()', function () {
it('should read a C-Octet String (null-terminated string) from the buffer', function () {
const result = types.cstring.read(b, 0);
assert.equal(result, expected);
});
});
describe('#size()', function() {
it('should return the length of a C-Octet String (null-terminated string)', function() {
describe('#size()', function () {
it('should return the length of a C-Octet String (null-terminated string)', function () {
assert.equal(9, types.cstring.size(expected));
});
});
describe('#write()', function() {
it('should write a C-Octet String (null-terminated string) to the buffer', function() {
var b2 = new Buffer(9);
describe('#write()', function () {
it('should write a C-Octet String (null-terminated string) to the buffer', function () {
const b2 = new Buffer(9);
types.cstring.write(expected, b2, 0);
assert.deepEqual(b, b2);
assert.deepEqual(b, b2);
});
});
});
describe('buffer', function() {
var b = new Buffer(8),
expected = new Buffer('abcd1234');
describe('buffer', function () {
const expected = new Buffer('abcd1234'),
b = new Buffer(8);
b.write(expected.toString());
describe('#read()', function() {
it('should read a binary field from the buffer', function() {
var result = types.buffer.read(b, 0, b.length);
describe('#read()', function () {
it('should read a binary field from the buffer', function () {
const result = types.buffer.read(b, 0, b.length);
assert.deepEqual(result, expected);
});
});
describe('#size()', function() {
it('should return the size of a binary field in bytes', function() {
describe('#size()', function () {
it('should return the size of a binary field in bytes', function () {
assert.equal(8, types.buffer.size(expected));
});
});
describe('#write()', function() {
it('should write a binary field to the buffer', function() {
var b2 = new Buffer(8);
describe('#write()', function () {
it('should write a binary field to the buffer', function () {
const b2 = new Buffer(8);
types.buffer.write(expected, b2, 0);
assert.deepEqual(b, b2);
});
});
});
describe('dest_address_array', function() {
var b,
expected;
describe('dest_address_array', function () {
const expected = [],
b = new Buffer([0x02, 0x01, 0x01, 0x02, 0x31, 0x32, 0x33, 0x00, 0x02, 0x61, 0x62, 0x63, 0x00]);
b = new Buffer([
0x02, 0x01, 0x01, 0x02, 0x31, 0x32, 0x33, 0x00,
0x02, 0x61, 0x62, 0x63, 0x00
]);
expected.push({
'dest_addr_ton': 1,
'dest_addr_npi': 2,
'destination_addr': '123'
});
expected.push({'dl_name': 'abc'});
expected = [
{
dest_addr_ton: 1,
dest_addr_npi: 2,
destination_addr: '123'
},
{ dl_name: 'abc' }
];
describe('#read()', function() {
it('should read all dest_address structures from the buffer', function() {
var result = types.dest_address_array.read(b, 0);
describe('#read()', function () {
it('should read all dest_address structures from the buffer', function () {
const result = types.dest_address_array.read(b, 0);
assert.deepEqual(result, expected);
});
});
describe('#size()', function() {
it('should return the size of all dest_address structures in bytes', function() {
describe('#size()', function () {
it('should return the size of all dest_address structures in bytes', function () {
assert.equal(types.dest_address_array.size(expected), 13);
});
});
describe('#write()', function() {
it('should write an array of dest_address structures to the buffer', function() {
var b2 = new Buffer(13);
describe('#write()', function () {
it('should write an array of dest_address structures to the buffer', function () {
const b2 = new Buffer(13);
types.dest_address_array.write(expected, b2, 0);
assert.deepEqual(b, b2);
});
});
});
describe('unsuccess_sme_array', function() {
var b,
expected;
describe('unsuccess_sme_array', function () {
const expected = [],
b = new Buffer([0x02, 0x03, 0x04, 0x61, 0x62, 0x63, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x06, 0x31, 0x32, 0x33, 0x00, 0x10, 0x00, 0x00, 0x08]);
b = new Buffer([
0x02, 0x03, 0x04, 0x61, 0x62, 0x63, 0x00, 0x00, 0x00, 0x00, 0x07,
0x05, 0x06, 0x31, 0x32, 0x33, 0x00, 0x10, 0x00, 0x00, 0x08
]);
expected.push({
'dest_addr_ton': 3,
'dest_addr_npi': 4,
'destination_addr': 'abc',
'error_status_code': 0x00000007
});
expected.push({
'dest_addr_ton': 5,
'dest_addr_npi': 6,
'destination_addr': '123',
'error_status_code': 0x10000008
});
expected = [
{
dest_addr_ton: 3,
dest_addr_npi: 4,
destination_addr: 'abc',
error_status_code: 0x00000007
},
{
dest_addr_ton: 5,
dest_addr_npi: 6,
destination_addr: '123',
error_status_code: 0x10000008
}
];
describe('#read()', function() {
it('should read all unsuccess_sme structures from the buffer', function() {
var result = types.unsuccess_sme_array.read(b, 0);
describe('#read()', function () {
it('should read all unsuccess_sme structures from the buffer', function () {
const result = types.unsuccess_sme_array.read(b, 0);
assert.deepEqual(result, expected);
});
});
describe('#size()', function() {
it('should return the size of all unsuccess_sme structures in bytes', function() {
describe('#size()', function () {
it('should return the size of all unsuccess_sme structures in bytes', function () {
assert.equal(types.unsuccess_sme_array.size(expected), 21);
});
});
describe('#write()', function() {
it('should write an array of unsuccess_sme structures to the buffer', function() {
var b2 = new Buffer(21);
describe('#write()', function () {
it('should write an array of unsuccess_sme structures to the buffer', function () {
const b2 = new Buffer(21);
types.unsuccess_sme_array.write(expected, b2, 0);
assert.deepEqual(b, b2);
});
+239 -242
View File
@@ -1,197 +1,196 @@
'use strict';
var larvitsmpp = require('../larvitsmpp'),
assert = require('assert');
const larvitsmpp = require(__dirname + '/../index.js'),
assert = require('assert');
describe('PDU convertion', function() {
describe('PDU convertion', function () {
this.slow(20);
describe('No TLVs', function() {
it('should build a PDU buffer for bind_transceiver_resp with error correctly', function(done) {
describe('No TLVs', function () {
it('should build a PDU buffer for bind_transceiver_resp with error correctly', function (done) {
larvitsmpp.utils.objToPdu({
'cmdName': 'bind_transceiver_resp',
'cmdStatus': 'ESME_RALYBND',
'seqNr': 1
}, function(err, pdu) {
assert( ! err, 'Error should be negative');
'cmdName': 'bind_transceiver_resp',
'cmdStatus': 'ESME_RALYBND',
'seqNr': 1
}, function (err, pdu) {
if (err) throw err;
assert(pdu.readUInt32BE(0) === 17, 'Command length should be 17, but is: "' + pdu.readUInt32BE(0) + '"');
assert(pdu.readUInt32BE(4).toString(16) === '80000009', 'Command ID should be 0x80000009');
assert(pdu.readUInt32BE(8).toString(16) === '5', 'Command status should be 0x00000005');
assert(pdu.readUInt32BE(12).toString(10) === '1', 'Sequence number should be 1');
assert.strictEqual(pdu.readUInt32BE(0), 17);
assert.strictEqual(pdu.readUInt32BE(4).toString(16), '80000009');
assert.strictEqual(pdu.readUInt32BE(8).toString(16), '5');
assert.strictEqual(pdu.readUInt32BE(12).toString(10), '1');
done();
});
});
it('should be able to do the above test and put it back to an object', function(done) {
it('should be able to do the above test and put it back to an object', function (done) {
larvitsmpp.utils.objToPdu({
'cmdName': 'bind_transceiver_resp',
'cmdStatus': 'ESME_RALYBND',
'seqNr': 1
}, function(err, pdu) {
assert( ! err, 'Error should be negative');
'cmdName': 'bind_transceiver_resp',
'cmdStatus': 'ESME_RALYBND',
'seqNr': 1
}, function (err, pdu) {
if (err) throw err;
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
if (err) throw err;
assert(obj.cmdId.toString(16) === '80000009', 'Command ID should be 0x80000009');
assert(obj.cmdStatus === 'ESME_RALYBND', 'Command status should be "ESME_RALYBND"');
assert(obj.seqNr === 1, 'Sequence number should be 1');
assert.strictEqual(obj.cmdId.toString(16), '80000009');
assert.strictEqual(obj.cmdStatus, 'ESME_RALYBND');
assert.strictEqual(obj.seqNr, 1);
done();
});
});
});
it('should parse a PDU to obj correctly', function(done) {
var pdu = new Buffer('0000002F000000020000000000000001534D50503354455354007365637265743038005355424D4954310000010100', 'hex');
it('should parse a PDU to obj correctly', function (done) {
const pdu = new Buffer('0000002F000000020000000000000001534D50503354455354007365637265743038005355424D4954310000010100', 'hex');
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
if (err) throw err;
assert(obj.cmdId === 2, 'Command ID should be 2');
assert(obj.cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
assert(obj.cmdName === 'bind_transmitter', 'Command name should be "bind_transmitter"');
assert(obj.params.system_id === 'SMPP3TEST', 'system_id should be "SMPP3TEST"');
assert(obj.params.interface_version === 0, 'Interface version should be 0');
assert.strictEqual(obj.cmdId, 2);
assert.strictEqual(obj.cmdStatus, 'ESME_ROK');
assert.strictEqual(obj.cmdName, 'bind_transmitter');
assert.strictEqual(obj.params.system_id, 'SMPP3TEST');
assert.strictEqual(obj.params.interface_version, 0);
done();
});
});
it('should create a return PDU without error', function(done) {
var pdu = new Buffer('0000002f000000020000000000000001534d50503354455354007365637265743038005355424d4954310000010100', 'hex');
it('should create a return PDU without error', function (done) {
const pdu = new Buffer('0000002f000000020000000000000001534d50503354455354007365637265743038005355424d4954310000010100', 'hex');
larvitsmpp.utils.pduReturn(pdu, function(err, retPdu) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduReturn(pdu, function (err, retPdu) {
if (err) throw err;
larvitsmpp.utils.pduToObj(retPdu, function(err, retObj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(retPdu, function (err, retObj) {
if (err) throw err;
assert(retObj.cmdId === 2147483650, 'Command ID should be 2147483650');
assert(retObj.cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
assert(retObj.cmdName === 'bind_transmitter_resp', 'Command name should be "bind_transmitter_resp"');
assert(retObj.params.system_id === 'SMPP3TEST', 'system_id should be "SMPP3TEST"');
assert.strictEqual(retObj.cmdId, 2147483650);
assert.strictEqual(retObj.cmdStatus, 'ESME_ROK');
assert.strictEqual(retObj.cmdName, 'bind_transmitter_resp');
assert.strictEqual(retObj.params.system_id, 'SMPP3TEST');
done();
});
});
});
it('should read a submit_sm with an ending NULL octet to the short_message', function(done) {
var pdu = new Buffer('0000003c0000000400000000000000020001003436373031313333313131000101343637303937373133333700000000000000000100047465737400', 'hex');
it('should read a submit_sm with an ending NULL octet to the short_message', function (done) {
const pdu = new Buffer('0000003c0000000400000000000000020001003436373031313333313131000101343637303937373133333700000000000000000100047465737400', 'hex');
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
if (err) throw err;
assert(obj.params.short_message === 'test', 'Param short_message should read "test"');
assert(obj.cmdLength === 60, 'Command length should be 60, due to the trailing NULL octet');
assert.strictEqual(obj.params.short_message, 'test');
assert.strictEqual(obj.cmdLength, 60);
done();
});
});
it('should read a submit_sm without an ending NULL octet to the short_message', function(done) {
var pdu = new Buffer('0000003b00000004000000000000000200010034363730313133333131310001013436373039373731333337000000000000000001000474657374', 'hex');
it('should read a submit_sm without an ending NULL octet to the short_message', function (done) {
const pdu = new Buffer('0000003b00000004000000000000000200010034363730313133333131310001013436373039373731333337000000000000000001000474657374', 'hex');
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
if (err) throw err;
assert(obj.params.short_message === 'test', 'Param short_message should read "test"');
assert(obj.cmdLength === 59, 'Command length should be 59');
assert.strictEqual(obj.params.short_message, 'test');
assert.strictEqual(obj.cmdLength, 59);
done();
});
});
it('should create a very simple submit_sm PDU', function(done) {
it('should create a very simple submit_sm PDU', function (done) {
larvitsmpp.utils.objToPdu({
'cmdName': 'submit_sm',
'cmdStatus': 'ESME_ROK',
'seqNr': 12,
'cmdName': 'submit_sm',
'cmdStatus': 'ESME_ROK',
'seqNr': 12,
'params': {
'source_addr': '46701113311',
'destination_addr': '46709771337',
'short_message': 'Hello world'
'source_addr': '46701113311',
'destination_addr': '46709771337',
'short_message': 'Hello world'
}
}, function(err, pdu) {
assert( ! err, 'Error should be negative');
}, function (err, pdu) {
if (err) throw err;
assert(pdu.toString('hex') === '0000004200000004000000000000000c00000034363730313131333331310000003436373039373731333337000000000000000001000b48656c6c6f20776f726c64');
assert.strictEqual(pdu.toString('hex'), '0000004200000004000000000000000c00000034363730313131333331310000003436373039373731333337000000000000000001000b48656c6c6f20776f726c64');
done();
});
});
it('should create a submit_sm PDU with UCS2 encoding', function(done) {
it('should create a submit_sm PDU with UCS2 encoding', function (done) {
larvitsmpp.utils.objToPdu({
'cmdName': 'submit_sm',
'cmdStatus': 'ESME_ROK',
'seqNr': 12,
'cmdName': 'submit_sm',
'cmdStatus': 'ESME_ROK',
'seqNr': 12,
'params': {
'source_addr': '46701113311',
'destination_addr': '46709771337',
'short_message': 'Hello«»world'
'source_addr': '46701113311',
'destination_addr': '46709771337',
'short_message': 'Hello«»world'
}
}, function(err, pdu) {
assert( ! err, 'Error should be negative');
}, function (err, pdu) {
if (err) throw err;
assert(pdu.toString('hex') === '0000004f00000004000000000000000c00000034363730313131333331310000003436373039373731333337000000000000000008001800480065006c006c006f00ab00bb0077006f0072006c0064');
assert.strictEqual(pdu.toString('hex'), '0000004f00000004000000000000000c00000034363730313131333331310000003436373039373731333337000000000000000008001800480065006c006c006f00ab00bb0077006f0072006c0064');
done();
});
});
it('should create a submit_sm PDU with esm_class 0x40 and a short_message with UDH in it', function(done) {
var msg = 'hej världen',
msgBuf = Buffer.concat([new Buffer('050003010101', 'hex'), new Buffer(msg)]),
encoding = larvitsmpp.defs.encodings.detect(msg);
it('should create a submit_sm PDU with esm_class 0x40 and a short_message with UDH in it', function (done) {
const msg = 'hej världen',
msgBuf = Buffer.concat([new Buffer('050003010101', 'hex'), new Buffer(msg)]),
encoding = larvitsmpp.defs.encodings.detect(msg);
larvitsmpp.utils.objToPdu({
'cmdName': 'submit_sm',
'cmdStatus': 'ESME_ROK',
'seqNr': 12,
'cmdName': 'submit_sm',
'cmdStatus': 'ESME_ROK',
'seqNr': 12,
'params': {
'esm_class': 0x40,
'source_addr': '46701113311',
'destination_addr': '46709771337',
'sm_length': msgBuf.length,
'data_coding': larvitsmpp.defs.consts.ENCODING[encoding],
'short_message': msgBuf
'esm_class': 0x40,
'source_addr': '46701113311',
'destination_addr': '46709771337',
'sm_length': msgBuf.length,
'data_coding': larvitsmpp.defs.consts.ENCODING[encoding],
'short_message': msgBuf
}
}, function(err, pdu) {
assert( ! err, 'Error should be negative');
}, function (err, pdu) {
if (err) throw err;
larvitsmpp.utils.pduToObj(pdu, function(err, retObj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pdu, function (err, retObj) {
if (err) throw err;
assert(retObj.params.short_message.toString('hex') === '05000301010168656a2076c3a4726c64656e', 'short_message should be correct');
assert.strictEqual(retObj.params.short_message.toString('hex'), '05000301010168656a2076c3a4726c64656e');
done();
});
});
});
it('should encode and decode integer cstring params correctly', function(done) {
var pduObj = {
'cmdName': 'submit_sm_resp',
'cmdStatus': 'ESME_ROK',
'seqNr': 2,
it('should encode and decode integer cstring params correctly', function (done) {
const pduObj = {
'cmdName': 'submit_sm_resp',
'cmdStatus': 'ESME_ROK',
'seqNr': 2,
'params': {
'message_id': 450
'message_id': 450
}
};
larvitsmpp.utils.objToPdu(pduObj, function(err, pduBuf) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.objToPdu(pduObj, function (err, pduBuf) {
if (err) throw err;
larvitsmpp.utils.pduToObj(pduBuf, function(err, retPduObj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pduBuf, function (err, retPduObj) {
if (err) throw err;
assert(retPduObj.params.message_id === '450', 'message_id param should be 450, but as string');
assert.strictEqual(retPduObj.params.message_id, '450');
done();
});
@@ -199,102 +198,102 @@ describe('PDU convertion', function() {
});
});
describe('TLVs', function() {
it('should extract TLVs from a PDU', function(done) {
var pdu = new Buffer('000000e9000000050000000002a82e8600010134363730393737313333370000003436373031313133333131000400000000000000007569643a313535303430363231323432313433353835207375623a30303120646c7672643a303031207375626d697420646174653a3135303430363233323420646f6e6520646174653a3135303430363233323420737461743a44454c49565244206572723a3030303020746578743a202062616666042300030300000427000102001e001331353530343036323132343231343335383500141800040000076c145400040000000114160006323430303800', 'hex');
describe('TLVs', function () {
it('should extract TLVs from a PDU', function (done) {
const pdu = new Buffer('000000e9000000050000000002a82e8600010134363730393737313333370000003436373031313133333131000400000000000000007569643a313535303430363231323432313433353835207375623a30303120646c7672643a303031207375626d697420646174653a3135303430363233323420646f6e6520646174653a3135303430363233323420737461743a44454c49565244206572723a3030303020746578743a202062616666042300030300000427000102001e001331353530343036323132343231343335383500141800040000076c145400040000000114160006323430303800', 'hex');
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
if (err) throw err;
assert(obj.cmdId.toString(16) === '5', 'Command ID should be 0x00000005 (5)');
assert(obj.cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
assert(obj.seqNr === 44576390, 'Sequence number should be 44576390');
assert(obj.params.destination_addr === '46701113311', 'Param destination_addr should be "46701113311"');
assert(obj.tlvs.receipted_message_id.tagValue === '155040621242143585', 'TLV receipted_message_id should be "155040621242143585", but is "' + obj.tlvs.receipted_message_id.tagValue + '"');
assert.strictEqual(obj.cmdId.toString(16), '5');
assert.strictEqual(obj.cmdStatus, 'ESME_ROK');
assert.strictEqual(obj.seqNr, 44576390);
assert.strictEqual(obj.params.destination_addr, '46701113311');
assert.strictEqual(obj.tlvs.receipted_message_id.tagValue, '155040621242143585');
done();
});
});
it('should add TLVs to a PDU', function(done) {
var pduObj = {
'cmdName': 'deliver_sm',
'seqNr': 393,
'cmdStatus': 'ESME_ROK',
it('should add TLVs to a PDU', function (done) {
const pduObj = {
'cmdName': 'deliver_sm',
'seqNr': 393,
'cmdStatus': 'ESME_ROK',
'params': {
'source_addr': '46701113311',
'destination_addr': '46709771337',
'esm_class': 4,
'short_message': 'random stuff'
'source_addr': '46701113311',
'destination_addr': '46709771337',
'esm_class': 4,
'short_message': 'random stuff'
},
'tlvs': {
'receipted_message_id': {
'tagId': 0x001E,
'tagName': 'receipted_message_id',
'tagValue': '293f293'
'tagId': 0x001E,
'tagName': 'receipted_message_id',
'tagValue': '293f293'
},
'5142': {
'tagId': 5142,
'tagName': 'Nils',
'tagValue': new Buffer('blajfoo', 'ascii')
'tagId': 5142,
'tagName': 'Nils',
'tagValue': new Buffer('blajfoo', 'ascii')
}
}
};
larvitsmpp.utils.objToPdu(pduObj, function(err, pduBuf) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.objToPdu(pduObj, function (err, pduBuf) {
if (err) throw err;
larvitsmpp.utils.pduToObj(pduBuf, function(err, pduObj2) {
var unknownTlvBuf = new Buffer(pduObj2.tlvs['5142'].tagValue, 'hex');
larvitsmpp.utils.pduToObj(pduBuf, function (err, pduObj2) {
const unknownTlvBuf = new Buffer(pduObj2.tlvs['5142'].tagValue, 'hex');
assert( ! err, 'Error should be negative');
if (err) throw err;
assert(pduObj2.tlvs.receipted_message_id !== undefined, 'TLV receipted_message_id should not be undefined');
assert(pduObj2.tlvs.receipted_message_id.tagValue === '293f293', 'receipted_message_id should match the given one');
assert(unknownTlvBuf.toString('ascii') === 'blajfoo', 'Unknown TLV 5142 should have a valid buffer');
assert.notStrictEqual(pduObj2.tlvs.receipted_message_id, undefined);
assert.strictEqual(pduObj2.tlvs.receipted_message_id.tagValue, '293f293');
assert.strictEqual(unknownTlvBuf.toString('ascii'), 'blajfoo');
done();
});
});
});
it('should add some other TLVs to a PDU', function(done) {
var pduObj = {
'cmdName': 'deliver_sm',
it('should add some other TLVs to a PDU', function (done) {
const pduObj = {
'cmdName': 'deliver_sm',
'params': {
'source_addr': '46701113311',
'destination_addr': '46709771337',
'esm_class': 4,
'short_message': 'id:450 sub:001 dlvrd:1 submit date:1504031342 done date:1504031342 stat:DELIVRD err:0 text:xxx'
'source_addr': '46701113311',
'destination_addr': '46709771337',
'esm_class': 4,
'short_message': 'id:450 sub:001 dlvrd:1 submit date:1504031342 done date:1504031342 stat:DELIVRD err:0 text:xxx'
},
'tlvs': {
'receipted_message_id': {
'tagId': 30,
'tagName': 'receipted_message_id',
'tagValue': 450
'tagId': 30,
'tagName': 'receipted_message_id',
'tagValue': 450
},
'message_state': {
'tagId': 1063,
'tagName': 'message_state',
'tagValue': 2
'tagId': 1063,
'tagName': 'message_state',
'tagValue': 2
}
},
'seqNr': 323
'seqNr': 323
};
larvitsmpp.utils.objToPdu(pduObj, function(err, pduBuf) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.objToPdu(pduObj, function (err, pduBuf) {
if (err) throw err;
larvitsmpp.utils.pduToObj(pduBuf, function(err, retPduObj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pduBuf, function (err, retPduObj) {
if (err) throw err;
assert(retPduObj.params.short_message === 'id:450 sub:001 dlvrd:1 submit date:1504031342 done date:1504031342 stat:DELIVRD err:0 text:xxx', 'short_message should be preserved');
assert(retPduObj.cmdName === 'deliver_sm', 'Command name should be "deliver_sm"');
assert(retPduObj.tlvs.message_state !== undefined, 'TLV message_state should be set');
assert(retPduObj.tlvs.message_state.tagValue === 2, 'TLV message_state tagValue should be 2');
assert(retPduObj.tlvs.receipted_message_id !== undefined, 'TLV receipted_message_id should be set');
assert(retPduObj.tlvs.receipted_message_id.tagValue === '450', 'TLV receipted_message_id tagValue should be "450"');
assert(retPduObj.seqNr === 323, 'Sequence number should be 323');
assert.strictEqual(retPduObj.params.short_message, 'id:450 sub:001 dlvrd:1 submit date:1504031342 done date:1504031342 stat:DELIVRD err:0 text:xxx');
assert.strictEqual(retPduObj.cmdName, 'deliver_sm');
assert.notStrictEqual(retPduObj.tlvs.message_state, undefined);
assert.strictEqual(retPduObj.tlvs.message_state.tagValue, 2);
assert.notStrictEqual(retPduObj.tlvs.receipted_message_id, undefined);
assert.strictEqual(retPduObj.tlvs.receipted_message_id.tagValue, '450');
assert.strictEqual(retPduObj.seqNr, 323);
done();
});
@@ -302,83 +301,83 @@ describe('PDU convertion', function() {
});
});
describe('Return PDUs', function() {
it('should create a basic and valid return PDU', function(done) {
var pduObj = {
'cmdName': 'deliver_sm',
'seqNr': 393,
'cmdStatus': 'ESME_ROK',
describe('Return PDUs', function () {
it('should create a basic and valid return PDU', function (done) {
const pduObj = {
'cmdName': 'deliver_sm',
'seqNr': 393,
'cmdStatus': 'ESME_ROK',
'params': {
'source_addr': '46701113311',
'destination_addr': '46709771337',
'esm_class': 4,
'short_message': 'random stuff',
'message_id': 'od9s2'
'source_addr': '46701113311',
'destination_addr': '46709771337',
'esm_class': 4,
'short_message': 'random stuff',
'message_id': 'od9s2'
},
'tlvs': {
'receipted_message_id': {
'tagId': 0x001E,
'tagName': 'receipted_message_id',
'tagValue': '293f293'
'tagId': 0x001E,
'tagName': 'receipted_message_id',
'tagValue': '293f293'
},
'5142': {
'tagId': 5142,
'tagName': 'Nils',
'tagValue': new Buffer('blajfoo', 'ascii')
'tagId': 5142,
'tagName': 'Nils',
'tagValue': new Buffer('blajfoo', 'ascii')
}
}
};
larvitsmpp.utils.pduReturn(pduObj, function(err, pduBuffer) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduReturn(pduObj, function (err, pduBuffer) {
if (err) throw err;
larvitsmpp.utils.pduToObj(pduBuffer, function(err, retPduObj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pduBuffer, function (err, retPduObj) {
if (err) throw err;
assert(retPduObj.cmdName === 'deliver_sm_resp', 'Command name should be "deliver_sm_resp"');
assert(retPduObj.cmdStatus === 'ESME_ROK', 'Command status should be ESME_ROK');
assert(retPduObj.params.message_id === 'od9s2', 'message_id should be correct');
assert.strictEqual(retPduObj.cmdName, 'deliver_sm_resp');
assert.strictEqual(retPduObj.cmdStatus, 'ESME_ROK');
assert.strictEqual(retPduObj.params.message_id, 'od9s2');
done();
});
});
});
it('should create a valid return PDU with custom param', function(done) {
var pduObj = {
'cmdName': 'deliver_sm',
'seqNr': 393,
'cmdStatus': 'ESME_ROK',
it('should create a valid return PDU with custom param', function (done) {
const pduObj = {
'cmdName': 'deliver_sm',
'seqNr': 393,
'cmdStatus': 'ESME_ROK',
'params': {
'source_addr': '46701113311',
'destination_addr': '46709771337',
'esm_class': 4,
'short_message': 'random stuff',
'message_id': 'od9s2'
'source_addr': '46701113311',
'destination_addr': '46709771337',
'esm_class': 4,
'short_message': 'random stuff',
'message_id': 'od9s2'
},
'tlvs': {
'receipted_message_id': {
'tagId': 0x001E,
'tagName': 'receipted_message_id',
'tagValue': '293f293'
'tagId': 0x001E,
'tagName': 'receipted_message_id',
'tagValue': '293f293'
},
'5142': {
'tagId': 5142,
'tagName': 'Nils',
'tagValue': new Buffer('blajfoo', 'ascii')
'tagId': 5142,
'tagName': 'Nils',
'tagValue': new Buffer('blajfoo', 'ascii')
}
}
};
larvitsmpp.utils.pduReturn(pduObj, 'ESME_RINVMSGID', {'message_id': 'mep'}, function(err, pduBuffer) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduReturn(pduObj, 'ESME_RINVMSGID', {'message_id': 'mep'}, function (err, pduBuffer) {
if (err) throw err;
larvitsmpp.utils.pduToObj(pduBuffer, function(err, retPduObj) {
assert( ! err, 'Error should be negative');
larvitsmpp.utils.pduToObj(pduBuffer, function (err, retPduObj) {
if (err) throw err;
assert(retPduObj.cmdName === 'deliver_sm_resp', 'Command name should be "deliver_sm_resp"');
assert(retPduObj.cmdStatus === 'ESME_RINVMSGID', 'Command status should be ESME_RINVMSGID');
assert(retPduObj.params.message_id === 'mep', 'message_id should be the overriden one');
assert.strictEqual(retPduObj.cmdName, 'deliver_sm_resp');
assert.strictEqual(retPduObj.cmdStatus, 'ESME_RINVMSGID');
assert.strictEqual(retPduObj.params.message_id, 'mep');
done();
});
@@ -386,44 +385,42 @@ describe('PDU convertion', function() {
});
});
describe('Message size and split', function() {
it('should calculate sizes of msgs', function(done) {
var a = 'abcd',
b = 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
c = 'Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi',
d = 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdHIHIHIHI foobar',
e = 'Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi',
f = 'abcd€abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
g = 'Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi bara lite längre';
describe('Message size and split', function () {
it('should calculate sizes of msgs', function (done) {
const a = 'abcd',
b = 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
c = 'Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi',
d = 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdHIHIHIHI foobar',
e = 'Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi',
f = 'abcd€abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
g = 'Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi bara lite längre';
assert(larvitsmpp.utils.bitCount(a) === 28, 'ASCII');
assert(larvitsmpp.utils.bitCount(b) === 1120, 'ASCII');
assert(larvitsmpp.utils.bitCount(b, 'UCS2') === 2560, 'ASCII, expected 2560 but got ' + larvitsmpp.utils.bitCount(b, 'UCS2'));
assert(larvitsmpp.utils.bitCount(c) === 1120, 'UCS2');
assert(larvitsmpp.utils.bitCount(d) === 1225, 'ASCII');
assert(larvitsmpp.utils.bitCount(e) === 4528, 'UCS2');
assert(larvitsmpp.utils.bitCount(f) === 1120, 'ASCII with special char');
assert(larvitsmpp.utils.bitCount(g) === 1392, 'UCS2');
assert(larvitsmpp.utils.splitMsg(a).length === 1);
assert(larvitsmpp.utils.splitMsg(b).length === 1);
assert(larvitsmpp.utils.splitMsg(b, 'UCS2').length === 3, 'Expected length 2, but got ' + larvitsmpp.utils.splitMsg(b, 'UCS2').length);
assert(larvitsmpp.utils.splitMsg(c).length === 1);
assert(larvitsmpp.utils.splitMsg(d).length === 2);
assert(larvitsmpp.utils.splitMsg(e).length === 5);
assert(larvitsmpp.utils.splitMsg(f).length === 1);
assert(larvitsmpp.utils.splitMsg(g).length === 2);
assert.strictEqual(larvitsmpp.utils.bitCount(a), 28);
assert.strictEqual(larvitsmpp.utils.bitCount(b), 1120);
assert.strictEqual(larvitsmpp.utils.bitCount(b, 'UCS2'), 2560);
assert.strictEqual(larvitsmpp.utils.bitCount(c), 1120);
assert.strictEqual(larvitsmpp.utils.bitCount(d), 1225);
assert.strictEqual(larvitsmpp.utils.bitCount(e), 4528);
assert.strictEqual(larvitsmpp.utils.bitCount(f), 1120);
assert.strictEqual(larvitsmpp.utils.bitCount(g), 1392);
assert.strictEqual(larvitsmpp.utils.splitMsg(a).length, 1);
assert.strictEqual(larvitsmpp.utils.splitMsg(b).length, 1);
assert.strictEqual(larvitsmpp.utils.splitMsg(b, 'UCS2').length, 3);
assert.strictEqual(larvitsmpp.utils.splitMsg(c).length, 1);
assert.strictEqual(larvitsmpp.utils.splitMsg(d).length, 2);
assert.strictEqual(larvitsmpp.utils.splitMsg(e).length, 5);
assert.strictEqual(larvitsmpp.utils.splitMsg(f).length, 1);
assert.strictEqual(larvitsmpp.utils.splitMsg(g).length, 2);
done();
});
it('should return an array with a buffer equalling the input msg', function(done) {
var msg = 'hello world',
msgs = larvitsmpp.utils.splitMsg(msg);
it('should return an array with a buffer equalling the input msg', function (done) {
const msg = 'hello world',
msgs = larvitsmpp.utils.splitMsg(msg);
assert(msgs[0].toString() === msg, 'Messages should equal');
assert.strictEqual(msgs[0].toString(), msg);
done();
});
});
});
+249 -249
View File
@@ -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();
});
+12
View File
@@ -0,0 +1,12 @@
'use strict';
require(
'mocha-eslint')([__dirname + '/..'],
{
// Increase the timeout of the test if linting takes to long
'timeout': 5000, // Defaults to the global mocha `timeout` option
// Increase the time until a test is marked as slow
'slow': 1000, // Defaults to the global mocha `slow` option
}
);