Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix crash when port is not provided for bind.
  • Loading branch information
Gogs committed Jun 10, 2017
1 parent 24dc807 commit cfaf852
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/socket/conn.js
Expand Up @@ -27,6 +27,14 @@ exports.parseConnectionUri = function(uri) {
throw new Error(err)
}

if (!target.port)
target.port = 0

if (!target.host) {
target.hostname = '127.0.0.1'
target.host = '127.0.0.1' + (target.port ? ':' + target.port : '')
}

return {
target: target,
protocol: protocol,
Expand Down
2 changes: 1 addition & 1 deletion test/default.js
Expand Up @@ -3,7 +3,7 @@ var socketmq = require('../index')

module.exports = function(name, T, smqServer, smqClient1, smqClient2, endpoint, options) {
// 4 were in the tcp/tls/eio transport tests
T.plan(24)
T.plan(25)

var serverStream1
var serverStream2
Expand Down
4 changes: 4 additions & 0 deletions test/eio.test.js
Expand Up @@ -21,6 +21,10 @@ module.exports = function() {
t.ok(event.stream, 'eio has stream instance in error event')
})

var noport = 'eio://'
socketmq.bind(noport)
t.pass('Bind should not crash when no port is not provided.')

testDefault('eio', t, smqServer, smqClient1, smqClient2, endpoint)
})
}
4 changes: 4 additions & 0 deletions test/tcp.test.js
Expand Up @@ -21,6 +21,10 @@ module.exports = function() {
t.ok(event.stream, 'tcp has stream instance in error event')
})

var noport = 'tcp://'
socketmq.bind(noport)
t.pass('Bind should not crash when no port is not provided.')

testDefault('tcp', t, smqServer, smqClient1, smqClient2, endpoint)
})
}
4 changes: 4 additions & 0 deletions test/tls.test.js
Expand Up @@ -36,6 +36,10 @@ module.exports = function() {
t.ok(event.stream, 'tls has stream instance in error event')
})

var noport = 'tls://'
socketmq.bind(noport)
t.pass('Bind should not crash when no port is not provided.')

testDefault('tls', t, smqServer, smqClient1, smqClient2, endpoint, clientOptions)
})
}

0 comments on commit cfaf852

Please sign in to comment.