forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssl_test.js
More file actions
executable file
·125 lines (106 loc) · 3.89 KB
/
Copy pathssl_test.js
File metadata and controls
executable file
·125 lines (106 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var PUBNUB = require('../pubnub.js'),
assert = require("assert"),
nock = require("nock"),
channel = "test_javascript_ssl",
origin = 'blah.pubnub.com',
uuid = "me",
message = "hello";
describe("When SSL mode", function () {
after(function () {
nock.enableNetConnect();
});
describe("is enabled", function () {
it("should be able to successfully subscribe to the channel and publish message to it ", function (done) {
this.timeout(5000);
nock.enableNetConnect();
var pubnub = PUBNUB.init({
publish_key : 'demo',
subscribe_key : 'demo',
ssl : true,
origin : 'pubsub.pubnub.com'
});
subscribeAndPublish(pubnub, channel + "_enabled_" + get_random(), done);
});
it("should send requests via HTTPS to 443 port", function (done) {
nock.disableNetConnect();
var pubnub = PUBNUB.init({
publish_key : 'demo',
subscribe_key : 'demo',
ssl : true,
origin : origin,
uuid : uuid
});
var path = "/publish/demo/demo/0/" + channel + "/0/" + encodeURI('"' + message + '"') +
"?uuid=" + uuid + "&pnsdk=PubNub-JS-Nodejs%2F3.7.10";
nock("https://" + origin + ":443")
.get(path)
.reply(200, [[message], "14264384975359568", channel]);
pubnub.publish({
channel: channel,
message: message,
callback: function () {
done();
},
error: function () {
done(new Error("Error callback triggered"));
}
});
});
});
describe("is disabled", function () {
it("should be able to successfully subscribe to the channel and publish message to it ", function (done) {
this.timeout(5000);
nock.enableNetConnect();
var pubnub = PUBNUB.init({
publish_key : 'demo',
subscribe_key : 'demo',
ssl : false,
origin : 'pubsub.pubnub.com'
});
subscribeAndPublish(pubnub, channel + "_disabled_" + get_random(), done);
});
it("should send requests via HTTP to 80 port", function (done) {
nock.disableNetConnect();
var pubnub = PUBNUB.init({
publish_key : 'demo',
subscribe_key : 'demo',
origin : origin,
uuid : uuid
});
var path = "/publish/demo/demo/0/" + channel + "/0/" + encodeURI('"' + message + '"') +
"?uuid=" + uuid + "&pnsdk=PubNub-JS-Nodejs%2F3.7.10";
nock("http://" + origin + ":80")
.get(path)
.reply(200, [[message], "14264384975359568", channel]);
pubnub.publish({
channel: channel,
message: message,
callback: function () {
done();
},
error: function () {
done(new Error("Error callback triggered"));
}
});
});
});
});
function subscribeAndPublish(pubnub, channel, done) {
pubnub.subscribe({
channel: channel,
connect: function () {
pubnub.publish({
channel: channel,
message: message
})
},
callback: function (msg, envelope, ch) {
assert.equal(message, msg);
assert.equal(channel, ch);
done();
}
});
}
function get_random(max) {
return Math.floor((Math.random() * (max || 1000000000) + 1))
}