pusher-js 7.0.6 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +27 -87
- package/dist/node/pusher.js +325 -73
- package/dist/node/pusher.js.map +1 -1
- package/dist/react-native/pusher.js +2 -2
- package/dist/react-native/pusher.js.map +1 -1
- package/dist/web/pusher-with-encryption.js +330 -78
- package/dist/web/pusher-with-encryption.js.map +1 -1
- package/dist/web/pusher-with-encryption.min.js +2 -2
- package/dist/web/pusher-with-encryption.min.js.map +1 -1
- package/dist/web/pusher.js +330 -78
- package/dist/web/pusher.js.map +1 -1
- package/dist/web/pusher.min.js +2 -2
- package/dist/web/pusher.min.js.map +1 -1
- package/dist/worker/pusher-with-encryption.worker.js +314 -69
- package/dist/worker/pusher-with-encryption.worker.js.map +1 -1
- package/dist/worker/pusher-with-encryption.worker.min.js +2 -2
- package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -1
- package/dist/worker/pusher.worker.js +314 -69
- package/dist/worker/pusher.worker.js.map +1 -1
- package/dist/worker/pusher.worker.min.js +2 -2
- package/dist/worker/pusher.worker.min.js.map +1 -1
- package/index.d.ts +8 -3
- package/package.json +2 -2
- package/spec/config/karma/config.worker.js +3 -0
- package/spec/config/karma/integration.js +4 -2
- package/spec/javascripts/helpers/mocks.js +41 -8
- package/spec/javascripts/helpers/worker/mock-dom-dependencies.js +1 -0
- package/spec/javascripts/integration/core/cluster_config_spec.js +8 -0
- package/spec/javascripts/integration/core/timeout_configuration_spec.js +1 -0
- package/spec/javascripts/integration/index.worker.js +12 -1
- package/spec/javascripts/unit/core/channels/channel_spec.js +25 -0
- package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +64 -66
- package/spec/javascripts/unit/core/channels/presence_channel_spec.js +51 -41
- package/spec/javascripts/unit/core/channels/private_channel_spec.js +8 -46
- package/spec/javascripts/unit/core/config_spec.js +307 -7
- package/spec/javascripts/unit/core/connection/connection_manager_spec.js +1 -0
- package/spec/javascripts/unit/core/http/http_socket_spec.js +1 -0
- package/spec/javascripts/unit/core/logger_spec.js +21 -20
- package/spec/javascripts/unit/core/pusher_spec.js +67 -39
- package/spec/javascripts/unit/core/pusher_with_encryption_spec.js +2 -0
- package/spec/javascripts/unit/core/strategies/cached_strategy_spec.js +1 -0
- package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +1 -0
- package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +1 -0
- package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +1 -0
- package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +1 -0
- package/spec/javascripts/unit/core/user_spec.js +295 -0
- package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +4 -1
- package/spec/javascripts/unit/core/utils/timers_spec.js +6 -0
- package/spec/javascripts/unit/core/utils/url_store_spec.js +1 -1
- package/spec/javascripts/unit/core_with_runtime/auth/channel_authorizer_spec.js +55 -0
- package/spec/javascripts/unit/core_with_runtime/auth/deprecated_channel_authorizer_spec.js +48 -0
- package/spec/javascripts/unit/core_with_runtime/auth/user_authorizer_spec.js +52 -0
- package/spec/javascripts/unit/core_with_runtime/readme.md +5 -0
- package/spec/javascripts/unit/index.node.js +3 -0
- package/spec/javascripts/unit/index.web.js +3 -0
- package/spec/javascripts/unit/index.worker.js +3 -0
- package/spec/javascripts/unit/web/pusher_authorizer_spec.js +15 -16
- package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +1 -0
- package/spec/javascripts/unit/worker/channel_authorizer_spec.js +110 -0
- package/src/core/auth/auth_transports.ts +8 -1
- package/src/core/auth/channel_authorizer.ts +53 -0
- package/src/core/auth/deprecated_channel_authorizer.ts +58 -0
- package/src/core/auth/options.ts +52 -17
- package/src/core/auth/user_authenticator.ts +51 -0
- package/src/core/channels/channel.ts +17 -3
- package/src/core/channels/channels.ts +4 -0
- package/src/core/channels/encrypted_channel.ts +26 -20
- package/src/core/channels/presence_channel.ts +5 -2
- package/src/core/channels/private_channel.ts +9 -4
- package/src/core/config.ts +76 -11
- package/src/core/defaults.ts +15 -0
- package/src/core/errors.ts +9 -0
- package/src/core/options.ts +18 -5
- package/src/core/pusher.ts +9 -1
- package/src/core/user.ts +143 -0
- package/src/core/utils/factory.ts +1 -10
- package/src/core/utils/url_store.ts +4 -1
- package/src/runtimes/isomorphic/auth/xhr_auth.ts +32 -19
- package/src/runtimes/web/auth/jsonp_auth.ts +13 -7
- package/src/runtimes/worker/auth/fetch_auth.ts +17 -12
- package/types/src/core/auth/auth_transports.d.ts +2 -1
- package/types/src/core/auth/channel_authorizer.d.ts +3 -0
- package/types/src/core/auth/deprecated_channel_authorizer.d.ts +18 -0
- package/types/src/core/auth/options.d.ts +34 -15
- package/types/src/core/auth/user_authenticator.d.ts +3 -0
- package/types/src/core/channels/channel.d.ts +4 -2
- package/types/src/core/channels/encrypted_channel.d.ts +2 -2
- package/types/src/core/channels/private_channel.d.ts +2 -2
- package/types/src/core/config.d.ts +4 -6
- package/types/src/core/defaults.d.ts +3 -0
- package/types/src/core/errors.d.ts +3 -0
- package/types/src/core/options.d.ts +6 -3
- package/types/src/core/pusher.d.ts +3 -0
- package/types/src/core/user.d.ts +15 -0
- package/types/src/core/utils/factory.d.ts +0 -2
- package/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts +1 -1
- package/worker/with-encryption/index.js +1 -1
- package/spec/javascripts/unit/core/pusher_authorizer_spec.js +0 -160
- package/spec/javascripts/unit/worker/pusher_authorizer_spec.js +0 -111
- package/src/core/auth/pusher_authorizer.ts +0 -64
- package/types/index.d.ts +0 -15
- package/types/src/core/auth/pusher_authorizer.d.ts +0 -13
- package/types/src/core/index.d.ts +0 -6
- package/types/src/runtimes/react-native/tweetnacl-dummy.d.ts +0 -5
- package/types/src/runtimes/react-native/tweetnacl-util-dummy.d.ts +0 -7
|
@@ -46,13 +46,6 @@ describe('Config', function() {
|
|
|
46
46
|
pongTimeout: 123,
|
|
47
47
|
activityTimeout: 345,
|
|
48
48
|
ignoreNullOrigin: true,
|
|
49
|
-
authorizer: () => {},
|
|
50
|
-
authTransport: 'some-auth-transport',
|
|
51
|
-
authEndpoint: '/pusher/spec/auth',
|
|
52
|
-
auth: {
|
|
53
|
-
params: { spec: 'param' },
|
|
54
|
-
headers: { spec: 'header' }
|
|
55
|
-
},
|
|
56
49
|
wsHost: 'ws-spec.pusher.com',
|
|
57
50
|
wsPort: 2020,
|
|
58
51
|
wssPort: 2021,
|
|
@@ -68,6 +61,313 @@ describe('Config', function() {
|
|
|
68
61
|
}
|
|
69
62
|
});
|
|
70
63
|
|
|
64
|
+
describe('auth', function(){
|
|
65
|
+
let _getAuthorizers;
|
|
66
|
+
let transportAuthorizer;
|
|
67
|
+
let transportAuthorizer2;
|
|
68
|
+
let transportAuthorizerAjax;
|
|
69
|
+
|
|
70
|
+
beforeAll(function() {
|
|
71
|
+
_getAuthorizers = Runtime.getAuthorizers;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
afterAll(function() {
|
|
75
|
+
Runtime.getAuthorizers = _getAuthorizers;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
beforeEach(function() {
|
|
79
|
+
transportAuthorizer = jasmine.createSpy("some-auth-transport")
|
|
80
|
+
transportAuthorizer2 = jasmine.createSpy("some-auth-transport2")
|
|
81
|
+
transportAuthorizerAjax = jasmine.createSpy("ajax")
|
|
82
|
+
Runtime.getAuthorizers = jasmine.createSpy("getAuthorizers").and.returnValue({
|
|
83
|
+
'some-auth-transport': transportAuthorizer,
|
|
84
|
+
'some-auth-transport2': transportAuthorizer2,
|
|
85
|
+
|
|
86
|
+
// When we test channelAuthorizer, the userAuthenticator will be using
|
|
87
|
+
// the default ajax transport and vice versa.
|
|
88
|
+
'ajax': transportAuthorizerAjax,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should use deprecated auth options', function() {
|
|
93
|
+
let opts = {
|
|
94
|
+
authTransport: 'some-auth-transport',
|
|
95
|
+
authEndpoint: '/pusher/spec/auth',
|
|
96
|
+
auth: {
|
|
97
|
+
params: { foo: 'bar' },
|
|
98
|
+
headers: { spec: 'header' }
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
const pusher = {};
|
|
102
|
+
let config = Config.getConfig(opts, pusher);
|
|
103
|
+
|
|
104
|
+
let callback = function(){};
|
|
105
|
+
config.channelAuthorizer({
|
|
106
|
+
socketId: '1.23',
|
|
107
|
+
channelName: 'private-test',
|
|
108
|
+
}, callback);
|
|
109
|
+
|
|
110
|
+
authOptions = {
|
|
111
|
+
transport: 'some-auth-transport',
|
|
112
|
+
endpoint: '/pusher/spec/auth',
|
|
113
|
+
params: { foo: 'bar' },
|
|
114
|
+
headers: { spec: 'header' }
|
|
115
|
+
}
|
|
116
|
+
const query = 'socket_id=1.23&channel_name=private-test&foo=bar';
|
|
117
|
+
expect(transportAuthorizer.calls.count()).toEqual(1);
|
|
118
|
+
expect(transportAuthorizer).toHaveBeenCalledWith(
|
|
119
|
+
Runtime,
|
|
120
|
+
query,
|
|
121
|
+
authOptions,
|
|
122
|
+
"channel-authorization",
|
|
123
|
+
callback
|
|
124
|
+
);
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('should create ChannelAuthorizerProxy if authorizer is set', function() {
|
|
128
|
+
const authorizer = { authorize: jasmine.createSpy('authorize') };
|
|
129
|
+
const authorizerGenerator = jasmine.createSpy('authorizerGenerator').and.returnValue(authorizer);
|
|
130
|
+
let opts = {
|
|
131
|
+
authorizer: authorizerGenerator,
|
|
132
|
+
authTransport: 'some-auth-transport',
|
|
133
|
+
authEndpoint: '/pusher/spec/auth',
|
|
134
|
+
auth: {
|
|
135
|
+
params: { spec: 'param' },
|
|
136
|
+
headers: { spec: 'header' }
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
const channel = {name: 'private-test'};
|
|
140
|
+
const pusher = { channel: jasmine.createSpy('channel').and.returnValue(channel) };
|
|
141
|
+
let config = Config.getConfig(opts, pusher);
|
|
142
|
+
|
|
143
|
+
const callback = function(){};
|
|
144
|
+
config.channelAuthorizer({
|
|
145
|
+
socketId: '1.23',
|
|
146
|
+
channelName: 'private-test',
|
|
147
|
+
}, callback);
|
|
148
|
+
expect(authorizerGenerator).toHaveBeenCalledWith(channel, {
|
|
149
|
+
authTransport: 'some-auth-transport',
|
|
150
|
+
authEndpoint: '/pusher/spec/auth',
|
|
151
|
+
auth: {
|
|
152
|
+
params: { spec: 'param' },
|
|
153
|
+
headers: { spec: 'header' }
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
expect(authorizer.authorize).toHaveBeenCalledWith('1.23', callback);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should use channelAuthorization and override deprecated auth options', function() {
|
|
160
|
+
let opts = {
|
|
161
|
+
authTransport: 'some-auth-transport',
|
|
162
|
+
authEndpoint: '/pusher/spec/auth',
|
|
163
|
+
auth: {
|
|
164
|
+
params: { foo: 'bar' },
|
|
165
|
+
headers: { spec: 'header' }
|
|
166
|
+
},
|
|
167
|
+
channelAuthorization: {
|
|
168
|
+
transport: 'some-auth-transport2',
|
|
169
|
+
endpoint: '/pusher/spec/auth2',
|
|
170
|
+
params: { spec2: 'param2' },
|
|
171
|
+
headers: { spec2: 'header2' }
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const pusher = {};
|
|
175
|
+
let config = Config.getConfig(opts, pusher);
|
|
176
|
+
let callback = function(){};
|
|
177
|
+
config.channelAuthorizer({
|
|
178
|
+
socketId: '1.23',
|
|
179
|
+
channelName: 'private-test',
|
|
180
|
+
}, callback);
|
|
181
|
+
|
|
182
|
+
console.log(config);
|
|
183
|
+
authOptions = {
|
|
184
|
+
transport: 'some-auth-transport2',
|
|
185
|
+
endpoint: '/pusher/spec/auth2',
|
|
186
|
+
params: { spec2: 'param2' },
|
|
187
|
+
headers: { spec2: 'header2' }
|
|
188
|
+
}
|
|
189
|
+
const query = 'socket_id=1.23&channel_name=private-test&spec2=param2';
|
|
190
|
+
expect(transportAuthorizer.calls.count()).toEqual(0);
|
|
191
|
+
expect(transportAuthorizer2.calls.count()).toEqual(1);
|
|
192
|
+
expect(transportAuthorizer2).toHaveBeenCalledWith(
|
|
193
|
+
Runtime,
|
|
194
|
+
query,
|
|
195
|
+
authOptions,
|
|
196
|
+
"channel-authorization",
|
|
197
|
+
callback
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('should use default transport when not provided in channelAuthorization', function() {
|
|
202
|
+
let opts = {
|
|
203
|
+
authEndpoint: '/pusher/spec/auth',
|
|
204
|
+
auth: {
|
|
205
|
+
params: { foo: 'bar' },
|
|
206
|
+
headers: { spec: 'header' }
|
|
207
|
+
},
|
|
208
|
+
channelAuthorization: {
|
|
209
|
+
endpoint: '/pusher/spec/auth2',
|
|
210
|
+
params: { spec2: 'param2' },
|
|
211
|
+
headers: { spec2: 'header2' }
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const pusher = {};
|
|
215
|
+
let config = Config.getConfig(opts, pusher);
|
|
216
|
+
let callback = function(){};
|
|
217
|
+
config.channelAuthorizer({
|
|
218
|
+
socketId: '1.23',
|
|
219
|
+
channelName: 'private-test',
|
|
220
|
+
}, callback);
|
|
221
|
+
|
|
222
|
+
authOptions = {
|
|
223
|
+
transport: 'ajax',
|
|
224
|
+
endpoint: '/pusher/spec/auth2',
|
|
225
|
+
params: { spec2: 'param2' },
|
|
226
|
+
headers: { spec2: 'header2' }
|
|
227
|
+
}
|
|
228
|
+
const query = 'socket_id=1.23&channel_name=private-test&spec2=param2';
|
|
229
|
+
expect(transportAuthorizer.calls.count()).toEqual(0);
|
|
230
|
+
expect(transportAuthorizer2.calls.count()).toEqual(0);
|
|
231
|
+
expect(transportAuthorizerAjax.calls.count()).toEqual(1);
|
|
232
|
+
expect(transportAuthorizerAjax).toHaveBeenCalledWith(
|
|
233
|
+
Runtime,
|
|
234
|
+
query,
|
|
235
|
+
authOptions,
|
|
236
|
+
"channel-authorization",
|
|
237
|
+
callback
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
it('should use customerHandler inside channelAuthorization', function() {
|
|
243
|
+
const customHandler = jasmine.createSpy('customHandler');
|
|
244
|
+
let opts = {
|
|
245
|
+
channelAuthorization: {
|
|
246
|
+
transport: 'some-auth-transport',
|
|
247
|
+
endpoint: '/pusher/spec/auth',
|
|
248
|
+
params: { spec: 'param' },
|
|
249
|
+
headers: { spec: 'header' },
|
|
250
|
+
customHandler: customHandler
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const pusher = {};
|
|
255
|
+
let config = Config.getConfig(opts, pusher);
|
|
256
|
+
expect(config.channelAuthorizer).toEqual(customHandler);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should have default options for user authentication', function() {
|
|
260
|
+
let opts = {};
|
|
261
|
+
|
|
262
|
+
const pusher = {};
|
|
263
|
+
let config = Config.getConfig(opts, pusher);
|
|
264
|
+
let callback = function(){};
|
|
265
|
+
config.userAuthenticator({
|
|
266
|
+
socketId: '1.23',
|
|
267
|
+
}, callback);
|
|
268
|
+
|
|
269
|
+
authOptions = {
|
|
270
|
+
transport: 'ajax',
|
|
271
|
+
endpoint: '/pusher/user-auth',
|
|
272
|
+
}
|
|
273
|
+
const query = 'socket_id=1.23';
|
|
274
|
+
expect(transportAuthorizerAjax.calls.count()).toEqual(1);
|
|
275
|
+
expect(transportAuthorizerAjax).toHaveBeenCalledWith(
|
|
276
|
+
Runtime,
|
|
277
|
+
query,
|
|
278
|
+
authOptions,
|
|
279
|
+
"user-authentication",
|
|
280
|
+
callback
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('should use userAuthentication options for user authentication', function() {
|
|
285
|
+
let opts = {
|
|
286
|
+
userAuthentication: {
|
|
287
|
+
transport: 'some-auth-transport',
|
|
288
|
+
endpoint: '/pusher/spec/auth',
|
|
289
|
+
params: { foo: 'bar' },
|
|
290
|
+
headers: { spec: 'header' }
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const pusher = {};
|
|
295
|
+
let config = Config.getConfig(opts, pusher);
|
|
296
|
+
let callback = function(){};
|
|
297
|
+
config.userAuthenticator({
|
|
298
|
+
socketId: '1.23',
|
|
299
|
+
}, callback);
|
|
300
|
+
|
|
301
|
+
authOptions = {
|
|
302
|
+
transport: 'some-auth-transport',
|
|
303
|
+
endpoint: '/pusher/spec/auth',
|
|
304
|
+
params: { foo: 'bar' },
|
|
305
|
+
headers: { spec: 'header' }
|
|
306
|
+
}
|
|
307
|
+
const query = 'socket_id=1.23&foo=bar';
|
|
308
|
+
expect(transportAuthorizer.calls.count()).toEqual(1);
|
|
309
|
+
expect(transportAuthorizer).toHaveBeenCalledWith(
|
|
310
|
+
Runtime,
|
|
311
|
+
query,
|
|
312
|
+
authOptions,
|
|
313
|
+
"user-authentication",
|
|
314
|
+
callback
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('should use default transport when not provided in userAuthentication', function() {
|
|
319
|
+
let opts = {
|
|
320
|
+
userAuthentication: {
|
|
321
|
+
endpoint: '/pusher/spec/auth',
|
|
322
|
+
params: { foo: 'bar' },
|
|
323
|
+
headers: { spec: 'header' }
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const pusher = {};
|
|
328
|
+
let config = Config.getConfig(opts, pusher);
|
|
329
|
+
let callback = function(){};
|
|
330
|
+
config.userAuthenticator({
|
|
331
|
+
socketId: '1.23',
|
|
332
|
+
}, callback);
|
|
333
|
+
|
|
334
|
+
authOptions = {
|
|
335
|
+
transport: 'ajax',
|
|
336
|
+
endpoint: '/pusher/spec/auth',
|
|
337
|
+
params: { foo: 'bar' },
|
|
338
|
+
headers: { spec: 'header' }
|
|
339
|
+
}
|
|
340
|
+
const query = 'socket_id=1.23&foo=bar';
|
|
341
|
+
expect(transportAuthorizer.calls.count()).toEqual(0);
|
|
342
|
+
expect(transportAuthorizer2.calls.count()).toEqual(0);
|
|
343
|
+
expect(transportAuthorizerAjax.calls.count()).toEqual(1);
|
|
344
|
+
expect(transportAuthorizerAjax).toHaveBeenCalledWith(
|
|
345
|
+
Runtime,
|
|
346
|
+
query,
|
|
347
|
+
authOptions,
|
|
348
|
+
"user-authentication",
|
|
349
|
+
callback
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('should use customHandler inside userAuthentication', function() {
|
|
354
|
+
const customHandler = jasmine.createSpy('customHandler');
|
|
355
|
+
let opts = {
|
|
356
|
+
userAuthentication: {
|
|
357
|
+
transport: 'some-auth-transport',
|
|
358
|
+
endpoint: '/pusher/spec/auth',
|
|
359
|
+
params: { spec: 'param' },
|
|
360
|
+
headers: { spec: 'header' },
|
|
361
|
+
customHandler: customHandler
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const pusher = {};
|
|
366
|
+
let config = Config.getConfig(opts, pusher);
|
|
367
|
+
expect(config.userAuthenticator).toEqual(customHandler);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
71
371
|
describe('TLS', function() {
|
|
72
372
|
it('should use TLS if forceTLS set', function() {
|
|
73
373
|
let config = Config.getConfig({ forceTLS: true });
|
|
@@ -3,38 +3,34 @@ var Logger = require('core/logger').default;
|
|
|
3
3
|
var global = Function("return this")();
|
|
4
4
|
|
|
5
5
|
describe("Logger", function() {
|
|
6
|
-
|
|
7
|
-
var _nativeConsoleLog;
|
|
8
|
-
var _nativeConsoleWarn;
|
|
9
|
-
var _nativeConsoleError;
|
|
10
6
|
var _consoleLogCalls;
|
|
11
7
|
var _consoleWarnCalls;
|
|
12
8
|
var _consoleErrorCalls;
|
|
13
9
|
|
|
10
|
+
var _nativeConsole;
|
|
11
|
+
|
|
14
12
|
beforeEach(function() {
|
|
15
13
|
_consoleLogCalls = [];
|
|
16
14
|
_consoleWarnCalls = [];
|
|
17
15
|
_consoleErrorCalls = [];
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
_nativeConsole = global.console
|
|
18
|
+
global.console = {
|
|
19
|
+
log: function() {
|
|
20
|
+
_consoleLogCalls.push(arguments);
|
|
21
|
+
},
|
|
22
|
+
warn: function() {
|
|
23
|
+
_consoleWarnCalls.push(arguments);
|
|
24
|
+
},
|
|
25
|
+
error: function() {
|
|
26
|
+
_consoleErrorCalls.push(arguments);
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
|
|
32
30
|
});
|
|
33
31
|
|
|
34
32
|
afterEach(function() {
|
|
35
|
-
global.console
|
|
36
|
-
global.console.warn = _nativeConsoleWarn;
|
|
37
|
-
global.console.error = _nativeConsoleError;
|
|
33
|
+
global.console = _nativeConsole;
|
|
38
34
|
});
|
|
39
35
|
|
|
40
36
|
// logToConsole should be disabled by default
|
|
@@ -65,9 +61,14 @@ describe("Logger", function() {
|
|
|
65
61
|
});
|
|
66
62
|
|
|
67
63
|
describe("with logToConsole == true", function() {
|
|
64
|
+
var _defaultLogToConsole
|
|
68
65
|
beforeEach(function() {
|
|
66
|
+
_defaultLogToConsole = Pusher.logToConsole;
|
|
69
67
|
Pusher.logToConsole = true;
|
|
70
68
|
})
|
|
69
|
+
afterEach(function() {
|
|
70
|
+
Pusher.logToConsole = _defaultLogToConsole;
|
|
71
|
+
})
|
|
71
72
|
|
|
72
73
|
it("should log to the console", function() {
|
|
73
74
|
Logger.debug("test", "this is a test");
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
var TestEnv = require(
|
|
2
|
-
var Util = require(
|
|
3
|
-
var Collections = require(
|
|
4
|
-
var Logger = require(
|
|
5
|
-
var Defaults = require(
|
|
6
|
-
var DefaultConfig = require(
|
|
7
|
-
var TimelineSender = require(
|
|
8
|
-
var Pusher = require(
|
|
9
|
-
var Mocks = require(
|
|
10
|
-
var Factory = require(
|
|
11
|
-
var Runtime = require(
|
|
1
|
+
var TestEnv = require("testenv");
|
|
2
|
+
var Util = require("core/util").default;
|
|
3
|
+
var Collections = require("core/utils/collections");
|
|
4
|
+
var Logger = require("core/logger").default;
|
|
5
|
+
var Defaults = require("core/defaults").default;
|
|
6
|
+
var DefaultConfig = require("core/config");
|
|
7
|
+
var TimelineSender = require("core/timeline/timeline_sender").default;
|
|
8
|
+
var Pusher = require("core/pusher").default;
|
|
9
|
+
var Mocks = require("../../helpers/mocks");
|
|
10
|
+
var Factory = require("core/utils/factory").default;
|
|
11
|
+
var Runtime = require("runtime").default;
|
|
12
|
+
const transports = Runtime.Transports;
|
|
13
|
+
const Network = require("net_info").Network;
|
|
14
|
+
const waitsFor = require("../../helpers/waitsFor");
|
|
15
|
+
var NetInfo = require("net_info").NetInfo;
|
|
12
16
|
|
|
13
17
|
describe("Pusher", function() {
|
|
14
18
|
var _isReady, _instances, _logToConsole;
|
|
@@ -20,9 +24,9 @@ describe("Pusher", function() {
|
|
|
20
24
|
break;
|
|
21
25
|
case "web":
|
|
22
26
|
var timelineTransport = "jsonp";
|
|
23
|
-
break
|
|
27
|
+
break;
|
|
24
28
|
default:
|
|
25
|
-
throw
|
|
29
|
+
throw "Please specify the test environment as an external.";
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
beforeEach(function() {
|
|
@@ -36,7 +40,11 @@ describe("Pusher", function() {
|
|
|
36
40
|
return Mocks.getStrategy(true);
|
|
37
41
|
});
|
|
38
42
|
|
|
39
|
-
spyOn(Factory, "createConnectionManager").and.callFake(function(
|
|
43
|
+
spyOn(Factory, "createConnectionManager").and.callFake(function(
|
|
44
|
+
key,
|
|
45
|
+
options,
|
|
46
|
+
config
|
|
47
|
+
) {
|
|
40
48
|
var manager = Mocks.getConnectionManager();
|
|
41
49
|
manager.key = key;
|
|
42
50
|
manager.options = options;
|
|
@@ -64,11 +72,15 @@ describe("Pusher", function() {
|
|
|
64
72
|
|
|
65
73
|
describe("app key validation", function() {
|
|
66
74
|
it("should throw on a null key", function() {
|
|
67
|
-
expect(function() {
|
|
75
|
+
expect(function() {
|
|
76
|
+
new Pusher(null);
|
|
77
|
+
}).toThrow("You must pass your app key when you instantiate Pusher.");
|
|
68
78
|
});
|
|
69
79
|
|
|
70
80
|
it("should throw on an undefined key", function() {
|
|
71
|
-
expect(function() {
|
|
81
|
+
expect(function() {
|
|
82
|
+
new Pusher();
|
|
83
|
+
}).toThrow("You must pass your app key when you instantiate Pusher.");
|
|
72
84
|
});
|
|
73
85
|
|
|
74
86
|
it("should allow a hex key", function() {
|
|
@@ -85,8 +97,10 @@ describe("Pusher", function() {
|
|
|
85
97
|
|
|
86
98
|
it("should not warn if no cluster is supplied if wsHost or httpHost are supplied", function() {
|
|
87
99
|
spyOn(Logger, "warn");
|
|
88
|
-
var wsPusher = new Pusher("1234567890abcdef", { wsHost:
|
|
89
|
-
var httpPusher = new Pusher("1234567890abcdef", {
|
|
100
|
+
var wsPusher = new Pusher("1234567890abcdef", { wsHost: "example.com" });
|
|
101
|
+
var httpPusher = new Pusher("1234567890abcdef", {
|
|
102
|
+
httpHost: "example.com"
|
|
103
|
+
});
|
|
90
104
|
expect(Logger.warn).not.toHaveBeenCalled();
|
|
91
105
|
expect(Logger.warn).not.toHaveBeenCalled();
|
|
92
106
|
});
|
|
@@ -147,7 +161,7 @@ describe("Pusher", function() {
|
|
|
147
161
|
expect(pusher.shouldUseTLS()).toBe(true);
|
|
148
162
|
});
|
|
149
163
|
|
|
150
|
-
it("should be off when
|
|
164
|
+
it("should be off when forceTLS parameter is passed", function() {
|
|
151
165
|
var pusher = new Pusher("foo", { forceTLS: false });
|
|
152
166
|
expect(pusher.shouldUseTLS()).toBe(false);
|
|
153
167
|
});
|
|
@@ -174,15 +188,15 @@ describe("Pusher", function() {
|
|
|
174
188
|
|
|
175
189
|
it("should pass config and options to the strategy builder", function() {
|
|
176
190
|
var config = DefaultConfig.getConfig({});
|
|
177
|
-
var options = { useTLS: true }
|
|
191
|
+
var options = { useTLS: true };
|
|
178
192
|
|
|
179
193
|
var getStrategy = pusher.connection.options.getStrategy;
|
|
180
|
-
getStrategy(options)
|
|
194
|
+
getStrategy(options);
|
|
181
195
|
expect(Runtime.getDefaultStrategy).toHaveBeenCalledWith(
|
|
182
196
|
pusher.config,
|
|
183
197
|
options,
|
|
184
|
-
jasmine.any(Function)
|
|
185
|
-
)
|
|
198
|
+
jasmine.any(Function)
|
|
199
|
+
);
|
|
186
200
|
});
|
|
187
201
|
});
|
|
188
202
|
|
|
@@ -236,6 +250,8 @@ describe("Pusher", function() {
|
|
|
236
250
|
});
|
|
237
251
|
|
|
238
252
|
describe("after connecting", function() {
|
|
253
|
+
var pusher;
|
|
254
|
+
|
|
239
255
|
beforeEach(function() {
|
|
240
256
|
pusher = new Pusher("foo");
|
|
241
257
|
pusher.connect();
|
|
@@ -244,11 +260,10 @@ describe("Pusher", function() {
|
|
|
244
260
|
});
|
|
245
261
|
|
|
246
262
|
it("should subscribe to all channels", function() {
|
|
247
|
-
|
|
248
|
-
|
|
263
|
+
pusher = new Pusher("foo");
|
|
249
264
|
var subscribedChannels = {
|
|
250
|
-
|
|
251
|
-
|
|
265
|
+
channel1: pusher.subscribe("channel1"),
|
|
266
|
+
channel2: pusher.subscribe("channel2")
|
|
252
267
|
};
|
|
253
268
|
|
|
254
269
|
expect(subscribedChannels.channel1.subscribe).not.toHaveBeenCalled();
|
|
@@ -265,7 +280,9 @@ describe("Pusher", function() {
|
|
|
265
280
|
it("should send events via the connection manager", function() {
|
|
266
281
|
pusher.send_event("event", { key: "value" }, "channel");
|
|
267
282
|
expect(pusher.connection.send_event).toHaveBeenCalledWith(
|
|
268
|
-
"event",
|
|
283
|
+
"event",
|
|
284
|
+
{ key: "value" },
|
|
285
|
+
"channel"
|
|
269
286
|
);
|
|
270
287
|
});
|
|
271
288
|
|
|
@@ -288,7 +305,7 @@ describe("Pusher", function() {
|
|
|
288
305
|
pusher.subscribe("xxx");
|
|
289
306
|
|
|
290
307
|
expect(channel.reinstateSubscription).toHaveBeenCalled();
|
|
291
|
-
})
|
|
308
|
+
});
|
|
292
309
|
});
|
|
293
310
|
|
|
294
311
|
describe("#unsubscribe", function() {
|
|
@@ -310,7 +327,7 @@ describe("Pusher", function() {
|
|
|
310
327
|
expect(channel.unsubscribe).not.toHaveBeenCalled();
|
|
311
328
|
});
|
|
312
329
|
|
|
313
|
-
it("should remove the channel from .channels if subscription is not pending", function
|
|
330
|
+
it("should remove the channel from .channels if subscription is not pending", function() {
|
|
314
331
|
var channel = pusher.subscribe("yyy");
|
|
315
332
|
expect(pusher.channel("yyy")).toBe(channel);
|
|
316
333
|
|
|
@@ -318,7 +335,7 @@ describe("Pusher", function() {
|
|
|
318
335
|
expect(pusher.channel("yyy")).toBe(undefined);
|
|
319
336
|
});
|
|
320
337
|
|
|
321
|
-
it("should delay unsubscription if the subscription is pending", function
|
|
338
|
+
it("should delay unsubscription if the subscription is pending", function() {
|
|
322
339
|
var channel = pusher.subscribe("yyy");
|
|
323
340
|
channel.subscriptionPending = true;
|
|
324
341
|
|
|
@@ -326,7 +343,7 @@ describe("Pusher", function() {
|
|
|
326
343
|
expect(pusher.channel("yyy")).toBe(channel);
|
|
327
344
|
expect(channel.unsubscribe).not.toHaveBeenCalled();
|
|
328
345
|
expect(channel.cancelSubscription).toHaveBeenCalled();
|
|
329
|
-
})
|
|
346
|
+
});
|
|
330
347
|
});
|
|
331
348
|
});
|
|
332
349
|
|
|
@@ -348,7 +365,7 @@ describe("Pusher", function() {
|
|
|
348
365
|
expect(channel.handleEvent).toHaveBeenCalledWith({
|
|
349
366
|
channel: "chan",
|
|
350
367
|
event: "event",
|
|
351
|
-
data: { key: "value" }
|
|
368
|
+
data: { key: "value" }
|
|
352
369
|
});
|
|
353
370
|
});
|
|
354
371
|
|
|
@@ -404,6 +421,12 @@ describe("Pusher", function() {
|
|
|
404
421
|
});
|
|
405
422
|
|
|
406
423
|
describe("#unbind", function() {
|
|
424
|
+
var pusher;
|
|
425
|
+
|
|
426
|
+
beforeEach(function() {
|
|
427
|
+
pusher = new Pusher("foo");
|
|
428
|
+
});
|
|
429
|
+
|
|
407
430
|
it("should allow a globally bound callback to be removed", function() {
|
|
408
431
|
var onEvent = jasmine.createSpy("onEvent");
|
|
409
432
|
pusher.bind("event", onEvent);
|
|
@@ -418,6 +441,7 @@ describe("Pusher", function() {
|
|
|
418
441
|
});
|
|
419
442
|
});
|
|
420
443
|
|
|
444
|
+
|
|
421
445
|
describe("#disconnect", function() {
|
|
422
446
|
it("should call disconnect on connection manager", function() {
|
|
423
447
|
var pusher = new Pusher("foo");
|
|
@@ -455,11 +479,11 @@ describe("Pusher", function() {
|
|
|
455
479
|
var timelineSender;
|
|
456
480
|
|
|
457
481
|
beforeEach(function() {
|
|
482
|
+
jasmine.clock().uninstall();
|
|
458
483
|
jasmine.clock().install();
|
|
459
484
|
|
|
460
485
|
timelineSender = Mocks.getTimelineSender();
|
|
461
486
|
spyOn(Factory, "createTimelineSender").and.returnValue(timelineSender);
|
|
462
|
-
|
|
463
487
|
});
|
|
464
488
|
|
|
465
489
|
afterEach(function() {
|
|
@@ -470,17 +494,19 @@ describe("Pusher", function() {
|
|
|
470
494
|
var pusher = new Pusher("foo", { enableStats: true });
|
|
471
495
|
expect(Factory.createTimelineSender.calls.count()).toEqual(1);
|
|
472
496
|
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
|
|
473
|
-
pusher.timeline,
|
|
497
|
+
pusher.timeline,
|
|
498
|
+
{ host: "stats.pusher.com", path: "/timeline/v2/" + timelineTransport }
|
|
474
499
|
);
|
|
475
500
|
});
|
|
476
501
|
|
|
477
502
|
it("should be sent to a hostname specified in constructor options", function() {
|
|
478
503
|
var pusher = new Pusher("foo", {
|
|
479
504
|
statsHost: "example.com",
|
|
480
|
-
enableStats: true
|
|
505
|
+
enableStats: true
|
|
481
506
|
});
|
|
482
507
|
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
|
|
483
|
-
pusher.timeline,
|
|
508
|
+
pusher.timeline,
|
|
509
|
+
{ host: "example.com", path: "/timeline/v2/" + timelineTransport }
|
|
484
510
|
);
|
|
485
511
|
});
|
|
486
512
|
|
|
@@ -498,7 +524,8 @@ describe("Pusher", function() {
|
|
|
498
524
|
pusher.connection.options.timeline.info({});
|
|
499
525
|
expect(Factory.createTimelineSender.calls.count()).toEqual(1);
|
|
500
526
|
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
|
|
501
|
-
pusher.timeline,
|
|
527
|
+
pusher.timeline,
|
|
528
|
+
{ host: "stats.pusher.com", path: "/timeline/v2/" + timelineTransport }
|
|
502
529
|
);
|
|
503
530
|
});
|
|
504
531
|
|
|
@@ -508,7 +535,8 @@ describe("Pusher", function() {
|
|
|
508
535
|
pusher.connection.options.timeline.info({});
|
|
509
536
|
expect(Factory.createTimelineSender.calls.count()).toEqual(1);
|
|
510
537
|
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
|
|
511
|
-
pusher.timeline,
|
|
538
|
+
pusher.timeline,
|
|
539
|
+
{ host: "stats.pusher.com", path: "/timeline/v2/" + timelineTransport }
|
|
512
540
|
);
|
|
513
541
|
});
|
|
514
542
|
|
|
@@ -8,9 +8,11 @@ describe('PusherWithEncryption', function() {
|
|
|
8
8
|
expect(Pusher.logToConsole).toEqual(true);
|
|
9
9
|
});
|
|
10
10
|
it('should pass log function to parent class', function() {
|
|
11
|
+
let _prevLog = PusherWithEncryption.log
|
|
11
12
|
let logFn = jasmine.createSpy('logFn');
|
|
12
13
|
PusherWithEncryption.log = logFn
|
|
13
14
|
let pusher = new PusherWithEncryption('key');
|
|
14
15
|
expect(logFn).toHaveBeenCalled();
|
|
16
|
+
PusherWithEncryption.log = _prevLog
|
|
15
17
|
});
|
|
16
18
|
});
|