diff --git a/clients/server/token-sockjs-ws.js b/clients/server/token-sockjs-ws.js index 930b64a..de807d2 100644 --- a/clients/server/token-sockjs-ws.js +++ b/clients/server/token-sockjs-ws.js @@ -214,6 +214,9 @@ var TokenSocket = function(options, actions){ var parsed = url.parse(options.host); options.protocol = parsed.protocol === "https:" ? "https:" : "http:"; + if (parsed.protocol) { + options.host = parsed.host; + } if(!options.port){ var parts = options.host.split(":"); diff --git a/test/server/unit.js b/test/server/unit.js index 31ee374..6444fe4 100644 --- a/test/server/unit.js +++ b/test/server/unit.js @@ -46,7 +46,15 @@ module.exports = function(TokenSocket, mocks){ assert.property(socketReq, "token", "Socket auth request has token property"); assert.equal(socketReq.token, token, "Socket auth request has correct token"); }); - + + it("Should create a valid socket URL when passed a host argument that includes protocol", function(){ + assert.doesNotThrow(function(){ + var socket = new TokenSocket({ host: 'http://foo.com' }); + var req = socket._rest._requests.shift(); + assert.isOk(req.options.host.indexOf('http') === -1, 'parsed host does not include protocol'); + }, "Constructor does not create an invalid url when passed a host argument that includes protocol"); + }); + it("Should not throw an error when created with all possible arguments", function(done){ assert.doesNotThrow(function(){ var socket = new TokenSocket({ @@ -128,4 +136,4 @@ module.exports = function(TokenSocket, mocks){ }); -}; \ No newline at end of file +};