Created
July 24, 2015 14:25
-
-
Save neich/b4788c093a100ade7cfe to your computer and use it in GitHub Desktop.
COAP library crashes when it receives two confimable responses with the same messageId & token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2013-2015 node-coap contributors. | |
* | |
* node-coap is licensed under an MIT +no-false-attribs license. | |
* All rights not explicitly granted in the MIT license are reserved. | |
* See the included LICENSE file for more details. | |
*/ | |
var coap = require('../../') | |
, parse = require('coap-packet').parse | |
, generate = require('coap-packet').generate | |
, dgram = require('dgram') | |
, bl = require('bl') | |
, sinon = require('sinon') | |
, request = coap.request | |
describe('request', function() { | |
var server | |
, server2 | |
, port | |
beforeEach(function (done) { | |
port = nextPort() | |
server = dgram.createSocket('udp4') | |
server.bind(port, done) | |
}) | |
afterEach(function () { | |
server.close() | |
if (server2) | |
server2.close() | |
server = server2 = null | |
}) | |
function ackBack(msg, rsinfo) { | |
var packet = parse(msg) | |
, toSend = generate({ | |
messageId: packet.messageId | |
, ack: true | |
, code: '0.00' | |
}) | |
server.send(toSend, 0, toSend.length, rsinfo.port, rsinfo.address) | |
} | |
it('should not crash with a response with a delayed CON message and same messageId & token', function (done) { | |
var req = request({ | |
port: port | |
, confirmable: true | |
}) | |
server.once('message', function (msg, rsinfo) { | |
var packet = parse(msg) | |
, toSend = generate({ | |
token: packet.token | |
, messageId: packet.messageId | |
, payload: new Buffer('42') | |
, confirmable: true | |
, code: '2.00' | |
}) | |
server.send(toSend, 0, toSend.length, rsinfo.port, rsinfo.address) | |
toSend = generate({ | |
token: packet.token | |
, messageId: packet.messageId | |
, payload: new Buffer('42') | |
, confirmable: true | |
, code: '2.00' | |
}) | |
server.send(toSend, 0, toSend.length, rsinfo.port, rsinfo.address) | |
}) | |
req.on('response', function (res) { | |
res.pipe(bl(function (err, data) { | |
expect(data).to.eql(new Buffer('42')) | |
done() | |
})) | |
}) | |
req.end() | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment