11var PUBNUB = require ( '../pubnub.js' ) ,
22 assert = require ( "assert" ) ,
3+ nock = require ( "nock" ) ,
34 channel = "test_javascript_ssl" ,
5+ origin = 'blah.pubnub.com' ,
6+ uuid = "me" ,
47 message = "hello" ;
58
69describe ( "When SSL mode" , function ( ) {
10+ after ( function ( ) {
11+ nock . enableNetConnect ( ) ;
12+ } ) ;
13+
714 describe ( "is enabled" , function ( ) {
815 it ( "should be able to successfully subscribe to the channel and publish message to it " , function ( done ) {
916 this . timeout ( 5000 ) ;
17+ nock . enableNetConnect ( ) ;
1018
1119 var pubnub = PUBNUB . init ( {
1220 publish_key : 'demo' ,
@@ -17,11 +25,42 @@ describe("When SSL mode", function () {
1725
1826 subscribeAndPublish ( pubnub , channel + "_enabled" , done ) ;
1927 } ) ;
28+
29+ it ( "should send requests via HTTPS to 443 port" , function ( done ) {
30+ nock . disableNetConnect ( ) ;
31+
32+ var pubnub = PUBNUB . init ( {
33+ publish_key : 'demo' ,
34+ subscribe_key : 'demo' ,
35+ ssl : true ,
36+ origin : origin ,
37+ uuid : uuid
38+ } ) ;
39+
40+ var path = "/publish/demo/demo/0/" + channel + "/0/" + encodeURI ( '"' + message + '"' ) +
41+ "?uuid=" + uuid + "&pnsdk=PubNub-JS-Nodejs%2F3.7.9" ;
42+
43+ nock ( "https://" + origin + ":443" )
44+ . get ( path )
45+ . reply ( 200 , [ [ message ] , "14264384975359568" , channel ] ) ;
46+
47+ pubnub . publish ( {
48+ channel : channel ,
49+ message : message ,
50+ callback : function ( ) {
51+ done ( ) ;
52+ } ,
53+ error : function ( ) {
54+ done ( new Error ( "Error callback triggered" ) ) ;
55+ }
56+ } ) ;
57+ } ) ;
2058 } ) ;
2159
2260 describe ( "is disabled" , function ( ) {
2361 it ( "should be able to successfully subscribe to the channel and publish message to it " , function ( done ) {
2462 this . timeout ( 5000 ) ;
63+ nock . enableNetConnect ( ) ;
2564
2665 var pubnub = PUBNUB . init ( {
2766 publish_key : 'demo' ,
@@ -32,6 +71,35 @@ describe("When SSL mode", function () {
3271
3372 subscribeAndPublish ( pubnub , channel + "_disabled" , done ) ;
3473 } ) ;
74+
75+ it ( "should send requests via HTTP to 80 port" , function ( done ) {
76+ nock . disableNetConnect ( ) ;
77+
78+ var pubnub = PUBNUB . init ( {
79+ publish_key : 'demo' ,
80+ subscribe_key : 'demo' ,
81+ origin : origin ,
82+ uuid : uuid
83+ } ) ;
84+
85+ var path = "/publish/demo/demo/0/" + channel + "/0/" + encodeURI ( '"' + message + '"' ) +
86+ "?uuid=" + uuid + "&pnsdk=PubNub-JS-Nodejs%2F3.7.9" ;
87+
88+ nock ( "http://" + origin + ":80" )
89+ . get ( path )
90+ . reply ( 200 , [ [ message ] , "14264384975359568" , channel ] ) ;
91+
92+ pubnub . publish ( {
93+ channel : channel ,
94+ message : message ,
95+ callback : function ( ) {
96+ done ( ) ;
97+ } ,
98+ error : function ( ) {
99+ done ( new Error ( "Error callback triggered" ) ) ;
100+ }
101+ } ) ;
102+ } ) ;
35103 } ) ;
36104} ) ;
37105
0 commit comments