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
|
@@ -1,23 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
headers?: any;
|
|
1
|
+
export declare enum AuthRequestType {
|
|
2
|
+
UserAuthentication = "user-authentication",
|
|
3
|
+
ChannelAuthorization = "channel-authorization"
|
|
5
4
|
}
|
|
6
|
-
export interface
|
|
5
|
+
export interface ChannelAuthorizationData {
|
|
7
6
|
auth: string;
|
|
8
7
|
channel_data?: string;
|
|
9
8
|
shared_secret?: string;
|
|
10
9
|
}
|
|
11
|
-
export declare type
|
|
12
|
-
export interface
|
|
13
|
-
|
|
10
|
+
export declare type ChannelAuthorizationCallback = (error: Error | null, authData: ChannelAuthorizationData | null) => void;
|
|
11
|
+
export interface ChannelAuthorizationRequestParams {
|
|
12
|
+
socketId: string;
|
|
13
|
+
channelName: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ChannelAuthorizationHandler {
|
|
16
|
+
(params: ChannelAuthorizationRequestParams, callback: ChannelAuthorizationCallback): void;
|
|
17
|
+
}
|
|
18
|
+
export interface UserAuthenticationData {
|
|
19
|
+
auth: string;
|
|
20
|
+
user_data: string;
|
|
21
|
+
}
|
|
22
|
+
export declare type UserAuthenticationCallback = (error: Error | null, authData: UserAuthenticationData | null) => void;
|
|
23
|
+
export interface UserAuthenticationRequestParams {
|
|
24
|
+
socketId: string;
|
|
14
25
|
}
|
|
15
|
-
export interface
|
|
16
|
-
(
|
|
26
|
+
export interface UserAuthenticationHandler {
|
|
27
|
+
(params: UserAuthenticationRequestParams, callback: UserAuthenticationCallback): void;
|
|
17
28
|
}
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
export declare type AuthTransportCallback = ChannelAuthorizationCallback | UserAuthenticationCallback;
|
|
30
|
+
export interface AuthOptions<AuthHandler> {
|
|
31
|
+
transport: 'ajax' | 'jsonp';
|
|
32
|
+
endpoint: string;
|
|
33
|
+
params?: any;
|
|
34
|
+
headers?: any;
|
|
35
|
+
customHandler?: AuthHandler;
|
|
36
|
+
}
|
|
37
|
+
export interface InternalAuthOptions {
|
|
38
|
+
transport: 'ajax' | 'jsonp';
|
|
39
|
+
endpoint: string;
|
|
40
|
+
params?: any;
|
|
41
|
+
headers?: any;
|
|
23
42
|
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { default as EventsDispatcher } from '../events/dispatcher';
|
|
2
2
|
import Pusher from '../pusher';
|
|
3
3
|
import { PusherEvent } from '../connection/protocol/message-types';
|
|
4
|
-
import {
|
|
4
|
+
import { ChannelAuthorizationCallback } from '../auth/options';
|
|
5
5
|
export default class Channel extends EventsDispatcher {
|
|
6
6
|
name: string;
|
|
7
7
|
pusher: Pusher;
|
|
8
8
|
subscribed: boolean;
|
|
9
9
|
subscriptionPending: boolean;
|
|
10
10
|
subscriptionCancelled: boolean;
|
|
11
|
+
subscriptionCount: null;
|
|
11
12
|
constructor(name: string, pusher: Pusher);
|
|
12
|
-
authorize(socketId: string, callback:
|
|
13
|
+
authorize(socketId: string, callback: ChannelAuthorizationCallback): void;
|
|
13
14
|
trigger(event: string, data: any): boolean;
|
|
14
15
|
disconnect(): void;
|
|
15
16
|
handleEvent(event: PusherEvent): void;
|
|
16
17
|
handleSubscriptionSucceededEvent(event: PusherEvent): void;
|
|
18
|
+
handleSubscriptionCountEvent(event: PusherEvent): void;
|
|
17
19
|
subscribe(): void;
|
|
18
20
|
unsubscribe(): void;
|
|
19
21
|
cancelSubscription(): void;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import PrivateChannel from './private_channel';
|
|
2
2
|
import Pusher from '../pusher';
|
|
3
3
|
import { PusherEvent } from '../connection/protocol/message-types';
|
|
4
|
-
import {
|
|
4
|
+
import { ChannelAuthorizationCallback } from '../auth/options';
|
|
5
5
|
import * as nacl from 'tweetnacl';
|
|
6
6
|
export default class EncryptedChannel extends PrivateChannel {
|
|
7
7
|
key: Uint8Array;
|
|
8
8
|
nacl: nacl;
|
|
9
9
|
constructor(name: string, pusher: Pusher, nacl: nacl);
|
|
10
|
-
authorize(socketId: string, callback:
|
|
10
|
+
authorize(socketId: string, callback: ChannelAuthorizationCallback): void;
|
|
11
11
|
trigger(event: string, data: any): boolean;
|
|
12
12
|
handleEvent(event: PusherEvent): void;
|
|
13
13
|
private handleEncryptedEvent;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Channel from './channel';
|
|
2
|
-
import {
|
|
2
|
+
import { ChannelAuthorizationCallback } from '../auth/options';
|
|
3
3
|
export default class PrivateChannel extends Channel {
|
|
4
|
-
authorize(socketId: string, callback:
|
|
4
|
+
authorize(socketId: string, callback: ChannelAuthorizationCallback): void;
|
|
5
5
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Options } from './options';
|
|
2
|
-
import {
|
|
2
|
+
import { ChannelAuthorizationHandler, UserAuthenticationHandler } from './auth/options';
|
|
3
3
|
import * as nacl from 'tweetnacl';
|
|
4
4
|
export declare type AuthTransport = 'ajax' | 'jsonp';
|
|
5
5
|
export declare type Transport = 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs';
|
|
6
6
|
export interface Config {
|
|
7
7
|
activityTimeout: number;
|
|
8
|
-
authEndpoint: string;
|
|
9
|
-
authTransport: AuthTransport;
|
|
10
8
|
enableStats: boolean;
|
|
11
9
|
httpHost: string;
|
|
12
10
|
httpPath: string;
|
|
@@ -20,9 +18,9 @@ export interface Config {
|
|
|
20
18
|
wsPath: string;
|
|
21
19
|
wsPort: number;
|
|
22
20
|
wssPort: number;
|
|
21
|
+
userAuthenticator: UserAuthenticationHandler;
|
|
22
|
+
channelAuthorizer: ChannelAuthorizationHandler;
|
|
23
23
|
forceTLS?: boolean;
|
|
24
|
-
auth?: AuthOptions;
|
|
25
|
-
authorizer?: AuthorizerGenerator;
|
|
26
24
|
cluster?: string;
|
|
27
25
|
disabledTransports?: Transport[];
|
|
28
26
|
enabledTransports?: Transport[];
|
|
@@ -30,4 +28,4 @@ export interface Config {
|
|
|
30
28
|
nacl?: nacl;
|
|
31
29
|
timelineParams?: any;
|
|
32
30
|
}
|
|
33
|
-
export declare function getConfig(opts: Options): Config;
|
|
31
|
+
export declare function getConfig(opts: Options, pusher: any): Config;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AuthOptions, ChannelAuthorizationHandler, UserAuthenticationHandler } from './auth/options';
|
|
1
2
|
import { AuthTransport } from './config';
|
|
2
3
|
export interface DefaultConfig {
|
|
3
4
|
VERSION: string;
|
|
@@ -16,6 +17,8 @@ export interface DefaultConfig {
|
|
|
16
17
|
pongTimeout: number;
|
|
17
18
|
unavailableTimeout: number;
|
|
18
19
|
cluster: string;
|
|
20
|
+
userAuthentication: AuthOptions<UserAuthenticationHandler>;
|
|
21
|
+
channelAuthorization: AuthOptions<ChannelAuthorizationHandler>;
|
|
19
22
|
cdn_http?: string;
|
|
20
23
|
cdn_https?: string;
|
|
21
24
|
dependency_suffix?: string;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { AuthOptions,
|
|
1
|
+
import { AuthOptions, ChannelAuthorizationHandler, UserAuthenticationHandler } from './auth/options';
|
|
2
|
+
import { ChannelAuthorizerGenerator, DeprecatedAuthOptions } from './auth/deprecated_channel_authorizer';
|
|
2
3
|
import { AuthTransport, Transport } from './config';
|
|
3
4
|
import * as nacl from 'tweetnacl';
|
|
4
5
|
export interface Options {
|
|
5
6
|
activityTimeout?: number;
|
|
6
|
-
auth?:
|
|
7
|
+
auth?: DeprecatedAuthOptions;
|
|
7
8
|
authEndpoint?: string;
|
|
8
9
|
authTransport?: AuthTransport;
|
|
9
|
-
authorizer?:
|
|
10
|
+
authorizer?: ChannelAuthorizerGenerator;
|
|
11
|
+
channelAuthorization?: AuthOptions<ChannelAuthorizationHandler>;
|
|
12
|
+
userAuthentication?: AuthOptions<UserAuthenticationHandler>;
|
|
10
13
|
cluster?: string;
|
|
11
14
|
enableStats?: boolean;
|
|
12
15
|
disableStats?: boolean;
|
|
@@ -8,6 +8,7 @@ import ConnectionManager from './connection/connection_manager';
|
|
|
8
8
|
import { PeriodicTimer } from './utils/timers';
|
|
9
9
|
import { Options } from './options';
|
|
10
10
|
import { Config } from './config';
|
|
11
|
+
import UserFacade from './user';
|
|
11
12
|
export default class Pusher {
|
|
12
13
|
static instances: Pusher[];
|
|
13
14
|
static isReady: boolean;
|
|
@@ -28,6 +29,7 @@ export default class Pusher {
|
|
|
28
29
|
timelineSender: TimelineSender;
|
|
29
30
|
connection: ConnectionManager;
|
|
30
31
|
timelineSenderTimer: PeriodicTimer;
|
|
32
|
+
user: UserFacade;
|
|
31
33
|
constructor(app_key: string, options?: Options);
|
|
32
34
|
channel(name: string): Channel;
|
|
33
35
|
allChannels(): Channel[];
|
|
@@ -43,4 +45,5 @@ export default class Pusher {
|
|
|
43
45
|
unsubscribe(channel_name: string): void;
|
|
44
46
|
send_event(event_name: string, data: any, channel?: string): boolean;
|
|
45
47
|
shouldUseTLS(): boolean;
|
|
48
|
+
signin(): void;
|
|
46
49
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Pusher from './pusher';
|
|
2
|
+
import Channel from './channels/channel';
|
|
3
|
+
import EventsDispatcher from './events/dispatcher';
|
|
4
|
+
export default class UserFacade extends EventsDispatcher {
|
|
5
|
+
pusher: Pusher;
|
|
6
|
+
signin_requested: boolean;
|
|
7
|
+
user_data: any;
|
|
8
|
+
serverToUserChannel: Channel;
|
|
9
|
+
constructor(pusher: Pusher);
|
|
10
|
+
signin(): void;
|
|
11
|
+
private _signin;
|
|
12
|
+
private _onSigninSuccess;
|
|
13
|
+
private _subscribeChannels;
|
|
14
|
+
private _disconnect;
|
|
15
|
+
}
|
|
@@ -4,7 +4,6 @@ import Transport from '../transports/transport';
|
|
|
4
4
|
import TransportManager from '../transports/transport_manager';
|
|
5
5
|
import Handshake from '../connection/handshake';
|
|
6
6
|
import TransportConnection from '../transports/transport_connection';
|
|
7
|
-
import { AuthorizerOptions, Authorizer } from '../auth/options';
|
|
8
7
|
import Timeline from '../timeline/timeline';
|
|
9
8
|
import { default as TimelineSender, TimelineSenderOptions } from '../timeline/timeline_sender';
|
|
10
9
|
import PresenceChannel from '../channels/presence_channel';
|
|
@@ -24,7 +23,6 @@ declare var Factory: {
|
|
|
24
23
|
createPresenceChannel(name: string, pusher: Pusher): PresenceChannel;
|
|
25
24
|
createEncryptedChannel(name: string, pusher: Pusher, nacl: nacl): EncryptedChannel;
|
|
26
25
|
createTimelineSender(timeline: Timeline, options: TimelineSenderOptions): TimelineSender;
|
|
27
|
-
createAuthorizer(channel: Channel, options: AuthorizerOptions): Authorizer;
|
|
28
26
|
createHandshake(transport: TransportConnection, callback: (HandshakePayload: any) => void): Handshake;
|
|
29
27
|
createAssistantToTheTransportManager(manager: TransportManager, transport: Transport, options: PingDelayOptions): AssistantToTheTransportManager;
|
|
30
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('
|
|
1
|
+
module.exports = require('../../dist/worker/pusher-with-encryption.worker.js');
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
var TestEnv = require('testenv');
|
|
2
|
-
var Authorizer = require('core/auth/pusher_authorizer').default;
|
|
3
|
-
var Logger = require('core/logger');
|
|
4
|
-
var Mocks = require('mocks');
|
|
5
|
-
var Util = require('core/util').default;
|
|
6
|
-
var Factory = require('core/utils/factory').default;
|
|
7
|
-
var Logger = require('core/logger').default;
|
|
8
|
-
var Runtime = require('runtime').default;
|
|
9
|
-
|
|
10
|
-
describe("Authorizer", function() {
|
|
11
|
-
|
|
12
|
-
describe("initialization", function(){
|
|
13
|
-
it("should throw an error if the specified transport is unrecognized", function(){
|
|
14
|
-
expect(function(){
|
|
15
|
-
new Authorizer({name: "chan"}, {
|
|
16
|
-
authTransport: "yolo"
|
|
17
|
-
})
|
|
18
|
-
}).toThrow("'yolo' is not a recognized auth transport");
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe("#composeQuery", function() {
|
|
23
|
-
it("should return str with just socket id and channel name if no auth query options", function() {
|
|
24
|
-
var authorizer = new Authorizer({ name: "chan" }, {authTransport: "ajax"});
|
|
25
|
-
|
|
26
|
-
expect(authorizer.composeQuery("1.1"))
|
|
27
|
-
.toEqual("socket_id=1.1&channel_name=chan");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should add query params specified in options object", function() {
|
|
31
|
-
var authorizer = new Authorizer(
|
|
32
|
-
{ name: "chan" },
|
|
33
|
-
{ auth: {
|
|
34
|
-
params: { a: 1, b: 2 }
|
|
35
|
-
},
|
|
36
|
-
authTransport: "ajax"
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
expect(authorizer.composeQuery("1.1"))
|
|
41
|
-
.toEqual("socket_id=1.1&channel_name=chan&a=1&b=2");
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (TestEnv !== "worker") {
|
|
48
|
-
describe("AJAX Authorizer", function() {
|
|
49
|
-
var xhr;
|
|
50
|
-
|
|
51
|
-
beforeEach(function() {
|
|
52
|
-
xhr = new Mocks.getXHR();
|
|
53
|
-
|
|
54
|
-
if (TestEnv === "web" && !window.XMLHttpRequest) {
|
|
55
|
-
spyOn(Runtime, "createMicrosoftXHR").and.returnValue(xhr);
|
|
56
|
-
} else {
|
|
57
|
-
spyOn(Runtime, "createXHR").and.returnValue(xhr);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("should pass headers in the request", function() {
|
|
62
|
-
var headers = { "foo": "bar", "n": 42 };
|
|
63
|
-
var authorizer = new Authorizer(
|
|
64
|
-
{ name: "chan" },
|
|
65
|
-
{ authTransport: "ajax",
|
|
66
|
-
auth: {
|
|
67
|
-
headers: headers
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
authorizer.authorize("1.23", function() {});
|
|
72
|
-
|
|
73
|
-
expect(xhr.setRequestHeader.calls.count()).toEqual(3);
|
|
74
|
-
expect(xhr.setRequestHeader).toHaveBeenCalledWith(
|
|
75
|
-
"Content-Type", "application/x-www-form-urlencoded"
|
|
76
|
-
);
|
|
77
|
-
expect(xhr.setRequestHeader).toHaveBeenCalledWith("foo", "bar");
|
|
78
|
-
expect(xhr.setRequestHeader).toHaveBeenCalledWith("n", 42);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("should pass params in the query string", function() {
|
|
82
|
-
var params = { "a": 1, "b": 2 };
|
|
83
|
-
var authorizer = new Authorizer(
|
|
84
|
-
{ name: "chan" },
|
|
85
|
-
{ authTransport: "ajax",
|
|
86
|
-
auth: {
|
|
87
|
-
params: params
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
authorizer.authorize("1.23", function() {});
|
|
92
|
-
|
|
93
|
-
expect(xhr.send.calls.count()).toEqual(1);
|
|
94
|
-
expect(xhr.send).toHaveBeenCalledWith(
|
|
95
|
-
"socket_id=1.23&channel_name=chan&a=1&b=2"
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should call back with auth result on success", function() {
|
|
100
|
-
var authorizer = new Authorizer(
|
|
101
|
-
{ name: "chan" },
|
|
102
|
-
{ authTransport: "ajax" }
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
var data = { foo: "bar", number: 1};
|
|
106
|
-
var dataJSON = JSON.stringify(data);
|
|
107
|
-
|
|
108
|
-
var callback = jasmine.createSpy("callback");
|
|
109
|
-
authorizer.authorize("1.23", callback);
|
|
110
|
-
|
|
111
|
-
if (TestEnv === "web" && !window.XMLHttpRequest) {
|
|
112
|
-
expect(Runtime.createMicrosoftXHR.calls.count()).toEqual(1);
|
|
113
|
-
} else {
|
|
114
|
-
expect(Runtime.createXHR.calls.count()).toEqual(1);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
xhr.readyState = 4;
|
|
118
|
-
xhr.status = 200;
|
|
119
|
-
xhr.responseText = dataJSON;
|
|
120
|
-
xhr.onreadystatechange();
|
|
121
|
-
|
|
122
|
-
expect(callback.calls.count()).toEqual(1);
|
|
123
|
-
expect(callback).toHaveBeenCalledWith(null, data);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should call back with an error if JSON in xhr.responseText is invalid", function() {
|
|
127
|
-
var authorizer = new Authorizer(
|
|
128
|
-
{ name: "chan" },
|
|
129
|
-
{ authTransport: "ajax" }
|
|
130
|
-
);
|
|
131
|
-
var invalidJSON = 'INVALID { "something": "something"}';
|
|
132
|
-
var callback = jasmine.createSpy("callback");
|
|
133
|
-
authorizer.authorize("1.23", callback);
|
|
134
|
-
|
|
135
|
-
if (TestEnv === "web" && !window.XMLHttpRequest) {
|
|
136
|
-
expect(Runtime.createMicrosoftXHR.calls.count()).toEqual(1);
|
|
137
|
-
} else {
|
|
138
|
-
expect(Runtime.createXHR.calls.count()).toEqual(1);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
xhr.readyState = 4;
|
|
142
|
-
xhr.status = 200;
|
|
143
|
-
xhr.responseText = invalidJSON;
|
|
144
|
-
xhr.onreadystatechange();
|
|
145
|
-
|
|
146
|
-
expect(callback.calls.count()).toEqual(1);
|
|
147
|
-
// For some reason comparing the Error types doesn't work properly in
|
|
148
|
-
// Safari on Mojave. Manually check the arguments.
|
|
149
|
-
let args = callback.calls.first().args;
|
|
150
|
-
expect(args.length).toEqual(2)
|
|
151
|
-
expect(args[0]).toEqual(jasmine.any(Error))
|
|
152
|
-
expect(args[0].message).toEqual(
|
|
153
|
-
"JSON returned from auth endpoint was invalid, yet status code was 200. " +
|
|
154
|
-
"Data was: " +
|
|
155
|
-
invalidJSON
|
|
156
|
-
);
|
|
157
|
-
expect(args[1]).toEqual({auth: ""});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
var Authorizer = require('core/auth/pusher_authorizer').default;
|
|
2
|
-
var fetchAuth = require('worker/auth/fetch_auth').default;
|
|
3
|
-
var Runtime = require('runtime').default;
|
|
4
|
-
var fetchMock = require('fetch-mock');
|
|
5
|
-
|
|
6
|
-
var endpoint = 'http://example.org/pusher/auth';
|
|
7
|
-
|
|
8
|
-
describe("Fetch Authorizer", function(){
|
|
9
|
-
|
|
10
|
-
beforeEach(function(){
|
|
11
|
-
Authorizer.authorizers = {ajax: fetchAuth}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
afterEach(function(){
|
|
15
|
-
fetchMock.restore();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("should pass headers in the request", function(){
|
|
19
|
-
fetchMock
|
|
20
|
-
.mock(endpoint, {body: {hello: "world"}});
|
|
21
|
-
|
|
22
|
-
var headers = { "foo": "bar", "n": 42 };
|
|
23
|
-
var authorizer = new Authorizer(
|
|
24
|
-
{ name: "chan" },
|
|
25
|
-
{ authTransport: "ajax",
|
|
26
|
-
authEndpoint: endpoint,
|
|
27
|
-
auth: {
|
|
28
|
-
headers: headers
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
authorizer.authorize("1.23", function() {});
|
|
34
|
-
|
|
35
|
-
var lastCall = fetchMock.lastCall(endpoint)[0];
|
|
36
|
-
var sentHeaders = lastCall.headers;
|
|
37
|
-
expect(sentHeaders.get("Content-Type")).toEqual("application/x-www-form-urlencoded");
|
|
38
|
-
expect(sentHeaders.get("foo")).toEqual("bar");
|
|
39
|
-
expect(sentHeaders.get("n")).toEqual('42');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("should pass params in the query string", function(){
|
|
43
|
-
fetchMock
|
|
44
|
-
.mock(endpoint, {body: {hello: "world"}});
|
|
45
|
-
|
|
46
|
-
var params = { "a": 1, "b": 2 };
|
|
47
|
-
var authorizer = new Authorizer(
|
|
48
|
-
{ name: "chan" },
|
|
49
|
-
{ authTransport: "ajax",
|
|
50
|
-
authEndpoint: endpoint,
|
|
51
|
-
auth: {
|
|
52
|
-
params: params
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
authorizer.authorize("1.23", function() {}).then(function(){
|
|
57
|
-
var lastCall = fetchMock.lastCall(endpoint)[0];
|
|
58
|
-
console.log(lastCall);
|
|
59
|
-
expect(lastCall.body).toEqual("socket_id=1.23&channel_name=chan&a=1&b=2");
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("should call back with the auth result on success", function(){
|
|
64
|
-
var data = { foo: "bar", number: 1};
|
|
65
|
-
var dataJSON = JSON.stringify(data);
|
|
66
|
-
|
|
67
|
-
fetchMock.mock(endpoint, {
|
|
68
|
-
body: dataJSON
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
var authorizer = new Authorizer(
|
|
72
|
-
{ name: "chan" },
|
|
73
|
-
{
|
|
74
|
-
authTransport: "ajax",
|
|
75
|
-
authEndpoint: endpoint
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
var callback = jasmine.createSpy("callback");
|
|
79
|
-
authorizer.authorize("1.23", callback).then(function(){
|
|
80
|
-
expect(callback.calls.count()).toEqual(1);
|
|
81
|
-
expect(callback).toHaveBeenCalledWith(false, data);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should call back with an error if JSON is invalid", function(){
|
|
86
|
-
var authorizer = new Authorizer(
|
|
87
|
-
{ name: "chan" },
|
|
88
|
-
{
|
|
89
|
-
authTransport: "ajax",
|
|
90
|
-
authEndpoint: endpoint
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
var invalidJSON = 'INVALID { "something": "something"}';
|
|
95
|
-
fetchMock.mock(endpoint, {
|
|
96
|
-
body: invalidJSON
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
var callback = jasmine.createSpy("callback");
|
|
100
|
-
|
|
101
|
-
authorizer.authorize("1.23", callback).then(function(){
|
|
102
|
-
expect(callback.calls.count()).toEqual(1);
|
|
103
|
-
expect(callback).toHaveBeenCalledWith(
|
|
104
|
-
true,
|
|
105
|
-
"JSON returned from auth endpoint was invalid, yet status code was 200. " +
|
|
106
|
-
"Data was: " +
|
|
107
|
-
invalidJSON
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import Logger from '../logger';
|
|
2
|
-
import Channel from '../channels/channel';
|
|
3
|
-
import Factory from '../utils/factory';
|
|
4
|
-
import Runtime from 'runtime';
|
|
5
|
-
import { AuthTransports } from './auth_transports';
|
|
6
|
-
import {
|
|
7
|
-
AuthOptions,
|
|
8
|
-
AuthorizerOptions,
|
|
9
|
-
Authorizer,
|
|
10
|
-
AuthorizerCallback
|
|
11
|
-
} from './options';
|
|
12
|
-
|
|
13
|
-
export default class PusherAuthorizer implements Authorizer {
|
|
14
|
-
static authorizers: AuthTransports;
|
|
15
|
-
|
|
16
|
-
channel: Channel;
|
|
17
|
-
type: string;
|
|
18
|
-
options: AuthorizerOptions;
|
|
19
|
-
authOptions: AuthOptions;
|
|
20
|
-
|
|
21
|
-
constructor(channel: Channel, options: AuthorizerOptions) {
|
|
22
|
-
this.channel = channel;
|
|
23
|
-
|
|
24
|
-
let { authTransport } = options;
|
|
25
|
-
|
|
26
|
-
if (typeof Runtime.getAuthorizers()[authTransport] === 'undefined') {
|
|
27
|
-
throw `'${authTransport}' is not a recognized auth transport`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this.type = authTransport;
|
|
31
|
-
this.options = options;
|
|
32
|
-
this.authOptions = options.auth || {};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
composeQuery(socketId: string): string {
|
|
36
|
-
var query =
|
|
37
|
-
'socket_id=' +
|
|
38
|
-
encodeURIComponent(socketId) +
|
|
39
|
-
'&channel_name=' +
|
|
40
|
-
encodeURIComponent(this.channel.name);
|
|
41
|
-
|
|
42
|
-
for (var i in this.authOptions.params) {
|
|
43
|
-
query +=
|
|
44
|
-
'&' +
|
|
45
|
-
encodeURIComponent(i) +
|
|
46
|
-
'=' +
|
|
47
|
-
encodeURIComponent(this.authOptions.params[i]);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return query;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
authorize(socketId: string, callback: AuthorizerCallback): void {
|
|
54
|
-
PusherAuthorizer.authorizers =
|
|
55
|
-
PusherAuthorizer.authorizers || Runtime.getAuthorizers();
|
|
56
|
-
|
|
57
|
-
PusherAuthorizer.authorizers[this.type].call(
|
|
58
|
-
this,
|
|
59
|
-
Runtime,
|
|
60
|
-
socketId,
|
|
61
|
-
callback
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
package/types/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import Pusher from './src/core/pusher'
|
|
2
|
-
import { Authorizer, AuthOptions, AuthorizerGenerator } from './src/core/auth/options';
|
|
3
|
-
import { Options } from './src/core/options'
|
|
4
|
-
import Channel from './src/core/channels/channel';
|
|
5
|
-
import Runtime from './src/runtimes/interface'
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
Options,
|
|
9
|
-
AuthOptions,
|
|
10
|
-
AuthorizerGenerator,
|
|
11
|
-
Authorizer,
|
|
12
|
-
Channel,
|
|
13
|
-
Runtime,
|
|
14
|
-
}
|
|
15
|
-
export default Pusher
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Channel from '../channels/channel';
|
|
2
|
-
import { AuthTransports } from './auth_transports';
|
|
3
|
-
import { AuthOptions, AuthorizerOptions, Authorizer, AuthorizerCallback } from './options';
|
|
4
|
-
export default class PusherAuthorizer implements Authorizer {
|
|
5
|
-
static authorizers: AuthTransports;
|
|
6
|
-
channel: Channel;
|
|
7
|
-
type: string;
|
|
8
|
-
options: AuthorizerOptions;
|
|
9
|
-
authOptions: AuthOptions;
|
|
10
|
-
constructor(channel: Channel, options: AuthorizerOptions);
|
|
11
|
-
composeQuery(socketId: string): string;
|
|
12
|
-
authorize(socketId: string, callback: AuthorizerCallback): void;
|
|
13
|
-
}
|