pusher-js 7.4.1 → 7.6.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/.github/workflows/release_pr.yml +3 -1
- package/.github/workflows/run-tests.yml +27 -3
- package/CHANGELOG.md +8 -0
- package/Makefile +1 -0
- package/README.md +11 -3
- package/dist/node/pusher.js +139 -28
- package/dist/node/pusher.js.map +1 -1
- package/dist/react-native/pusher.js +5 -5
- package/dist/react-native/pusher.js.map +1 -1
- package/dist/web/pusher-with-encryption.js +83 -9
- 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 +83 -9
- 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 +81 -8
- 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 +81 -8
- 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/integration_tests_server/index.js +176 -0
- package/integration_tests_server/package-lock.json +1177 -0
- package/integration_tests_server/package.json +15 -0
- package/package.json +6 -5
- package/spec/config/karma/config.common.js +1 -2
- package/spec/javascripts/helpers/node/integration.js +2 -2
- package/spec/javascripts/helpers/web/integration.js +2 -2
- package/spec/javascripts/integration/core/cluster_config_spec.js +1 -1
- package/spec/javascripts/integration/core/pusher_spec/test_builder.js +13 -43
- package/spec/javascripts/integration/web/dom/jsonp_spec.js +2 -2
- package/spec/javascripts/unit/core/config_spec.js +91 -3
- package/spec/javascripts/unit/core/connection/connection_manager_spec.js +11 -1
- package/spec/javascripts/unit/core/http/http_request_spec.js +0 -6
- package/spec/javascripts/unit/core/transports/transport_connection_spec.js +5 -0
- package/spec/javascripts/unit/core/utils/timers_spec.js +0 -4
- package/spec/javascripts/unit/core/watchlist_spec.js +48 -0
- package/spec/javascripts/unit/core_with_runtime/auth/channel_authorizer_spec.js +82 -0
- package/spec/javascripts/unit/core_with_runtime/auth/user_authorizer_spec.js +76 -0
- package/spec/javascripts/unit/web/pusher_authorizer_spec.js +28 -0
- package/spec/javascripts/unit/worker/channel_authorizer_spec.js +46 -0
- package/src/core/auth/channel_authorizer.ts +14 -3
- package/src/core/auth/options.ts +4 -0
- package/src/core/auth/user_authenticator.ts +14 -3
- package/src/core/pusher.ts +0 -1
- package/src/core/user.ts +5 -0
- package/src/core/watchlist.ts +31 -0
- package/src/runtimes/isomorphic/auth/xhr_auth.ts +6 -0
- package/src/runtimes/web/auth/jsonp_auth.ts +4 -1
- package/src/runtimes/worker/auth/fetch_auth.ts +7 -0
- package/types/src/core/auth/options.d.ts +4 -0
- package/types/src/core/user.d.ts +2 -0
- package/types/src/core/watchlist.d.ts +8 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "integration_tests_auth_server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"express": "^4.18.2",
|
|
13
|
+
"pusher": "^5.1.1-beta"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pusher-js",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.6.0",
|
|
4
4
|
"description": "Pusher Channels JavaScript library for browsers, React Native, NodeJS and web workers",
|
|
5
5
|
"main": "dist/node/pusher.js",
|
|
6
6
|
"browser": "dist/web/pusher.js",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"faye-websocket": "^0.11.3",
|
|
39
39
|
"fetch-mock": "git+https://git@github.com/jpatel531/fetch-mock.git",
|
|
40
40
|
"isomorphic-fetch": "^3.0.0",
|
|
41
|
-
"jasmine": "^
|
|
41
|
+
"jasmine": "^4.5.0",
|
|
42
42
|
"jasmine-spec-reporter": "^7.0.0",
|
|
43
|
-
"karma": "^6.4.
|
|
43
|
+
"karma": "^6.4.1",
|
|
44
44
|
"karma-browserstack-launcher": "^1.6.0",
|
|
45
45
|
"karma-chrome-launcher": "^3.1.0",
|
|
46
46
|
"karma-firefox-launcher": "^2.1.1",
|
|
@@ -58,12 +58,13 @@
|
|
|
58
58
|
"uglify-js": "^2.6.2",
|
|
59
59
|
"webpack": "^4.46.0",
|
|
60
60
|
"webpack-cli": "^3.3.12",
|
|
61
|
-
"webpack-dev-server": "^
|
|
61
|
+
"webpack-dev-server": "^4.11.1",
|
|
62
62
|
"webpack-merge": "^5.8.0",
|
|
63
63
|
"xmlhttprequest": "^1.8.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"tweetnacl": "^1.0.3",
|
|
67
|
-
"@types/node": "^14.14.31"
|
|
67
|
+
"@types/node": "^14.14.31",
|
|
68
|
+
"@types/express-serve-static-core": "4.17.28"
|
|
68
69
|
}
|
|
69
70
|
}
|
|
@@ -32,7 +32,7 @@ module.exports = {
|
|
|
32
32
|
autoWatch: true,
|
|
33
33
|
|
|
34
34
|
browsers: browserList,
|
|
35
|
-
captureTimeout:
|
|
35
|
+
captureTimeout: 10e3,
|
|
36
36
|
browserNoActivityTimeout: 3e4,
|
|
37
37
|
browserDisconnectTimeout: 3e4,
|
|
38
38
|
browserDisconnectTolerance: 3,
|
|
@@ -48,4 +48,3 @@ module.exports = {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
|
|
@@ -3,8 +3,8 @@ var Runtime = require('runtime').default
|
|
|
3
3
|
var Collections = require('core/utils/collections');
|
|
4
4
|
var util = require('core/util').default;
|
|
5
5
|
|
|
6
|
-
exports.API_URL = "http://
|
|
7
|
-
exports.API_EU_URL = "http://
|
|
6
|
+
exports.API_URL = "http://localhost:3000";
|
|
7
|
+
exports.API_EU_URL = "http://localhost:3001";
|
|
8
8
|
|
|
9
9
|
exports.describe = function(name, body) {
|
|
10
10
|
describe(name + " (integration)", body);
|
|
@@ -5,8 +5,8 @@ var Collections = require('core/utils/collections');
|
|
|
5
5
|
var JSONPRequest = require('dom/jsonp_request').default;
|
|
6
6
|
var ScriptReceivers = require('dom/script_receiver_factory').ScriptReceivers;
|
|
7
7
|
|
|
8
|
-
exports.API_URL = "http://
|
|
9
|
-
exports.API_EU_URL = "http://
|
|
8
|
+
exports.API_URL = "http://localhost:3000";
|
|
9
|
+
exports.API_EU_URL = "http://localhost:3001";
|
|
10
10
|
|
|
11
11
|
exports.describe = function(name, body) {
|
|
12
12
|
if (navigator.userAgent.match(/phantomjs/i)) {
|
|
@@ -59,7 +59,7 @@ module.exports = function(testConfigs) {
|
|
|
59
59
|
it("should open a connection to the 'eu' cluster", async function() {
|
|
60
60
|
var authTransport = (TestEnv === "web") ? 'jsonp' : 'ajax';
|
|
61
61
|
|
|
62
|
-
pusher = new Pusher("
|
|
62
|
+
pusher = new Pusher("cb7d5e50f5669e5c9ae6", {
|
|
63
63
|
authTransport: authTransport,
|
|
64
64
|
authEndpoint: Integration.API_EU_URL + "/auth",
|
|
65
65
|
cluster: "eu",
|
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
const Pusher = require('pusher_integration');
|
|
2
2
|
|
|
3
3
|
const Integration = require('integration');
|
|
4
|
-
const OneOffTimer = require('core/utils/timers').OneOffTimer;
|
|
5
4
|
const Collections = require('core/utils/collections');
|
|
6
5
|
const Runtime = require('runtime').default;
|
|
7
6
|
const TRANSPORTS = Runtime.Transports;
|
|
8
7
|
const waitsFor = require('../../../helpers/waitsFor');
|
|
9
8
|
|
|
10
|
-
// this is a slightly horrible function that allows easy placement of arbitrary
|
|
11
|
-
// delays in jasmine async tests. e.g:
|
|
12
|
-
// waitsFor(sleep(3000), "thing to happen", 3500)
|
|
13
|
-
function sleep(time) {
|
|
14
|
-
var fn = function() {
|
|
15
|
-
var val = false;
|
|
16
|
-
setTimeout(function(){
|
|
17
|
-
val = true;
|
|
18
|
-
}, time)
|
|
19
|
-
return function() {
|
|
20
|
-
return val;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return fn();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
9
|
function canRunTwoConnections(transport) {
|
|
27
10
|
if (transport !== "sockjs") {
|
|
28
11
|
return true;
|
|
@@ -38,6 +21,10 @@ function subscribe(pusher, channelName, callback) {
|
|
|
38
21
|
return channel;
|
|
39
22
|
}
|
|
40
23
|
|
|
24
|
+
function delay(timeMs) {
|
|
25
|
+
return new Promise(resolve => setTimeout(resolve, timeMs));
|
|
26
|
+
}
|
|
27
|
+
|
|
41
28
|
function build(testConfig) {
|
|
42
29
|
var forceTLS = testConfig.forceTLS;
|
|
43
30
|
var transport = testConfig.transport;
|
|
@@ -67,11 +54,11 @@ function build(testConfig) {
|
|
|
67
54
|
|
|
68
55
|
describe("setup", function() {
|
|
69
56
|
it("should open connections", async function() {
|
|
70
|
-
pusher1 = new Pusher("
|
|
57
|
+
pusher1 = new Pusher("c49a449b916bb4246729", {
|
|
71
58
|
forceTLS: forceTLS,
|
|
72
59
|
});
|
|
73
60
|
if (canRunTwoConnections(transport)) {
|
|
74
|
-
pusher2 = new Pusher("
|
|
61
|
+
pusher2 = new Pusher("c49a449b916bb4246729", {
|
|
75
62
|
forceTLS: forceTLS,
|
|
76
63
|
});
|
|
77
64
|
await waitsFor(function() {
|
|
@@ -401,11 +388,7 @@ function buildClientEventsTests(getPusher1, getPusher2, prefix) {
|
|
|
401
388
|
|
|
402
389
|
channel.bind(eventName, onEvent);
|
|
403
390
|
pusher.send_event(eventName, {}, channelName);
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
await waitsFor(function() {
|
|
407
|
-
return !timer.isRunning();
|
|
408
|
-
}, "timer to finish", 3210);
|
|
391
|
+
await delay(5000);
|
|
409
392
|
|
|
410
393
|
expect(onEvent).not.toHaveBeenCalled();
|
|
411
394
|
pusher.unsubscribe(channelName);
|
|
@@ -470,12 +453,7 @@ function buildPublicChannelTests(getPusher, prefix) {
|
|
|
470
453
|
event: eventName,
|
|
471
454
|
data: {}
|
|
472
455
|
});
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
await waitsFor(function() {
|
|
476
|
-
return !timer.isRunning();
|
|
477
|
-
}, "timer to finish", 3210);
|
|
478
|
-
|
|
456
|
+
await delay(5000);
|
|
479
457
|
expect(received).toBe(null);
|
|
480
458
|
});
|
|
481
459
|
|
|
@@ -519,11 +497,7 @@ function buildPublicChannelTests(getPusher, prefix) {
|
|
|
519
497
|
event: eventName,
|
|
520
498
|
data: {}
|
|
521
499
|
});
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
await waitsFor(function() {
|
|
525
|
-
return !timer.isRunning();
|
|
526
|
-
}, "timer to finish", 10000);
|
|
500
|
+
await delay(5000);
|
|
527
501
|
|
|
528
502
|
expect(channel.subscribed).toEqual(false);
|
|
529
503
|
expect(received).toBe(null);
|
|
@@ -554,11 +528,7 @@ function buildPublicChannelTests(getPusher, prefix) {
|
|
|
554
528
|
event: eventName,
|
|
555
529
|
data: {}
|
|
556
530
|
});
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
await waitsFor(function() {
|
|
560
|
-
return !timer.isRunning();
|
|
561
|
-
}, "timer to finish", 10000);
|
|
531
|
+
await delay(10000);
|
|
562
532
|
|
|
563
533
|
expect(channel.subscribed).toEqual(true);
|
|
564
534
|
expect(received).not.toBe(null);
|
|
@@ -627,7 +597,7 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
627
597
|
|
|
628
598
|
// there is no easy way to know when an unsubscribe request has been
|
|
629
599
|
// actioned by the server, so we just wait a while
|
|
630
|
-
await
|
|
600
|
+
await delay(5000);
|
|
631
601
|
|
|
632
602
|
expect(pusher.channel(channelName)).toBe(undefined);
|
|
633
603
|
});
|
|
@@ -697,7 +667,7 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
697
667
|
|
|
698
668
|
// there is no easy way to know when an unsubscribe request has been
|
|
699
669
|
// actioned by the server, so we just wait a while
|
|
700
|
-
await
|
|
670
|
+
await delay(5000);
|
|
701
671
|
expect(pusher.channel(channelName)).toBe(undefined);
|
|
702
672
|
|
|
703
673
|
pusher.subscribe(channelName)
|
|
@@ -735,7 +705,7 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
735
705
|
|
|
736
706
|
// there is no easy way to know when an unsubscribe request has been
|
|
737
707
|
// actioned by the server, so we just wait a while
|
|
738
|
-
await
|
|
708
|
+
await delay(5000);
|
|
739
709
|
|
|
740
710
|
expect(pusher.channel(channelName)).toBe(undefined);
|
|
741
711
|
});
|
|
@@ -37,10 +37,10 @@ Integration.describe("JSONP", function() {
|
|
|
37
37
|
|
|
38
38
|
expect(callback.calls.count()).toEqual(1);
|
|
39
39
|
expect(callback).toHaveBeenCalledWith(null, {
|
|
40
|
-
"session":
|
|
40
|
+
"session": 2289545,
|
|
41
41
|
"features": ["ws", "sockjs"],
|
|
42
42
|
"version": "1.13.0",
|
|
43
|
-
"t0":
|
|
43
|
+
"t0": 1355850357911,
|
|
44
44
|
"timeline": [
|
|
45
45
|
{ t: 0, e: 2 },
|
|
46
46
|
{ t: 2, e: 2, type: "ws" },
|
|
@@ -198,6 +198,54 @@ describe('Config', function() {
|
|
|
198
198
|
);
|
|
199
199
|
});
|
|
200
200
|
|
|
201
|
+
it('should use channelAuthorization with providers and override deprecated auth options', function() {
|
|
202
|
+
let headersProvider = () => { return { abc: '123'} };
|
|
203
|
+
let paramsProvider = () => { return { def: '456'} };
|
|
204
|
+
let opts = {
|
|
205
|
+
authTransport: 'some-auth-transport',
|
|
206
|
+
authEndpoint: '/pusher/spec/auth',
|
|
207
|
+
auth: {
|
|
208
|
+
params: { foo: 'bar' },
|
|
209
|
+
headers: { spec: 'header' }
|
|
210
|
+
},
|
|
211
|
+
channelAuthorization: {
|
|
212
|
+
transport: 'some-auth-transport2',
|
|
213
|
+
endpoint: '/pusher/spec/auth2',
|
|
214
|
+
params: { spec2: 'param2' },
|
|
215
|
+
headers: { spec2: 'header2' },
|
|
216
|
+
headersProvider,
|
|
217
|
+
paramsProvider
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
const pusher = {};
|
|
221
|
+
let config = Config.getConfig(opts, pusher);
|
|
222
|
+
let callback = function(){};
|
|
223
|
+
config.channelAuthorizer({
|
|
224
|
+
socketId: '1.23',
|
|
225
|
+
channelName: 'private-test',
|
|
226
|
+
}, callback);
|
|
227
|
+
|
|
228
|
+
console.log(config);
|
|
229
|
+
authOptions = {
|
|
230
|
+
transport: 'some-auth-transport2',
|
|
231
|
+
endpoint: '/pusher/spec/auth2',
|
|
232
|
+
params: { spec2: 'param2' },
|
|
233
|
+
headers: { spec2: 'header2' },
|
|
234
|
+
headersProvider,
|
|
235
|
+
paramsProvider
|
|
236
|
+
}
|
|
237
|
+
const query = 'socket_id=1.23&channel_name=private-test&spec2=param2&def=456';
|
|
238
|
+
expect(transportAuthorizer.calls.count()).toEqual(0);
|
|
239
|
+
expect(transportAuthorizer2.calls.count()).toEqual(1);
|
|
240
|
+
expect(transportAuthorizer2).toHaveBeenCalledWith(
|
|
241
|
+
Runtime,
|
|
242
|
+
query,
|
|
243
|
+
authOptions,
|
|
244
|
+
"channel-authorization",
|
|
245
|
+
callback
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
|
|
201
249
|
it('should use default transport when not provided in channelAuthorization', function() {
|
|
202
250
|
let opts = {
|
|
203
251
|
authEndpoint: '/pusher/spec/auth',
|
|
@@ -239,7 +287,7 @@ describe('Config', function() {
|
|
|
239
287
|
});
|
|
240
288
|
|
|
241
289
|
|
|
242
|
-
it('should use
|
|
290
|
+
it('should use customHandler inside channelAuthorization', function() {
|
|
243
291
|
const customHandler = jasmine.createSpy('customHandler');
|
|
244
292
|
let opts = {
|
|
245
293
|
channelAuthorization: {
|
|
@@ -287,7 +335,7 @@ describe('Config', function() {
|
|
|
287
335
|
transport: 'some-auth-transport',
|
|
288
336
|
endpoint: '/pusher/spec/auth',
|
|
289
337
|
params: { foo: 'bar' },
|
|
290
|
-
headers: { spec: 'header' }
|
|
338
|
+
headers: { spec: 'header' },
|
|
291
339
|
}
|
|
292
340
|
};
|
|
293
341
|
|
|
@@ -302,7 +350,7 @@ describe('Config', function() {
|
|
|
302
350
|
transport: 'some-auth-transport',
|
|
303
351
|
endpoint: '/pusher/spec/auth',
|
|
304
352
|
params: { foo: 'bar' },
|
|
305
|
-
headers: { spec: 'header' }
|
|
353
|
+
headers: { spec: 'header' },
|
|
306
354
|
}
|
|
307
355
|
const query = 'socket_id=1.23&foo=bar';
|
|
308
356
|
expect(transportAuthorizer.calls.count()).toEqual(1);
|
|
@@ -315,6 +363,46 @@ describe('Config', function() {
|
|
|
315
363
|
);
|
|
316
364
|
});
|
|
317
365
|
|
|
366
|
+
it('should use userAuthentication options with providers for user authentication', function() {
|
|
367
|
+
let headersProvider = () => { return { abc: '123'} };
|
|
368
|
+
let paramsProvider = () => { return { def: '456'} };
|
|
369
|
+
let opts = {
|
|
370
|
+
userAuthentication: {
|
|
371
|
+
transport: 'some-auth-transport',
|
|
372
|
+
endpoint: '/pusher/spec/auth',
|
|
373
|
+
params: { foo: 'bar' },
|
|
374
|
+
headers: { spec: 'header' },
|
|
375
|
+
headersProvider,
|
|
376
|
+
paramsProvider
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const pusher = {};
|
|
381
|
+
let config = Config.getConfig(opts, pusher);
|
|
382
|
+
let callback = function(){};
|
|
383
|
+
config.userAuthenticator({
|
|
384
|
+
socketId: '1.23',
|
|
385
|
+
}, callback);
|
|
386
|
+
|
|
387
|
+
authOptions = {
|
|
388
|
+
transport: 'some-auth-transport',
|
|
389
|
+
endpoint: '/pusher/spec/auth',
|
|
390
|
+
params: { foo: 'bar' },
|
|
391
|
+
headers: { spec: 'header' },
|
|
392
|
+
headersProvider,
|
|
393
|
+
paramsProvider
|
|
394
|
+
}
|
|
395
|
+
const query = 'socket_id=1.23&foo=bar&def=456';
|
|
396
|
+
expect(transportAuthorizer.calls.count()).toEqual(1);
|
|
397
|
+
expect(transportAuthorizer).toHaveBeenCalledWith(
|
|
398
|
+
Runtime,
|
|
399
|
+
query,
|
|
400
|
+
authOptions,
|
|
401
|
+
"user-authentication",
|
|
402
|
+
callback
|
|
403
|
+
);
|
|
404
|
+
});
|
|
405
|
+
|
|
318
406
|
it('should use default transport when not provided in userAuthentication', function() {
|
|
319
407
|
let opts = {
|
|
320
408
|
userAuthentication: {
|
|
@@ -13,7 +13,17 @@ describe("ConnectionManager", function() {
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
afterAll(() => {
|
|
16
|
-
|
|
16
|
+
try {
|
|
17
|
+
jasmine.clock().uninstall();
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (e instanceof TypeError) {
|
|
20
|
+
// Ignore
|
|
21
|
+
// It's a bug in jasmine AFAIK and all other attempts of working
|
|
22
|
+
// around it led to other issues
|
|
23
|
+
} else {
|
|
24
|
+
throw e;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
17
27
|
});
|
|
18
28
|
|
|
19
29
|
beforeEach(function() {
|
|
@@ -225,6 +225,11 @@ describe("TransportConnection", function() {
|
|
|
225
225
|
expect(loadCallback).toHaveBeenCalledWith(false);
|
|
226
226
|
});
|
|
227
227
|
});
|
|
228
|
+
} else {
|
|
229
|
+
// Needed so that the describe block isn't empty
|
|
230
|
+
it("dummy test", function() {
|
|
231
|
+
expect(true).toBe(true);
|
|
232
|
+
})
|
|
228
233
|
}
|
|
229
234
|
});
|
|
230
235
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var WatchlistFacade = require("core/watchlist").default;
|
|
2
|
+
|
|
3
|
+
describe("WatchlistFacade", function () {
|
|
4
|
+
var connection;
|
|
5
|
+
var pusher;
|
|
6
|
+
|
|
7
|
+
beforeEach(function() {
|
|
8
|
+
connection = jasmine.createSpy('connection');
|
|
9
|
+
pusher = jasmine.createSpy('pusher');
|
|
10
|
+
pusher.connection = connection;
|
|
11
|
+
|
|
12
|
+
spyOn(pusher.connection, 'bind')
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should bind to pusher_internal:user_presence events', function() {
|
|
16
|
+
new WatchlistFacade(pusher);
|
|
17
|
+
expect(connection.bind).toHaveBeenCalledWith('message', jasmine.any(Function));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('#handleEvent', function() {
|
|
21
|
+
var watchlistFacade;
|
|
22
|
+
|
|
23
|
+
beforeEach(function() {
|
|
24
|
+
watchlistFacade = new WatchlistFacade(pusher);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const watchlistEvents = [
|
|
28
|
+
{ name: 'online', user_ids: ['1'] },
|
|
29
|
+
{ name: 'offline', user_ids: ['2', '3', '4'] },
|
|
30
|
+
{ name: 'subscribe', user_ids: ['5', '6'], channel_name: 'presence-chat' }
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
it(`should emit ${watchlistEvents.length} events`, function() {
|
|
34
|
+
const pusherEvent = {
|
|
35
|
+
event: 'pusher_internal:watchlist_events',
|
|
36
|
+
data: { events: watchlistEvents }
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
spyOn(watchlistFacade, 'emit').and.callThrough();
|
|
40
|
+
watchlistFacade.handleEvent(pusherEvent);
|
|
41
|
+
|
|
42
|
+
expect(watchlistFacade.emit).toHaveBeenCalledTimes(watchlistEvents.length)
|
|
43
|
+
watchlistEvents.forEach(function(event) {
|
|
44
|
+
expect(watchlistFacade.emit).toHaveBeenCalledWith(event.name, event);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
})
|
|
48
|
+
});
|
|
@@ -26,6 +26,32 @@ describe("ChannelAuthorizer", function() {
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it("should call the specified transport authorizer", function(){
|
|
29
|
+
const authOptions = {
|
|
30
|
+
transport: "ajax",
|
|
31
|
+
endpoint: "http://example.com/auth",
|
|
32
|
+
headers: { "X-Foo": "my-bar" }
|
|
33
|
+
};
|
|
34
|
+
channelAuthorizer = ChannelAuthorizer(authOptions);
|
|
35
|
+
|
|
36
|
+
transportAuthorizer = jasmine.createSpy("ajax")
|
|
37
|
+
Runtime.getAuthorizers = jasmine.createSpy("getAuthorizers").and.returnValue({
|
|
38
|
+
ajax: transportAuthorizer
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const params = { socketId: '1.23', channelName: 'private-test' };
|
|
42
|
+
const callback = function(){};
|
|
43
|
+
const query = 'socket_id=1.23&channel_name=private-test';
|
|
44
|
+
channelAuthorizer(params, callback);
|
|
45
|
+
expect(Runtime.getAuthorizers.calls.count()).toEqual(1);
|
|
46
|
+
expect(transportAuthorizer).toHaveBeenCalledWith(
|
|
47
|
+
Runtime,
|
|
48
|
+
query,
|
|
49
|
+
authOptions,
|
|
50
|
+
'channel-authorization',
|
|
51
|
+
callback);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should call the specified transport authorizer with params", function(){
|
|
29
55
|
const authOptions = {
|
|
30
56
|
transport: "ajax",
|
|
31
57
|
endpoint: "http://example.com/auth",
|
|
@@ -51,5 +77,61 @@ describe("ChannelAuthorizer", function() {
|
|
|
51
77
|
'channel-authorization',
|
|
52
78
|
callback);
|
|
53
79
|
});
|
|
80
|
+
|
|
81
|
+
it("should call the specified transport authorizer with paramsProvider", function(){
|
|
82
|
+
const authOptions = {
|
|
83
|
+
transport: "ajax",
|
|
84
|
+
endpoint: "http://example.com/auth",
|
|
85
|
+
paramsProvider: () => { return { abc: '123' }; },
|
|
86
|
+
headers: { "X-Foo": "my-bar" }
|
|
87
|
+
};
|
|
88
|
+
channelAuthorizer = ChannelAuthorizer(authOptions);
|
|
89
|
+
|
|
90
|
+
transportAuthorizer = jasmine.createSpy("ajax")
|
|
91
|
+
Runtime.getAuthorizers = jasmine.createSpy("getAuthorizers").and.returnValue({
|
|
92
|
+
ajax: transportAuthorizer
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const params = { socketId: '1.23', channelName: 'private-test' };
|
|
96
|
+
const callback = function(){};
|
|
97
|
+
const query = 'socket_id=1.23&channel_name=private-test&abc=123';
|
|
98
|
+
channelAuthorizer(params, callback);
|
|
99
|
+
expect(Runtime.getAuthorizers.calls.count()).toEqual(1);
|
|
100
|
+
expect(transportAuthorizer).toHaveBeenCalledWith(
|
|
101
|
+
Runtime,
|
|
102
|
+
query,
|
|
103
|
+
authOptions,
|
|
104
|
+
'channel-authorization',
|
|
105
|
+
callback);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
it("should call the specified transport authorizer with params and paramsProvider", function(){
|
|
110
|
+
const authOptions = {
|
|
111
|
+
transport: "ajax",
|
|
112
|
+
endpoint: "http://example.com/auth",
|
|
113
|
+
params: { foo: "bar" },
|
|
114
|
+
paramsProvider: () => { return { abc: '123' }; },
|
|
115
|
+
headers: { "X-Foo": "my-bar" }
|
|
116
|
+
};
|
|
117
|
+
channelAuthorizer = ChannelAuthorizer(authOptions);
|
|
118
|
+
|
|
119
|
+
transportAuthorizer = jasmine.createSpy("ajax")
|
|
120
|
+
Runtime.getAuthorizers = jasmine.createSpy("getAuthorizers").and.returnValue({
|
|
121
|
+
ajax: transportAuthorizer
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const params = { socketId: '1.23', channelName: 'private-test' };
|
|
125
|
+
const callback = function(){};
|
|
126
|
+
const query = 'socket_id=1.23&channel_name=private-test&foo=bar&abc=123';
|
|
127
|
+
channelAuthorizer(params, callback);
|
|
128
|
+
expect(Runtime.getAuthorizers.calls.count()).toEqual(1);
|
|
129
|
+
expect(transportAuthorizer).toHaveBeenCalledWith(
|
|
130
|
+
Runtime,
|
|
131
|
+
query,
|
|
132
|
+
authOptions,
|
|
133
|
+
'channel-authorization',
|
|
134
|
+
callback);
|
|
135
|
+
});
|
|
54
136
|
});
|
|
55
137
|
});
|
|
@@ -48,5 +48,81 @@ describe("UserAuthenticator", function() {
|
|
|
48
48
|
'user-authentication',
|
|
49
49
|
callback);
|
|
50
50
|
});
|
|
51
|
+
|
|
52
|
+
it("should call the specified transport authorizer with params", function(){
|
|
53
|
+
const userAuthentication = {
|
|
54
|
+
transport: "ajax",
|
|
55
|
+
params: { abc: '123' }
|
|
56
|
+
};
|
|
57
|
+
userAuthenticator = UserAuthenticator(userAuthentication);
|
|
58
|
+
|
|
59
|
+
transportAuthorizer = jasmine.createSpy("ajax")
|
|
60
|
+
Runtime.getAuthorizers = jasmine.createSpy("getAuthorizers").and.returnValue({
|
|
61
|
+
ajax: transportAuthorizer
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const params = { socketId: '1.23' };
|
|
65
|
+
const callback = function(){};
|
|
66
|
+
const query = 'socket_id=1.23&abc=123';
|
|
67
|
+
userAuthenticator(params, callback);
|
|
68
|
+
expect(Runtime.getAuthorizers.calls.count()).toEqual(1);
|
|
69
|
+
expect(transportAuthorizer).toHaveBeenCalledWith(
|
|
70
|
+
Runtime,
|
|
71
|
+
query,
|
|
72
|
+
userAuthentication,
|
|
73
|
+
'user-authentication',
|
|
74
|
+
callback);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should call the specified transport authorizer with paramsProvider", function(){
|
|
78
|
+
const userAuthentication = {
|
|
79
|
+
transport: "ajax",
|
|
80
|
+
paramsProvider: () => { return { abc: '123' }; }
|
|
81
|
+
};
|
|
82
|
+
userAuthenticator = UserAuthenticator(userAuthentication);
|
|
83
|
+
|
|
84
|
+
transportAuthorizer = jasmine.createSpy("ajax")
|
|
85
|
+
Runtime.getAuthorizers = jasmine.createSpy("getAuthorizers").and.returnValue({
|
|
86
|
+
ajax: transportAuthorizer
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const params = { socketId: '1.23' };
|
|
90
|
+
const callback = function(){};
|
|
91
|
+
const query = 'socket_id=1.23&abc=123';
|
|
92
|
+
userAuthenticator(params, callback);
|
|
93
|
+
expect(Runtime.getAuthorizers.calls.count()).toEqual(1);
|
|
94
|
+
expect(transportAuthorizer).toHaveBeenCalledWith(
|
|
95
|
+
Runtime,
|
|
96
|
+
query,
|
|
97
|
+
userAuthentication,
|
|
98
|
+
'user-authentication',
|
|
99
|
+
callback);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("should call the specified transport authorizer with params and paramsProvider", function(){
|
|
103
|
+
const userAuthentication = {
|
|
104
|
+
transport: "ajax",
|
|
105
|
+
params: { abc: '123' },
|
|
106
|
+
paramsProvider: () => { return { def: '456' }; }
|
|
107
|
+
};
|
|
108
|
+
userAuthenticator = UserAuthenticator(userAuthentication);
|
|
109
|
+
|
|
110
|
+
transportAuthorizer = jasmine.createSpy("ajax")
|
|
111
|
+
Runtime.getAuthorizers = jasmine.createSpy("getAuthorizers").and.returnValue({
|
|
112
|
+
ajax: transportAuthorizer
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const params = { socketId: '1.23' };
|
|
116
|
+
const callback = function(){};
|
|
117
|
+
const query = 'socket_id=1.23&abc=123&def=456';
|
|
118
|
+
userAuthenticator(params, callback);
|
|
119
|
+
expect(Runtime.getAuthorizers.calls.count()).toEqual(1);
|
|
120
|
+
expect(transportAuthorizer).toHaveBeenCalledWith(
|
|
121
|
+
Runtime,
|
|
122
|
+
query,
|
|
123
|
+
userAuthentication,
|
|
124
|
+
'user-authentication',
|
|
125
|
+
callback);
|
|
126
|
+
});
|
|
51
127
|
});
|
|
52
128
|
});
|