pubnub 4.0.27 → 4.0.28
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pubnub might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.pubnub.yml +8 -1
- data/.rubocop.yml +9 -3
- data/.travis.yml +6 -19
- data/CHANGELOG.md +86 -82
- data/Gemfile +7 -5
- data/Gemfile.lock +155 -157
- data/README.md +34 -34
- data/VERSION +1 -1
- data/gemfiles/celluloid_017.gemfile +4 -4
- data/gemfiles/celluloid_018.gemfile +4 -4
- data/gemfiles/celluloid_master.gemfile +4 -4
- data/gemfiles/concurrent-ruby-1.0.5.gem +0 -0
- data/gemfiles/concurrent-ruby-edge-0.3.1.gem +0 -0
- data/lib/pubnub.rb +3 -3
- data/lib/pubnub/client.rb +19 -16
- data/lib/pubnub/client/events.rb +5 -5
- data/lib/pubnub/client/getters_setters.rb +11 -12
- data/lib/pubnub/client/paged_history.rb +11 -9
- data/lib/pubnub/configuration.rb +1 -2
- data/lib/pubnub/constants.rb +47 -47
- data/lib/pubnub/crypto.rb +2 -2
- data/lib/pubnub/envelope.rb +7 -5
- data/lib/pubnub/error.rb +22 -15
- data/lib/pubnub/event.rb +24 -25
- data/lib/pubnub/event/formatter.rb +8 -5
- data/lib/pubnub/event/signature.rb +3 -3
- data/lib/pubnub/events/audit.rb +1 -1
- data/lib/pubnub/events/channel_registration.rb +10 -15
- data/lib/pubnub/events/delete_messages.rb +9 -9
- data/lib/pubnub/events/grant.rb +3 -3
- data/lib/pubnub/events/heartbeat.rb +4 -8
- data/lib/pubnub/events/here_now.rb +4 -8
- data/lib/pubnub/events/history.rb +10 -10
- data/lib/pubnub/events/leave.rb +2 -2
- data/lib/pubnub/events/presence.rb +1 -1
- data/lib/pubnub/events/publish.rb +3 -5
- data/lib/pubnub/events/revoke.rb +3 -3
- data/lib/pubnub/events/set_state.rb +3 -3
- data/lib/pubnub/events/state.rb +4 -6
- data/lib/pubnub/events/subscribe.rb +1 -1
- data/lib/pubnub/events/time.rb +2 -2
- data/lib/pubnub/events/where_now.rb +6 -6
- data/lib/pubnub/format.rb +73 -0
- data/lib/pubnub/formatter.rb +23 -21
- data/lib/pubnub/heart.rb +4 -4
- data/lib/pubnub/origin_manager.rb +3 -5
- data/lib/pubnub/pam.rb +5 -5
- data/lib/pubnub/schemas/envelope_schema.rb +1 -1
- data/lib/pubnub/subscribe_callback.rb +3 -3
- data/lib/pubnub/subscribe_event.rb +6 -10
- data/lib/pubnub/subscribe_event/formatter.rb +82 -80
- data/lib/pubnub/subscribe_event/heartbeat.rb +1 -1
- data/lib/pubnub/subscriber.rb +31 -32
- data/lib/pubnub/telemetry.rb +26 -27
- data/lib/pubnub/validators/audit.rb +3 -2
- data/lib/pubnub/validators/channel_registration.rb +6 -4
- data/lib/pubnub/validators/client.rb +1 -0
- data/lib/pubnub/validators/common_validator.rb +37 -31
- data/lib/pubnub/validators/delete.rb +5 -4
- data/lib/pubnub/validators/grant.rb +3 -2
- data/lib/pubnub/validators/history.rb +3 -2
- data/lib/pubnub/validators/leave.rb +3 -2
- data/lib/pubnub/validators/presence.rb +3 -2
- data/lib/pubnub/validators/publish.rb +15 -10
- data/lib/pubnub/validators/set_state.rb +0 -2
- data/lib/pubnub/validators/state.rb +3 -2
- data/lib/pubnub/version.rb +1 -1
- data/pubnub.gemspec +19 -18
- data/spec/examples/audit_examples_spec.rb +1268 -1418
- data/spec/examples/channel_registration_examples_spec.rb +655 -757
- data/spec/examples/delete_messages_examples_spec.rb +19 -21
- data/spec/examples/grant_examples_spec.rb +34028 -37920
- data/spec/examples/heartbeat_examples_spec.rb +583 -731
- data/spec/examples/here_now_examples_spec.rb +493 -569
- data/spec/examples/history_examples_spec.rb +979 -1127
- data/spec/examples/leave_examples_spec.rb +439 -551
- data/spec/examples/presence_examples_spec.rb +686 -830
- data/spec/examples/publish_examples_spec.rb +27223 -31547
- data/spec/examples/publish_with_ttl_spec.rb +11 -14
- data/spec/examples/revoke_examples_spec.rb +68048 -75828
- data/spec/examples/set_state_examples_spec.rb +295 -371
- data/spec/examples/state_examples_spec.rb +169 -197
- data/spec/examples/status_request_message_count_exceeded_spec.rb +16 -19
- data/spec/examples/subscribe_examples_spec.rb +43843 -52035
- data/spec/examples/time_examples_spec.rb +82 -98
- data/spec/examples/where_now_examples_spec.rb +88 -104
- data/spec/lib/client_spec.rb +99 -117
- data/spec/lib/connection_callback_spec.rb +27 -33
- data/spec/lib/custom_retries_examples_spec.rb +8 -11
- data/spec/lib/event_spec.rb +35 -42
- data/spec/lib/events/audit_spec.rb +19 -25
- data/spec/lib/events/channel_registration_spec.rb +17 -23
- data/spec/lib/events/delete_messages_spec.rb +14 -20
- data/spec/lib/events/grant_spec.rb +15 -21
- data/spec/lib/events/heartbeat_spec.rb +21 -27
- data/spec/lib/events/here_now_spec.rb +14 -20
- data/spec/lib/events/history_spec.rb +14 -20
- data/spec/lib/events/leave_spec.rb +14 -20
- data/spec/lib/events/presence_delta_spec.rb +15 -16
- data/spec/lib/events/presence_spec.rb +36 -45
- data/spec/lib/events/publish_spec.rb +33 -40
- data/spec/lib/events/revoke_spec.rb +16 -22
- data/spec/lib/events/state_spec.rb +16 -22
- data/spec/lib/events/subscribe_spec.rb +75 -85
- data/spec/lib/events/time_spec.rb +12 -18
- data/spec/lib/events/timeout_handling_spec.rb +8 -14
- data/spec/lib/events/where_now_spec.rb +14 -20
- data/spec/lib/keep_alive_spec.rb +4 -8
- data/spec/lib/multiple_ciphers_spec.rb +56 -60
- data/spec/lib/pubnub_spec.rb +10 -13
- data/spec/lib/signatures_spec.rb +118 -120
- data/spec/lib/ssl_error_spec.rb +14 -18
- data/spec/lib/super_admin_spec.rb +58 -66
- data/spec/lib/uuid_spec.rb +3 -4
- data/spec/spec_expectations.rb +3 -3
- data/spec/spec_helper.rb +29 -46
- metadata +52 -22
- data/lib/pubnub/message.rb +0 -43
@@ -1,33 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub::Time do
|
4
|
-
it_behaves_like
|
4
|
+
it_behaves_like "an event"
|
5
5
|
|
6
|
-
|
7
|
-
Celluloid.boot
|
8
|
-
example.run
|
9
|
-
Celluloid.shutdown
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given basic parameters' do
|
6
|
+
context "given basic parameters" do
|
13
7
|
before :each do
|
14
8
|
@pubnub = Pubnub::Client.new(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
10
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
11
|
+
auth_key: "ruby-test-auth",
|
12
|
+
uuid: "ruby-test-uuid",
|
19
13
|
)
|
20
14
|
end
|
21
|
-
it
|
22
|
-
VCR.use_cassette(
|
15
|
+
it "works" do
|
16
|
+
VCR.use_cassette("lib/events/time", record: :once) do
|
23
17
|
envelope = @pubnub.time.value
|
24
18
|
|
25
19
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
26
20
|
end
|
27
21
|
end
|
28
22
|
|
29
|
-
it
|
30
|
-
VCR.use_cassette(
|
23
|
+
it "forms valid ErrorEnvelope on error" do
|
24
|
+
VCR.use_cassette("lib/events/time-error", record: :once) do
|
31
25
|
envelope = @pubnub.time.value
|
32
26
|
|
33
27
|
expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true
|
@@ -35,4 +29,4 @@ describe Pubnub::Time do
|
|
35
29
|
end
|
36
30
|
end
|
37
31
|
end
|
38
|
-
end
|
32
|
+
end
|
@@ -1,19 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
Celluloid.boot
|
6
|
-
example.run
|
7
|
-
Celluloid.shutdown
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'in single event' do
|
3
|
+
describe "timeout" do
|
4
|
+
context "in single event" do
|
11
5
|
let(:pubnub) do
|
12
6
|
Pubnub::Client.new(
|
13
|
-
subscribe_key:
|
14
|
-
publish_key:
|
15
|
-
auth_key:
|
16
|
-
uuid:
|
7
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
8
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
9
|
+
auth_key: "ruby-test-auth",
|
10
|
+
uuid: "ruby-test-uuid",
|
17
11
|
)
|
18
12
|
end
|
19
13
|
let(:envelope) { pubnub.time.value }
|
@@ -21,7 +15,7 @@ describe 'timeout' do
|
|
21
15
|
[
|
22
16
|
HTTPClient::ConnectTimeoutError,
|
23
17
|
HTTPClient::ReceiveTimeoutError,
|
24
|
-
HTTPClient::SendTimeoutError
|
18
|
+
HTTPClient::SendTimeoutError,
|
25
19
|
].each do |error_class|
|
26
20
|
it "forms valid ErrorEnvelope on #{error_class}" do
|
27
21
|
allow_any_instance_of(HTTPClient).to receive(:get).and_return error_class.new
|
@@ -1,27 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub::WhereNow do
|
4
|
-
it_behaves_like
|
4
|
+
it_behaves_like "an event"
|
5
5
|
|
6
|
-
|
7
|
-
Celluloid.boot
|
8
|
-
example.run
|
9
|
-
Celluloid.shutdown
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given basic parameters' do
|
6
|
+
context "given basic parameters" do
|
13
7
|
before :each do
|
14
8
|
@pubnub = Pubnub::Client.new(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
10
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
11
|
+
auth_key: "ruby-test-auth",
|
12
|
+
uuid: "ruby-test-uuid",
|
19
13
|
)
|
20
14
|
end
|
21
|
-
it
|
22
|
-
VCR.use_cassette(
|
15
|
+
it "works" do
|
16
|
+
VCR.use_cassette("lib/events/where-now", record: :once) do
|
23
17
|
envelope = @pubnub.where_now(
|
24
|
-
|
18
|
+
uuid: "ruby-test",
|
25
19
|
).value
|
26
20
|
|
27
21
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
@@ -29,10 +23,10 @@ describe Pubnub::WhereNow do
|
|
29
23
|
end
|
30
24
|
end
|
31
25
|
|
32
|
-
it
|
33
|
-
VCR.use_cassette(
|
26
|
+
it "forms valid ErrorEnvelope on error" do
|
27
|
+
VCR.use_cassette("lib/events/where-now-error", record: :once) do
|
34
28
|
envelope = @pubnub.where_now(
|
35
|
-
|
29
|
+
uuid: "ruby-test",
|
36
30
|
).value
|
37
31
|
|
38
32
|
expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true
|
@@ -40,4 +34,4 @@ describe Pubnub::WhereNow do
|
|
40
34
|
end
|
41
35
|
end
|
42
36
|
end
|
43
|
-
end
|
37
|
+
end
|
data/spec/lib/keep_alive_spec.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe 'keep_alive connection' do
|
1
|
+
require "spec_helper"
|
4
2
|
|
3
|
+
describe "keep_alive connection" do
|
5
4
|
around :each do |example|
|
6
|
-
|
7
|
-
example.run
|
8
|
-
Celluloid.shutdown
|
5
|
+
example.run_with_retry retry: 10
|
9
6
|
end
|
10
7
|
|
11
|
-
it
|
12
|
-
|
8
|
+
it ""
|
13
9
|
end
|
@@ -1,145 +1,141 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe 'Using multiple cipher keys' do
|
1
|
+
require "spec_helper"
|
4
2
|
|
3
|
+
describe "Using multiple cipher keys" do
|
5
4
|
around :each do |example|
|
6
|
-
|
7
|
-
example.run
|
8
|
-
Celluloid.shutdown
|
5
|
+
example.run_with_retry retry: 10
|
9
6
|
end
|
10
7
|
|
11
|
-
it
|
12
|
-
@pubnub = Pubnub.new(subscribe_key: :demo, publish_key: :demo, cipher_key:
|
8
|
+
it "works with publish" do
|
9
|
+
@pubnub = Pubnub.new(subscribe_key: :demo, publish_key: :demo, cipher_key: "this_doesnt_fit_anywhere")
|
13
10
|
|
14
|
-
VCR.use_cassette(
|
11
|
+
VCR.use_cassette("lib/multiple_ciphers", record: :once) do
|
15
12
|
# Fetch current timestamp
|
16
13
|
@pubnub.subscribe(channel: :multiple_cipher_test, http_sync: true)
|
17
14
|
|
18
15
|
@pubnub.publish(
|
19
16
|
channel: :multiple_cipher_test,
|
20
|
-
message:
|
21
|
-
cipher_key:
|
22
|
-
http_sync: true
|
17
|
+
message: "Some test message",
|
18
|
+
cipher_key: "super_secret",
|
19
|
+
http_sync: true,
|
23
20
|
)
|
24
21
|
|
25
22
|
e0 = @pubnub.subscribe(
|
26
23
|
channel: :multiple_cipher_test,
|
27
|
-
cipher_key:
|
28
|
-
http_sync: true
|
24
|
+
cipher_key: "super_secret",
|
25
|
+
http_sync: true,
|
29
26
|
).first
|
30
27
|
|
31
28
|
@pubnub.publish(
|
32
29
|
channel: :multiple_cipher_test,
|
33
|
-
message:
|
34
|
-
cipher_key:
|
35
|
-
http_sync: true
|
30
|
+
message: "Another test message",
|
31
|
+
cipher_key: "another_secret",
|
32
|
+
http_sync: true,
|
36
33
|
)
|
37
34
|
|
38
35
|
e1 = @pubnub.subscribe(
|
39
36
|
channel: :multiple_cipher_test,
|
40
|
-
cipher_key:
|
41
|
-
http_sync: true
|
37
|
+
cipher_key: "another_secret",
|
38
|
+
http_sync: true,
|
42
39
|
).first
|
43
40
|
|
44
|
-
expect(e0.result[:data][:message]).to eq
|
45
|
-
expect(e1.result[:data][:message]).to eq
|
41
|
+
expect(e0.result[:data][:message]).to eq "Some test message"
|
42
|
+
expect(e1.result[:data][:message]).to eq "Another test message"
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
49
|
-
it
|
50
|
-
@pubnub = Pubnub.new(subscribe_key: :demo, publish_key: :demo, cipher_key:
|
46
|
+
it "works with history" do
|
47
|
+
@pubnub = Pubnub.new(subscribe_key: :demo, publish_key: :demo, cipher_key: "this_doesnt_fit_anywhere")
|
51
48
|
|
52
|
-
VCR.use_cassette(
|
49
|
+
VCR.use_cassette("lib/multiple_ciphers_history", record: :once) do
|
53
50
|
@pubnub.publish(
|
54
51
|
channel: :multiple_cipher_test,
|
55
|
-
message:
|
56
|
-
cipher_key:
|
57
|
-
http_sync: true
|
52
|
+
message: "Some test message",
|
53
|
+
cipher_key: "super_secret",
|
54
|
+
http_sync: true,
|
58
55
|
)
|
59
56
|
|
60
57
|
e0 = @pubnub.history(
|
61
58
|
channel: :multiple_cipher_test,
|
62
|
-
cipher_key:
|
59
|
+
cipher_key: "super_secret",
|
63
60
|
count: 1,
|
64
|
-
http_sync: true
|
61
|
+
http_sync: true,
|
65
62
|
)
|
66
63
|
|
67
64
|
@pubnub.publish(
|
68
65
|
channel: :multiple_cipher_test,
|
69
|
-
message:
|
70
|
-
cipher_key:
|
71
|
-
http_sync: true
|
66
|
+
message: "Another test message",
|
67
|
+
cipher_key: "another_secret",
|
68
|
+
http_sync: true,
|
72
69
|
)
|
73
70
|
|
74
71
|
e1 = @pubnub.history(
|
75
72
|
channel: :multiple_cipher_test,
|
76
|
-
cipher_key:
|
73
|
+
cipher_key: "another_secret",
|
77
74
|
count: 1,
|
78
|
-
http_sync: true
|
75
|
+
http_sync: true,
|
79
76
|
)
|
80
77
|
|
81
|
-
expect(e0.result[:data][:messages].first).to eq
|
82
|
-
expect(e1.result[:data][:messages].first).to eq
|
78
|
+
expect(e0.result[:data][:messages].first).to eq "Some test message"
|
79
|
+
expect(e1.result[:data][:messages].first).to eq "Another test message"
|
83
80
|
end
|
84
81
|
end
|
85
82
|
|
86
|
-
it
|
87
|
-
@pubnub = Pubnub.new(subscribe_key: :demo, publish_key: :demo, cipher_key:
|
83
|
+
it "works with async history" do
|
84
|
+
@pubnub = Pubnub.new(subscribe_key: :demo, publish_key: :demo, cipher_key: "this_doesnt_fit_anywhere")
|
88
85
|
|
89
|
-
VCR.use_cassette(
|
86
|
+
VCR.use_cassette("lib/multiple_ciphers_history", record: :once) do
|
90
87
|
@pubnub.publish(
|
91
88
|
channel: :multiple_cipher_test,
|
92
|
-
message:
|
93
|
-
cipher_key:
|
94
|
-
http_sync: true
|
89
|
+
message: "Some test message",
|
90
|
+
cipher_key: "super_secret",
|
91
|
+
http_sync: true,
|
95
92
|
)
|
96
93
|
|
97
94
|
e0 = @pubnub.history(
|
98
95
|
channel: :multiple_cipher_test,
|
99
|
-
cipher_key:
|
100
|
-
count: 1
|
96
|
+
cipher_key: "super_secret",
|
97
|
+
count: 1,
|
101
98
|
).value
|
102
99
|
|
103
100
|
@pubnub.publish(
|
104
101
|
channel: :multiple_cipher_test,
|
105
|
-
message:
|
106
|
-
cipher_key:
|
107
|
-
http_sync: true
|
102
|
+
message: "Another test message",
|
103
|
+
cipher_key: "another_secret",
|
104
|
+
http_sync: true,
|
108
105
|
)
|
109
106
|
|
110
107
|
e1 = @pubnub.history(
|
111
108
|
channel: :multiple_cipher_test,
|
112
|
-
cipher_key:
|
113
|
-
count: 1
|
109
|
+
cipher_key: "another_secret",
|
110
|
+
count: 1,
|
114
111
|
).value
|
115
112
|
|
116
|
-
expect(e0.result[:data][:messages].first).to eq
|
117
|
-
expect(e1.result[:data][:messages].first).to eq
|
113
|
+
expect(e0.result[:data][:messages].first).to eq "Some test message"
|
114
|
+
expect(e1.result[:data][:messages].first).to eq "Another test message"
|
118
115
|
end
|
119
116
|
end
|
120
|
-
|
121
|
-
it
|
117
|
+
|
118
|
+
it "works with asynchronous subscribe and callable cipher key argument" do
|
122
119
|
@message = nil
|
123
120
|
cb = Pubnub::SubscribeCallback.new(
|
124
|
-
message: ->(envelope){ @message = envelope.result[:data][:message] }
|
121
|
+
message: -> (envelope) { @message = envelope.result[:data][:message] },
|
125
122
|
)
|
126
123
|
|
127
124
|
ciphers = {
|
128
|
-
|
125
|
+
"some-uuid" => "secret",
|
129
126
|
}
|
130
127
|
|
131
|
-
lambda_cipher_key = ->(data) do
|
128
|
+
lambda_cipher_key = -> (data) do
|
132
129
|
ciphers[data[:issuing_client_id]]
|
133
130
|
end
|
134
131
|
|
135
132
|
@pubnub = Pubnub.new(subscribe_key: :demo, publish_key: :demo, cipher_key_selector: lambda_cipher_key)
|
136
133
|
@pubnub.add_listener(callback: cb)
|
137
134
|
|
138
|
-
VCR.use_cassette(
|
135
|
+
VCR.use_cassette("lib/callable_cipher_key", record: :once) do
|
139
136
|
@pubnub.subscribe(channel: :multiple_cipher_test)
|
140
137
|
sleep(1)
|
141
|
-
expect(@message).to eq(
|
138
|
+
expect(@message).to eq("hello ruby!")
|
142
139
|
end
|
143
140
|
end
|
144
|
-
|
145
|
-
end
|
141
|
+
end
|
data/spec/lib/pubnub_spec.rb
CHANGED
@@ -1,28 +1,25 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub do
|
4
|
-
|
5
4
|
around :each do |example|
|
6
|
-
|
7
|
-
example.run
|
8
|
-
Celluloid.shutdown
|
5
|
+
example.run_with_retry retry: 10
|
9
6
|
end
|
10
7
|
|
11
|
-
context
|
12
|
-
it
|
8
|
+
context "version" do
|
9
|
+
it "has VERSION" do
|
13
10
|
expect(Pubnub::VERSION).to match(/\d+\.\d+\..+/)
|
14
11
|
end
|
15
12
|
end
|
16
13
|
|
17
|
-
context
|
18
|
-
it
|
19
|
-
logger = Logger.new(
|
20
|
-
_pubnub = Pubnub.new(subscribe_key:
|
14
|
+
context "logger" do
|
15
|
+
it "is settable" do
|
16
|
+
logger = Logger.new("pubnub.log")
|
17
|
+
_pubnub = Pubnub.new(subscribe_key: "valid", logger: logger)
|
21
18
|
expect(Pubnub.logger).to be logger
|
22
19
|
end
|
23
20
|
|
24
|
-
it
|
25
|
-
_pubnub = Pubnub.new(subscribe_key:
|
21
|
+
it "is set by default if not provided" do
|
22
|
+
_pubnub = Pubnub.new(subscribe_key: "valid")
|
26
23
|
expect(Pubnub.logger.class).to be Logger
|
27
24
|
end
|
28
25
|
end
|
data/spec/lib/signatures_spec.rb
CHANGED
@@ -1,206 +1,204 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe 'Signatures' do
|
1
|
+
require "spec_helper"
|
4
2
|
|
3
|
+
describe "Signatures" do
|
5
4
|
around :each do |example|
|
6
|
-
|
7
|
-
example.run
|
8
|
-
Celluloid.shutdown
|
5
|
+
example.run_with_retry retry: 10
|
9
6
|
end
|
10
7
|
|
11
|
-
it
|
12
|
-
stub_const(
|
8
|
+
it "works all letters channel" do
|
9
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
13
10
|
Pubnub::Grant.any_instance.stub(:current_time).and_return(1496242823)
|
14
11
|
|
15
12
|
pubnub = Pubnub.new(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
14
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
15
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
16
|
+
uuid: "test",
|
20
17
|
)
|
21
18
|
|
22
|
-
VCR.use_cassette(
|
23
|
-
envelope = pubnub.grant(channel:
|
19
|
+
VCR.use_cassette("lib/signatures/all-letters", record: :once) do
|
20
|
+
envelope = pubnub.grant(channel: "demo", http_sync: true)
|
24
21
|
expect(envelope.status[:code]).to eq 200
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
it
|
29
|
-
stub_const(
|
25
|
+
it "works with wildcard" do
|
26
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
30
27
|
Pubnub::Grant.any_instance.stub(:current_time).and_return(1496242823)
|
31
28
|
|
32
29
|
pubnub = Pubnub.new(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
31
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
32
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
33
|
+
uuid: "test",
|
37
34
|
)
|
38
35
|
|
39
|
-
VCR.use_cassette(
|
40
|
-
envelope = pubnub.grant(channel:
|
36
|
+
VCR.use_cassette("lib/signatures/wildcard", record: :once) do
|
37
|
+
envelope = pubnub.grant(channel: "demo.*", http_sync: true)
|
41
38
|
expect(envelope.status[:code]).to eq 200
|
42
39
|
end
|
43
40
|
end
|
44
41
|
|
45
|
-
context
|
46
|
-
it
|
47
|
-
stub_const(
|
42
|
+
context "with various special characters" do
|
43
|
+
it "grant works" do
|
44
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
48
45
|
Pubnub::Grant.any_instance.stub(:current_time).and_return(1496242824)
|
49
46
|
|
50
47
|
pubnub = Pubnub.new(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
49
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
50
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
51
|
+
uuid: "test",
|
55
52
|
)
|
56
53
|
|
57
|
-
VCR.use_cassette(
|
54
|
+
VCR.use_cassette("lib/signatures/special", record: :once) do
|
58
55
|
envelope = pubnub.grant(channel: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z', http_sync: true)
|
59
56
|
expect(envelope.status[:code]).to eq 200
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
|
-
it
|
64
|
-
stub_const(
|
60
|
+
it "publish works" do
|
61
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
65
62
|
Pubnub::Publish.any_instance.stub(:current_time).and_return 1496396127
|
66
63
|
Pubnub::Client.any_instance.stub(:generate_ortt).and_return 14963961271418600
|
67
64
|
|
68
65
|
pubnub = Pubnub.new(
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
67
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
68
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
69
|
+
uuid: "test",
|
73
70
|
)
|
74
71
|
|
75
|
-
VCR.use_cassette(
|
72
|
+
VCR.use_cassette("lib/signatures/publish", record: :once) do
|
76
73
|
envelope = pubnub.publish(channel: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z', message: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z', http_sync: true)
|
77
74
|
expect(envelope.status[:code]).to eq 200
|
78
75
|
end
|
79
76
|
end
|
80
77
|
|
81
|
-
it
|
82
|
-
stub_const(
|
78
|
+
it "subscribe works" do
|
79
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
83
80
|
Pubnub::Subscribe.any_instance.stub(:current_time).and_return 1496397558
|
84
81
|
|
85
82
|
pubnub = Pubnub.new(
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
83
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
84
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
85
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
86
|
+
uuid: "test",
|
90
87
|
)
|
91
88
|
|
92
|
-
VCR.use_cassette(
|
89
|
+
VCR.use_cassette("lib/signatures/subscribe", record: :once) do
|
93
90
|
envelope = pubnub.subscribe(channel: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z', http_sync: true)
|
94
91
|
expect(envelope.first.status[:code]).to eq 200
|
95
92
|
end
|
96
93
|
end
|
97
94
|
|
98
|
-
it
|
99
|
-
stub_const(
|
95
|
+
it "presence works" do
|
96
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
100
97
|
Pubnub::Presence.any_instance.stub(:current_time).and_return 1496401532
|
101
98
|
|
102
99
|
pubnub = Pubnub.new(
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
100
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
101
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
102
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
103
|
+
uuid: "test",
|
107
104
|
)
|
108
105
|
|
109
|
-
VCR.use_cassette(
|
106
|
+
VCR.use_cassette("lib/signatures/presence", record: :once) do
|
110
107
|
envelope = pubnub.presence(channel: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z', http_sync: true)
|
111
108
|
expect(envelope.first.status[:code]).to eq 200
|
112
109
|
end
|
113
110
|
end
|
114
111
|
|
115
|
-
it
|
116
|
-
stub_const(
|
112
|
+
it "leave works" do
|
113
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
117
114
|
Pubnub::Leave.any_instance.stub(:current_time).and_return 1496401409
|
118
115
|
|
119
116
|
pubnub = Pubnub.new(
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
117
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
118
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
119
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
120
|
+
uuid: "test",
|
124
121
|
)
|
125
122
|
|
126
|
-
VCR.use_cassette(
|
123
|
+
VCR.use_cassette("lib/signatures/leave", record: :once) do
|
127
124
|
envelope = pubnub.leave(channel: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z', http_sync: true)
|
128
125
|
expect(envelope.status[:code]).to eq 200
|
129
126
|
end
|
130
127
|
end
|
131
128
|
|
132
|
-
it
|
133
|
-
stub_const(
|
129
|
+
it "history works" do
|
130
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
134
131
|
Pubnub::History.any_instance.stub(:current_time).and_return 1496396745
|
135
132
|
|
136
133
|
pubnub = Pubnub.new(
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
134
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
135
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
136
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
137
|
+
uuid: "test",
|
141
138
|
)
|
142
139
|
|
143
|
-
VCR.use_cassette(
|
140
|
+
VCR.use_cassette("lib/signatures/history", record: :once) do
|
144
141
|
envelope = pubnub.history(channel: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z', http_sync: true)
|
145
142
|
expect(envelope.status[:code]).to eq 200
|
146
143
|
end
|
147
144
|
end
|
148
145
|
|
149
|
-
it
|
150
|
-
stub_const(
|
146
|
+
it "here-now works" do
|
147
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
151
148
|
Pubnub::HereNow.any_instance.stub(:current_time).and_return 1496401140
|
152
149
|
|
153
150
|
pubnub = Pubnub.new(
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
151
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
152
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
153
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
154
|
+
uuid: "test",
|
158
155
|
)
|
159
156
|
|
160
|
-
VCR.use_cassette(
|
157
|
+
VCR.use_cassette("lib/signatures/here_now", record: :once) do
|
161
158
|
envelope = pubnub.here_now(channel: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z', http_sync: true)
|
162
159
|
expect(envelope.status[:code]).to eq 200
|
163
160
|
end
|
164
161
|
end
|
165
162
|
|
166
|
-
it
|
167
|
-
stub_const(
|
163
|
+
it "channel registration works" do
|
164
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
168
165
|
pubnub = Pubnub.new(
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
166
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
167
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
168
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
169
|
+
uuid: "test",
|
173
170
|
)
|
171
|
+
pubnub.env[:no_telemetry] = true
|
174
172
|
|
175
|
-
VCR.use_cassette(
|
173
|
+
VCR.use_cassette("lib/signatures/channel_registration", record: :once) do
|
176
174
|
Pubnub::ChannelRegistration.any_instance.stub(:current_time).and_return 1496400706
|
177
175
|
envelope0 = pubnub.channel_registration(
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
176
|
+
action: :add,
|
177
|
+
channel: 'a!@#$%^&()ŻÓŁ[]{}""<>??~`Z',
|
178
|
+
channel_group: 'a!@#$%^&()ŻÓŁ[]{}""<>??~`Z',
|
179
|
+
http_sync: true,
|
182
180
|
)
|
183
181
|
|
184
182
|
Pubnub::ChannelRegistration.any_instance.stub(:current_time).and_return 1496400706
|
185
183
|
envelope1 = pubnub.channel_registration(
|
186
|
-
|
187
|
-
|
188
|
-
|
184
|
+
action: :get,
|
185
|
+
channel_group: 'a!@#$%^&()ŻÓŁ[]{}""<>??~`Z',
|
186
|
+
http_sync: true,
|
189
187
|
)
|
190
188
|
|
191
189
|
Pubnub::ChannelRegistration.any_instance.stub(:current_time).and_return 1496400706
|
192
190
|
envelope2 = pubnub.channel_registration(
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
191
|
+
action: :remove,
|
192
|
+
channel: 'a!@#$%^&()ŻÓŁ[]{}""<>??~`Z',
|
193
|
+
channel_group: 'a!@#$%^&()ŻÓŁ[]{}""<>??~`Z',
|
194
|
+
http_sync: true,
|
197
195
|
)
|
198
196
|
|
199
197
|
Pubnub::ChannelRegistration.any_instance.stub(:current_time).and_return 1496400706
|
200
198
|
envelope3 = pubnub.channel_registration(
|
201
|
-
|
202
|
-
|
203
|
-
|
199
|
+
action: :remove,
|
200
|
+
channel_group: 'a!@#$%^&()ŻÓŁ[]{}""<>??~`Z',
|
201
|
+
http_sync: true,
|
204
202
|
)
|
205
203
|
|
206
204
|
expect(envelope0.status[:code]).to eq 200
|
@@ -210,40 +208,40 @@ describe 'Signatures' do
|
|
210
208
|
end
|
211
209
|
end
|
212
210
|
|
213
|
-
it
|
214
|
-
stub_const(
|
211
|
+
it "heartbeat works" do
|
212
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
215
213
|
Pubnub::Heartbeat.any_instance.stub(:current_time).and_return 1496400995
|
216
214
|
|
217
215
|
pubnub = Pubnub.new(
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
216
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
217
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
218
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
219
|
+
uuid: "test",
|
222
220
|
)
|
223
221
|
|
224
|
-
VCR.use_cassette(
|
222
|
+
VCR.use_cassette("lib/signatures/heartbeat", record: :once) do
|
225
223
|
envelope = pubnub.heartbeat(channel: 'a!@#$%^&()ŻÓŁ[]{}""<>??~`Z', heartbeat: 10, http_sync: true)
|
226
224
|
expect(envelope.status[:code]).to eq 200
|
227
225
|
end
|
228
226
|
end
|
229
227
|
|
230
|
-
it
|
231
|
-
stub_const(
|
228
|
+
it "state works" do
|
229
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
232
230
|
Pubnub::SetState.any_instance.stub(:current_time).and_return 1496402248
|
233
231
|
Pubnub::State.any_instance.stub(:current_time).and_return 1496402248
|
234
|
-
|
235
232
|
pubnub = Pubnub.new(
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
233
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
234
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
235
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
236
|
+
uuid: 'a!@#$%^&()ŻÓŁ[]{}""<>??~`Z',
|
240
237
|
)
|
238
|
+
pubnub.env[:no_telemetry] = true
|
241
239
|
|
242
|
-
VCR.use_cassette(
|
240
|
+
VCR.use_cassette("lib/signatures/state", record: :once) do
|
243
241
|
envelope = pubnub.set_state(
|
244
|
-
|
245
|
-
|
246
|
-
|
242
|
+
channel: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z',
|
243
|
+
state: {something: 'a!@#$%^&*()ŻÓŁ[]{}""<>??~`Z'},
|
244
|
+
http_sync: true,
|
247
245
|
)
|
248
246
|
|
249
247
|
expect(envelope.status[:code]).to eq 200
|
@@ -253,21 +251,21 @@ describe 'Signatures' do
|
|
253
251
|
end
|
254
252
|
end
|
255
253
|
|
256
|
-
it
|
257
|
-
stub_const(
|
254
|
+
it "where now works" do
|
255
|
+
stub_const("Pubnub::VERSION", "4.0.21")
|
258
256
|
Pubnub::WhereNow.any_instance.stub(:current_time).and_return 1496402114
|
259
257
|
|
260
258
|
pubnub = Pubnub.new(
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
259
|
+
subscribe_key: "sub-c-b6df3d38-45e3-11e7-86e2-02ee2ddab7fe",
|
260
|
+
publish_key: "pub-c-cd48c41a-afce-4f37-8b3b-7fafccf52e2d",
|
261
|
+
secret_key: "sec-c-OTMzNmViNGEtYjg0MS00ZTZkLWI5ZmMtNDYzMDA0NTBlMDdi",
|
262
|
+
uuid: "test",
|
265
263
|
)
|
266
264
|
|
267
|
-
VCR.use_cassette(
|
265
|
+
VCR.use_cassette("lib/signatures/where_now", record: :once) do
|
268
266
|
envelope = pubnub.where_now(
|
269
|
-
|
270
|
-
|
267
|
+
uuid: 'a!@#$%^&()ŻÓŁ[]{}""<>??~`Z',
|
268
|
+
http_sync: true,
|
271
269
|
)
|
272
270
|
|
273
271
|
expect(envelope.status[:code]).to eq 200
|