@@ -30,33 +30,44 @@ describe("Connect to remote server", function() {
3030 assert ( wsConstructor . calledOnce ) ;
3131 assert ( wsConstructor . calledWithNew ( ) ) ;
3232 assert ( wsConstructor . call ) ;
33- assert . deepEqual ( wsConstructor . args , [ [ 'ws://localhost:3000/websocket' ] ] ) ;
33+ assert . deepEqual ( wsConstructor . args , [ [ 'ws://localhost:3000/websocket' , null , { } ] ] ) ;
3434 } ) ;
3535
3636 it ( 'should connect to the provided host' , function ( ) {
3737 new DDPClient ( { 'host' : 'myserver.com' } ) . connect ( ) ;
38- assert . deepEqual ( wsConstructor . args , [ [ 'ws://myserver.com:3000/websocket' ] ] ) ;
38+ assert . deepEqual ( wsConstructor . args , [ [ 'ws://myserver.com:3000/websocket' , null , { } ] ] ) ;
3939 } ) ;
4040
4141 it ( 'should connect to the provided host and port' , function ( ) {
4242 new DDPClient ( { 'host' : 'myserver.com' , 'port' : 42 } ) . connect ( ) ;
43- assert . deepEqual ( wsConstructor . args , [ [ 'ws://myserver.com:42/websocket' ] ] ) ;
43+ assert . deepEqual ( wsConstructor . args , [ [ 'ws://myserver.com:42/websocket' , null , { } ] ] ) ;
4444 } ) ;
4545
4646 it ( 'should use ssl if the port is 443' , function ( ) {
4747 new DDPClient ( { 'host' : 'myserver.com' , 'port' : 443 } ) . connect ( ) ;
48- assert . deepEqual ( wsConstructor . args , [ [ 'wss://myserver.com:443/websocket' ] ] ) ;
48+ assert . deepEqual ( wsConstructor . args , [ [ 'wss://myserver.com:443/websocket' , null , { } ] ] ) ;
4949 } ) ;
50+
51+ it ( 'should propagate tls options if specified' , function ( ) {
52+ var tlsOpts = {
53+ 'ca' : [ 'fake_pem_content' ]
54+ }
55+ new DDPClient ( { 'host' : 'myserver.com' , 'port' : 443 , 'tlsOpts' : tlsOpts } ) . connect ( ) ;
56+ assert . deepEqual ( wsConstructor . args , [ [ 'wss://myserver.com:443/websocket' , null , tlsOpts ] ] ) ;
57+ } ) ;
58+
5059 it ( 'should connect to the provided url' , function ( ) {
5160 new DDPClient ( { 'url' : 'wss://myserver.com/websocket' } ) . connect ( ) ;
52- assert . deepEqual ( wsConstructor . args , [ [ 'wss://myserver.com/websocket' ] ] ) ;
61+ assert . deepEqual ( wsConstructor . args , [ [ 'wss://myserver.com/websocket' , null , { } ] ] ) ;
5362 } ) ;
63+
5464 it ( 'should fallback to sockjs if url and useSockJs:true are provided' , function ( ) {
5565 var ddpclient = new DDPClient ( { 'url' : 'wss://myserver.com/websocket' , 'useSockJs' : true } ) ;
5666 ddpclient . _makeSockJSConnection = sinon . stub ( ) ;
5767 ddpclient . connect ( ) ;
5868 assert . ok ( ddpclient . _makeSockJSConnection . called ) ;
5969 } ) ;
70+
6071 it ( 'should clear event listeners on close' , function ( done ) {
6172 var ddpclient = new DDPClient ( ) ;
6273 var callback = sinon . stub ( ) ;
@@ -297,8 +308,8 @@ describe("SockJS", function() {
297308 describe ( "after info hit" , function ( ) {
298309 var request = require ( "request" ) ;
299310 it ( "should connect to the correct url" , function ( done ) {
300- var get = function ( url , callback ) {
301- assert . equal ( url , "http://the-host:9000/sockjs/info" ) ;
311+ var get = function ( opts , callback ) {
312+ assert . equal ( opts . url , "http://the-host:9000/sockjs/info" ) ;
302313 done ( ) ;
303314 } ;
304315
@@ -313,8 +324,8 @@ describe("SockJS", function() {
313324 } ) ;
314325
315326 it ( "should support custom paths" , function ( done ) {
316- var get = function ( url , callback ) {
317- assert . equal ( url , "http://the-host:9000/search/sockjs/info" ) ;
327+ var get = function ( opts , callback ) {
328+ assert . equal ( opts . url , "http://the-host:9000/search/sockjs/info" ) ;
318329 done ( ) ;
319330 } ;
320331
@@ -331,7 +342,7 @@ describe("SockJS", function() {
331342
332343 it ( "should retry if there is an error" , function ( ) {
333344 var error = { message : "error" } ;
334- var get = function ( url , callback ) {
345+ var get = function ( opts , callback ) {
335346 callback ( error ) ;
336347 } ;
337348
@@ -345,7 +356,7 @@ describe("SockJS", function() {
345356
346357 it ( "should use direct WS if there is no body" , function ( ) {
347358 var info = null ;
348- var get = function ( url , callback ) {
359+ var get = function ( opts , callback ) {
349360 callback ( null , null , info ) ;
350361 } ;
351362
@@ -361,7 +372,7 @@ describe("SockJS", function() {
361372
362373 it ( "should use direct WS if there is no base_url" , function ( ) {
363374 var info = '{}' ;
364- var get = function ( url , callback ) {
375+ var get = function ( opts , callback ) {
365376 callback ( null , null , info ) ;
366377 } ;
367378
@@ -377,7 +388,7 @@ describe("SockJS", function() {
377388
378389 it ( "should use full base url if it's starts with http" , function ( ) {
379390 var info = '{"base_url": "https://somepath"}' ;
380- var get = function ( url , callback ) {
391+ var get = function ( opts , callback ) {
381392 callback ( null , null , info ) ;
382393 } ;
383394
@@ -393,7 +404,7 @@ describe("SockJS", function() {
393404
394405 it ( "should compute url based on the base_url if it's not starts with http" , function ( ) {
395406 var info = '{"base_url": "/somepath"}' ;
396- var get = function ( url , callback ) {
407+ var get = function ( opts , callback ) {
397408 callback ( null , null , info ) ;
398409 } ;
399410
@@ -406,6 +417,25 @@ describe("SockJS", function() {
406417 assert . ok ( ddpclient . _makeWebSocketConnection . calledWith ( wsUrl ) ) ;
407418 } ) ;
408419 } ) ;
420+
421+ it ( "should propagate tls options" , function ( done ) {
422+ var tlsOpts = { 'ca' : [ 'fake_pem_content' ] } ;
423+ var get = function ( opts , callback ) {
424+ assert . equal ( opts . agentOptions , tlsOpts ) ;
425+ done ( ) ;
426+ } ;
427+
428+ WithRequestGet ( get , function ( ) {
429+ var opts = {
430+ host : "the-host" ,
431+ port : 9000 ,
432+ path : "search" ,
433+ tlsOpts : tlsOpts
434+ } ;
435+ var ddpclient = new DDPClient ( opts ) ;
436+ ddpclient . _makeSockJSConnection ( ) ;
437+ } ) ;
438+ } ) ;
409439 } ) ;
410440} ) ;
411441
0 commit comments