Skip to content

Commit 891571b

Browse files
committed
add tests for ssl mode with request port check
1 parent 37b9f76 commit 891571b

5 files changed

Lines changed: 79 additions & 3 deletions

File tree

node.js/Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function (grunt) {
99
quiet: false
1010
},
1111
// NOTICE: ignore test2.js test due it's
12-
src: ['tests/ssl_test.js', 'tests/test.js', 'tests/tests.js']
12+
src: ['tests/ssl_test.js', 'tests/test.js']
1313
},
1414
unit: 'karma.conf.js'
1515
},

node.js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"grunt-contrib-nodeunit": "^0.4.1",
4141
"grunt-mocha-test": "^0.12.7",
4242
"mocha": "^2.1.0",
43+
"nock": "^1.1.0",
4344
"nodeunit": "^0.9.0",
4445
"underscore": "^1.7.0"
4546
},

node.js/tests/ssl_test.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
var 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

69
describe("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

node.js/tests/test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var PUBNUB = require('../pubnub.js'),
22
assert = require('assert'),
3-
_ = require("underscore");
3+
_ = require("underscore"),
4+
nock = require('nock');
45

56
var pubnub = PUBNUB.init({
67
publish_key : 'ds',
@@ -87,6 +88,10 @@ describe('Pubnub', function() {
8788
});
8889
})
8990

91+
beforeEach(function () {
92+
nock.enableNetConnect();
93+
});
94+
9095
after(function(){
9196
for (var i in namespaces) {
9297
var namespace = namespaces[i];

node.js/tests/tests.js

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
21
var assert = require('assert');
32
var PUBNUB = require('../pubnub.js');
43
var _ = require("underscore");
4+
5+
require('nock').enableNetConnect();
6+
57
var pubnub = PUBNUB.init({
68
publish_key : 'ds',
79
subscribe_key : 'ds',

0 commit comments

Comments
 (0)