Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
107 lines (86 loc) · 3.17 KB

File metadata and controls

107 lines (86 loc) · 3.17 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/* global describe, it */
import assert from 'assert';
import lilUUID from 'lil-uuid';
import PubNub from '../../src/node/index';
import CryptoJS from '../../src/core/components/cryptography/hmac-sha256';
describe('#core / mounting point', () => {
it('should have default heartbeat interval undefined', () => {
let pn = new PubNub({});
assert(pn._config.getHeartbeatInterval() === undefined);
});
it('should have correct heartbeat interval set when reducing presence timeout', () => {
let pn = new PubNub({});
let presenceTimeout = 200;
let expectedHeartBeat = presenceTimeout / 2 - 1;
pn._config.setPresenceTimeout(presenceTimeout);
assert(pn._config.getHeartbeatInterval() === expectedHeartBeat);
});
it('should support multiple pnsdk suffix', () => {
let pn = new PubNub({});
let suffix1 = 'suffix1/0.1';
let suffix2 = 'suffix2/0.2';
pn._addPnsdkSuffix('a', suffix1);
pn._addPnsdkSuffix('b', suffix2);
assert(pn._config._getPnsdkSuffix(' ') === ' suffix1/0.1 suffix2/0.2');
});
it('should replace duplicate pnsdk suffix by name', () => {
let pn = new PubNub({});
let suffix1 = 'suffix1/0.1';
let suffix2 = 'suffix2/0.2';
let suffix3 = 'suffix3/0.3';
pn._addPnsdkSuffix('a', suffix1);
pn._addPnsdkSuffix('b', suffix2);
pn._addPnsdkSuffix('a', suffix3); // duplicate name should replace
assert(pn._config._getPnsdkSuffix(' ') === ' suffix3/0.3 suffix2/0.2');
});
it('should default to empty pnsdk suffix', () => {
let pn = new PubNub({});
assert(pn._config._getPnsdkSuffix(' ') === '');
});
it('supports UUID generation', () => {
assert.equal(lilUUID.isUUID(PubNub.generateUUID()), true);
});
it('supports encryption', () => {
let pn = new PubNub({ cipherKey: 'customKey' });
assert.equal(
pn.encrypt(JSON.stringify({ hi: 'there' })),
'TejX6F2JNqH/gIiGHWN4Cw=='
);
});
it('supports encryption with custom key', () => {
let pn = new PubNub({});
assert.equal(
pn.encrypt(JSON.stringify({ hi: 'there' }), 'customKey'),
'TejX6F2JNqH/gIiGHWN4Cw=='
);
});
it('supports decryption', () => {
let pn = new PubNub({ cipherKey: 'customKey' });
assert.deepEqual(pn.decrypt('TejX6F2JNqH/gIiGHWN4Cw=='), { hi: 'there' });
});
it('supports decryption with custom key', () => {
let pn = new PubNub({});
assert.deepEqual(pn.decrypt('TejX6F2JNqH/gIiGHWN4Cw==', 'customKey'), {
hi: 'there',
});
});
it('supports decryption with custom key', () => {
let pn = new PubNub({});
assert.deepEqual(pn.decrypt('TejX6F2JNqH/gIiGHWN4Cw==', 'customKey'), {
hi: 'there',
});
});
it('supports custom encryption/decryption', () => {
let customEncrypt = (data) => {
let cipher = CryptoJS.AES.encrypt(JSON.stringify(data), 'customKey');
return cipher.toString();
};
let customDecrypt = (data) => {
let bytes = CryptoJS.AES.decrypt(data, 'customKey');
return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
};
let pn = new PubNub({ customEncrypt, customDecrypt });
let ciphertext = pn.encrypt({ hi: 'there' });
assert.deepEqual(pn.decrypt(ciphertext), { hi: 'there' });
});
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.