Skip to content

Commit

Permalink
Merge pull request #45 from dmoranj/serverShutDownOnUnexpectedOption
Browse files Browse the repository at this point in the history
Server shut down on unexpected option
  • Loading branch information
mcollina committed Mar 4, 2015
2 parents 1cd233c + c121734 commit ff3b031
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ CoAPServer.prototype.listen = function(port, address, done) {
return that._sendError(new Buffer('Unable to parse packet'), rsinfo)
}

that._handle(packet, rsinfo)
try {
that._handle(packet, rsinfo)
} catch(err) {
return that._sendError(new Buffer(err.message), rsinfo)
}
})

this._sock.bind(port, address || null, done || null)
Expand Down
24 changes: 24 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,30 @@ describe('server', function() {
}
})

describe('with the \'Content-Format\' header and a wrong value in the request', function() {
it('should return a 5.00 error to the cliend', function(done) {
send(generate({
options: [{
name: 'Content-Format'
, value: new Buffer([1541])
}]
}))

client.on('message', function(msg) {
var response = parse(msg);

expect(response.code).to.equal('5.00')
expect(response.payload.toString()).to.equal('No matching format found')

done()
})

server.on('request', function(req) {
assert(false, 'This should not happen')
})
})
})

describe('with a non-confirmable message', function() {
var packet = {
confirmable: false
Expand Down

0 comments on commit ff3b031

Please sign in to comment.