Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from azuqua/fix/argsWithProtocol
Browse files Browse the repository at this point in the history
fix for duplicate protocol when provided a host arg with protocol
  • Loading branch information
stegmanh authored Nov 10, 2017
2 parents da69ef9 + f146d66 commit 4d1843d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions clients/server/token-sockjs-ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(":");
Expand Down
12 changes: 10 additions & 2 deletions test/server/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -128,4 +136,4 @@ module.exports = function(TokenSocket, mocks){

});

};
};

0 comments on commit 4d1843d

Please sign in to comment.