forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipherKeyTest.js
More file actions
executable file
·80 lines (71 loc) · 2.42 KB
/
Copy pathcipherKeyTest.js
File metadata and controls
executable file
·80 lines (71 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var Pubnub = require('cloud/pubnub'),
assert = require('assert'),
Sandbox = require('cloud/utils/sandbox'),
TestSuite = require('cloud/utils/testSuite');
var test = new TestSuite("Using Cipher Key"),
cipher_key = 'blah',
pubnub,
pubnub2,
pubnub3,
sandbox;
test.before(function () {
pubnub = Pubnub.init({
publish_key: test.config.get("pub_key"),
subscribe_key: test.config.get("sub_key"),
secret_key: test.config.get("secret_key"),
cipher_key: cipher_key
});
pubnub2 = Pubnub.init({
publish_key: test.config.get("pub_key"),
subscribe_key: test.config.get("sub_key"),
cipher_key: cipher_key
});
pubnub3 = Pubnub.init({
publish_key: test.config.get("pub_key"),
subscribe_key: test.config.get("sub_key"),
cipher_key: cipher_key + "_wrong"
});
});
test.beforeEach(function () {
sandbox = Sandbox.create();
});
test.it("should be able to send & receive encrypted messages", function (done) {
var channel = 'js-parse-test-cypher',
message = 'hi cypher!',
encodedMessage = 'M5PIZiKHKMaHc1O1E47cxQ==';
pubnub.publish({
channel: channel,
message: message,
callback: function (response) {
assert.equal(response[0], 1);
pubnub2.history({
channel: channel,
count: 1,
callback: function (response) {
assert.equal(response[0][0], message);
pubnub3.history({
channel: channel,
count: 1,
callback: function (response) {
assert.equal(response[0][0], encodedMessage);
done();
},
error: function (error) {
done(new Error("Error callback invoked while shouldn't: " + JSON.stringify(error)))
}
});
},
error: function (error) {
done(new Error("Error callback invoked while shouldn't: " + JSON.stringify(error)))
}
});
},
error: function (error) {
done(new Error("Error callback invoked while shouldn't: " + JSON.stringify(error)))
}
});
});
test.afterEach(function () {
sandbox.restore();
});
module.exports = test;