pubnub 3.5.8 → 3.5.12
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/.gitignore +1 -0
- data/CHANGELOG +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -3
- data/VERSION +1 -1
- data/examples/chaos/tmp/pids/passenger.3000.pid.lock +0 -0
- data/fixtures/vcr_cassettes/eof_subscribe.yml +85 -0
- data/fixtures/vcr_cassettes/grant-multiple-channels.yml +45 -0
- data/fixtures/vcr_cassettes/heartbeat-non200.yml +173 -25
- data/lib/pubnub/client.rb +4 -0
- data/lib/pubnub/event.rb +50 -29
- data/lib/pubnub/events/grant.rb +1 -1
- data/lib/pubnub/events/publish.rb +1 -0
- data/lib/pubnub/events/revoke.rb +1 -1
- data/lib/pubnub/pam.rb +2 -2
- data/lib/pubnub/version.rb +1 -1
- data/pubnub.gemspec +2 -2
- data/spec/lib/eof_error_spec.rb +48 -0
- data/spec/lib/integration/audit_dpc_spec.rb +544 -0
- data/spec/lib/integration/global_here_now_dpc_spec.rb +541 -0
- data/spec/lib/integration/grant_dpc_spec.rb +555 -0
- data/spec/lib/integration/grant_spec.rb +25 -0
- data/spec/lib/integration/here_now_dpc_spec.rb +543 -0
- data/spec/lib/integration/history_dpc_spec.rb +541 -0
- data/spec/lib/integration/leave_dpc_spec.rb +540 -0
- data/spec/lib/integration/presence_dpc_spec.rb +557 -0
- data/spec/lib/integration/publish_dpc_spec.rb +1877 -0
- data/spec/lib/integration/revoke_dpc_spec.rb +555 -0
- data/spec/lib/integration/subscribe_dpc_spec.rb +564 -0
- data/spec/lib/integration/time_dpc_spec.rb +541 -0
- data/spec/lib/integration/v3_presence_dpc_spec.rb +557 -0
- metadata +18 -2
data/lib/pubnub/client.rb
CHANGED
data/lib/pubnub/event.rb
CHANGED
@@ -5,18 +5,18 @@ module Pubnub
|
|
5
5
|
|
6
6
|
def initialize(options, app)
|
7
7
|
@app = app
|
8
|
-
@origin = options[:origin]
|
8
|
+
@origin = options[:origin] || app.env[:origin]
|
9
9
|
@channel = options[:channel]
|
10
10
|
@message = options[:message]
|
11
11
|
@http_sync = options[:http_sync]
|
12
12
|
@callback = options[:callback]
|
13
|
-
@error_callback = options[:error_callback]
|
14
|
-
@connect_callback = options[:
|
15
|
-
@ssl = options[:ssl]
|
13
|
+
@error_callback = options[:error_callback] || app.env[:error_callback]
|
14
|
+
@connect_callback = options[:connect_callback] || app.env[:connect_callback]
|
15
|
+
@ssl = options[:ssl] || app.env[:ssl]
|
16
16
|
|
17
17
|
@cipher_key = app.env[:cipher_key]
|
18
18
|
@secret_key = app.env[:secret_key]
|
19
|
-
@auth_key = options[:auth_key]
|
19
|
+
@auth_key = options[:auth_key] || app.env[:auth_key]
|
20
20
|
@publish_key = app.env[:publish_key]
|
21
21
|
@subscribe_key = app.env[:subscribe_key]
|
22
22
|
|
@@ -36,12 +36,20 @@ module Pubnub
|
|
36
36
|
envelopes = start_event(app)
|
37
37
|
end
|
38
38
|
|
39
|
+
def send_request(app)
|
40
|
+
if app.disabled_persistent_connection?
|
41
|
+
@response = Net::HTTP.get_response uri(app)
|
42
|
+
else
|
43
|
+
@response = get_connection(app).request(uri(app))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
39
47
|
def start_event(app, count = 0)
|
40
48
|
begin
|
41
49
|
if count <= app.env[:max_retries]
|
42
50
|
$logger.debug('Pubnub'){'Event#start_event | sending request'}
|
43
51
|
$logger.debug('Pubnub'){"Event#start_event | tt: #{@timetoken}; ctt #{app.env[:timetoken]}"}
|
44
|
-
@response =
|
52
|
+
@response = send_request(app)
|
45
53
|
end
|
46
54
|
|
47
55
|
error = response_error(@response, app)
|
@@ -52,9 +60,13 @@ module Pubnub
|
|
52
60
|
start_event(app, count + 1)
|
53
61
|
end
|
54
62
|
rescue => e
|
55
|
-
$logger.error('Pubnub'){e}
|
56
63
|
$logger.error('Pubnub'){e.inspect}
|
57
|
-
|
64
|
+
if count <= app.env[:max_retries]
|
65
|
+
start_event(app, count + 1)
|
66
|
+
else
|
67
|
+
$logger.error('Pubnub'){"Aborting #{self.class} event due to network errors and reaching max retries"}
|
68
|
+
end
|
69
|
+
false
|
58
70
|
end
|
59
71
|
end
|
60
72
|
|
@@ -103,15 +115,18 @@ module Pubnub
|
|
103
115
|
end
|
104
116
|
|
105
117
|
def fire_callbacks(envelopes, app)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
118
|
+
unless envelopes.blank?
|
119
|
+
$logger.debug('Pubnub'){'Firing callbacks'}
|
120
|
+
envelopes.each do |envelope|
|
121
|
+
@callback.call(envelope) if !envelope.error && @callback && !envelope.timetoken_update
|
122
|
+
#if envelope.timetoken_update || envelope.timetoken.to_i > app.env[:timetoken].to_i
|
123
|
+
# update_timetoken(app, envelope.timetoken)
|
124
|
+
#end
|
125
|
+
end
|
126
|
+
@error_callback.call(envelopes.first) if envelopes.first.error
|
127
|
+
else
|
128
|
+
$logger.debug('Pubnub'){'No envelopes for callback'}
|
112
129
|
end
|
113
|
-
@error_callback.call(envelopes.first) if envelopes.first.error
|
114
|
-
|
115
130
|
end
|
116
131
|
|
117
132
|
def update_timetoken(app, timetoken)
|
@@ -129,8 +144,8 @@ module Pubnub
|
|
129
144
|
envelope.status = response.code.to_i
|
130
145
|
end
|
131
146
|
|
132
|
-
envelopes.last.last = true
|
133
|
-
envelopes.first.first = true
|
147
|
+
envelopes.last.last = true if envelopes.last
|
148
|
+
envelopes.first.first = true if envelopes.first
|
134
149
|
|
135
150
|
envelopes = insert_errors(envelopes, error, app) if error
|
136
151
|
|
@@ -244,11 +259,14 @@ module Pubnub
|
|
244
259
|
end
|
245
260
|
|
246
261
|
def new_connection(app)
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
262
|
+
unless app.disabled_persistent_connection?
|
263
|
+
connection = Net::HTTP::Persistent.new "pubnub_ruby_client_v#{Pubnub::VERSION}"
|
264
|
+
connection.idle_timeout = app.env[:subscribe_timeout]
|
265
|
+
connection.read_timeout = app.env[:subscribe_timeout]
|
266
|
+
@connect_callback.call "New connection to #{@origin}"
|
267
|
+
connection.proxy_from_env
|
268
|
+
connection
|
269
|
+
end
|
252
270
|
end
|
253
271
|
end
|
254
272
|
|
@@ -498,12 +516,15 @@ module Pubnub
|
|
498
516
|
end
|
499
517
|
|
500
518
|
def new_connection(app)
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
519
|
+
unless app.disabled_persistent_connection?
|
520
|
+
connection = Net::HTTP::Persistent.new "pubnub_ruby_client_v#{Pubnub::VERSION}"
|
521
|
+
connection.idle_timeout = app.env[:subscribe_timeout]
|
522
|
+
connection.read_timeout = app.env[:subscribe_timeout]
|
523
|
+
@connect_callback.call "New connection to #{@origin}"
|
524
|
+
connection.proxy_from_env
|
525
|
+
connection
|
526
|
+
end
|
527
|
+
|
507
528
|
end
|
508
529
|
end
|
509
530
|
end
|
data/lib/pubnub/events/grant.rb
CHANGED
@@ -12,6 +12,7 @@ module Pubnub
|
|
12
12
|
@event = 'publish'
|
13
13
|
@allow_multiple_channels = false
|
14
14
|
|
15
|
+
raise ArgumentError.new(:object => self, :message => ':message argument is too big, encoded uri would excess 32k size limit') if uri(app).to_s.bytesize > 32000
|
15
16
|
end
|
16
17
|
|
17
18
|
def validate!
|
data/lib/pubnub/events/revoke.rb
CHANGED
data/lib/pubnub/pam.rb
CHANGED
@@ -19,14 +19,14 @@ module Pubnub
|
|
19
19
|
parsed_response['message'] if parsed_response
|
20
20
|
end
|
21
21
|
|
22
|
-
def channel(
|
22
|
+
def channel(_parsed_response)
|
23
23
|
@channel.first
|
24
24
|
end
|
25
25
|
|
26
26
|
def parameters(app, signature = false)
|
27
27
|
params = super(app)
|
28
28
|
params.merge!({ :timestamp => @timestamp })
|
29
|
-
params.merge!({ :channel => @channel.
|
29
|
+
params.merge!({ :channel => @channel.join(',') }) unless @channel.first.blank?
|
30
30
|
params.merge!({ :signature => signature(app) }) unless signature
|
31
31
|
params
|
32
32
|
end
|
data/lib/pubnub/version.rb
CHANGED
data/pubnub.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'pubnub'
|
5
|
-
s.version = '3.5.
|
5
|
+
s.version = '3.5.12'
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ['PubNub']
|
9
|
-
s.date = '2014-
|
9
|
+
s.date = '2014-10-08'
|
10
10
|
s.description = 'Ruby anywhere in the world in 250ms with PubNub!'
|
11
11
|
s.email = 'support@pubnub.com'
|
12
12
|
s.files = `git ls-files`.split("\n")
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'quick eof error test' do
|
4
|
+
before(:each) do
|
5
|
+
|
6
|
+
EM.stop if EM.reactor_running?
|
7
|
+
while EM.reactor_running? do end
|
8
|
+
sleep(0.1)
|
9
|
+
|
10
|
+
@response_output = StringIO.new
|
11
|
+
@message_output = StringIO.new
|
12
|
+
|
13
|
+
@callback = lambda { |envelope|
|
14
|
+
$logger.debug 'FIRING CALLBACK FROM TEST'
|
15
|
+
@response_output.write envelope.response
|
16
|
+
@message_output.write envelope.msg
|
17
|
+
@after_callback = true
|
18
|
+
}
|
19
|
+
|
20
|
+
@error_callback = lambda { |envelope|
|
21
|
+
$logger.debug 'FIRING ERROR CALLBACK FROM TEST'
|
22
|
+
@response_output.write envelope.response
|
23
|
+
@message_output.write envelope.msg
|
24
|
+
@after_error_callback = true
|
25
|
+
}
|
26
|
+
|
27
|
+
@pn = nil
|
28
|
+
@pn = Pubnub.new(:max_retries => 1, :subscribe_key => :demo, :publish_key => :demo, :auth_key => :demoish_authkey, :secret_key => 'some_secret_key', :error_callback => @error_callback)
|
29
|
+
@pn.uuid = 'rubytests'
|
30
|
+
|
31
|
+
Pubnub::Subscribe.any_instance.stub(:send_request){
|
32
|
+
Pubnub::Subscribe.any_instance.unstub(:send_request)
|
33
|
+
raise EOFError
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not break client' do
|
38
|
+
VCR.use_cassette('eof_subscribe', :record => :none) do
|
39
|
+
@pn.subscribe(:channel => 'ping_3', &@callback)
|
40
|
+
eventually do
|
41
|
+
@after_callback.should eq true
|
42
|
+
@response_output.seek 0
|
43
|
+
@response_output.read.should eq '[["ping_3.php says 1403984741"],"14039847413557067"]'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,544 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#audit" do
|
4
|
+
before(:each) do
|
5
|
+
|
6
|
+
EM.stop if EM.reactor_running?
|
7
|
+
while EM.reactor_running? do end
|
8
|
+
sleep(0.1)
|
9
|
+
|
10
|
+
@response_output = StringIO.new
|
11
|
+
@message_output = StringIO.new
|
12
|
+
|
13
|
+
@callback = lambda { |envelope|
|
14
|
+
$logger.debug 'FIRING CALLBACK FROM TEST'
|
15
|
+
@response_output.write envelope.response
|
16
|
+
@message_output.write envelope.msg
|
17
|
+
@after_callback = true
|
18
|
+
}
|
19
|
+
|
20
|
+
@error_callback = lambda { |envelope|
|
21
|
+
$logger.debug 'FIRING ERROR CALLBACK FROM TEST'
|
22
|
+
@response_output.write envelope.response
|
23
|
+
@message_output.write envelope.msg
|
24
|
+
@after_error_callback = true
|
25
|
+
}
|
26
|
+
|
27
|
+
@pn = Pubnub.new(:disable_persistent_connection => true, :max_retries => 0, :subscribe_key => 'sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe', :publish_key => 'pub-c-15d6fd3c-05de-4abc-8eba-6595a441959d', :secret_key => 'sec-c-ZWYwMGJiZTYtMTQwMC00NDQ5LWI0NmEtMzZiM2M5NThlOTJh', :error_callback => @error_callback)
|
28
|
+
@pn.uuid = 'f0ac67ef-912f-4797-be67-a59745107306'
|
29
|
+
|
30
|
+
Pubnub::Audit.any_instance.stub(:current_time).and_return 1234567890
|
31
|
+
Pubnub::Audit.any_instance.stub(:signature).and_return 'kdDh/sFC3rSR%2Bt5AEymIc57d1velIr562V7usa5M4k0='
|
32
|
+
|
33
|
+
end
|
34
|
+
context "uses ssl" do
|
35
|
+
before(:each) { @ssl = true }
|
36
|
+
context "passess callback as block" do
|
37
|
+
context "gets valid json in response" do
|
38
|
+
context "gets status 200 in response" do
|
39
|
+
context "uses sync connection" do
|
40
|
+
it 'works fine' do
|
41
|
+
VCR.use_cassette("audit-ssl-block-valid-200-sync", :record => :none) do
|
42
|
+
@pn.audit(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", &@callback)
|
43
|
+
|
44
|
+
@after_callback.should eq true
|
45
|
+
@response_output.seek 0
|
46
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
47
|
+
@message_output.seek 0
|
48
|
+
@message_output.read.should eq 'Success'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
context "uses async connection" do
|
53
|
+
it 'works fine' do
|
54
|
+
VCR.use_cassette("audit-ssl-block-valid-200-async", :record => :none) do
|
55
|
+
@pn.audit(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", &@callback)
|
56
|
+
|
57
|
+
eventually do
|
58
|
+
@after_callback.should eq true
|
59
|
+
@response_output.seek 0
|
60
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
61
|
+
@message_output.seek 0
|
62
|
+
@message_output.read.should eq 'Success'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
context "gets status non-200 in response" do
|
69
|
+
context "uses sync connection" do
|
70
|
+
it 'works fine' do
|
71
|
+
VCR.use_cassette("audit-ssl-block-valid-non-200-sync", :record => :none) do
|
72
|
+
@pn.audit(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", &@callback)
|
73
|
+
|
74
|
+
@after_error_callback.should eq true
|
75
|
+
@response_output.seek 0
|
76
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
77
|
+
@message_output.seek 0
|
78
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context "uses async connection" do
|
83
|
+
it 'works fine' do
|
84
|
+
VCR.use_cassette("audit-ssl-block-valid-non-200-async", :record => :none) do
|
85
|
+
@pn.audit(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", &@callback)
|
86
|
+
|
87
|
+
eventually do
|
88
|
+
@after_error_callback.should eq true
|
89
|
+
@response_output.seek 0
|
90
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
91
|
+
@message_output.seek 0
|
92
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
context "gets invalid json in response" do
|
100
|
+
context "gets status 200 in response" do
|
101
|
+
context "uses sync connection" do
|
102
|
+
it 'works fine' do
|
103
|
+
VCR.use_cassette("audit-ssl-block-invalid-200-sync", :record => :none) do
|
104
|
+
@pn.audit(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", &@callback)
|
105
|
+
|
106
|
+
@after_error_callback.should eq true
|
107
|
+
@response_output.seek 0
|
108
|
+
@response_output.read.should eq '{"status":200,'
|
109
|
+
@message_output.seek 0
|
110
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
context "uses async connection" do
|
115
|
+
it 'works fine' do
|
116
|
+
VCR.use_cassette("audit-ssl-block-invalid-200-async", :record => :none) do
|
117
|
+
@pn.audit(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", &@callback)
|
118
|
+
|
119
|
+
eventually do
|
120
|
+
@after_error_callback.should eq true
|
121
|
+
@response_output.seek 0
|
122
|
+
@response_output.read.should eq '{"status":200,'
|
123
|
+
@message_output.seek 0
|
124
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
context "gets status non-200 in response" do
|
131
|
+
context "uses sync connection" do
|
132
|
+
it 'works fine' do
|
133
|
+
VCR.use_cassette("audit-ssl-block-invalid-non-200-sync", :record => :none) do
|
134
|
+
@pn.audit(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", &@callback)
|
135
|
+
|
136
|
+
@after_error_callback.should eq true
|
137
|
+
@response_output.seek 0
|
138
|
+
@response_output.read.should eq '{"status":200,'
|
139
|
+
@message_output.seek 0
|
140
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
context "uses async connection" do
|
145
|
+
it 'works fine' do
|
146
|
+
VCR.use_cassette("audit-ssl-block-invalid-non-200-async", :record => :none) do
|
147
|
+
@pn.audit(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", &@callback)
|
148
|
+
|
149
|
+
eventually do
|
150
|
+
@after_error_callback.should eq true
|
151
|
+
@response_output.seek 0
|
152
|
+
@response_output.read.should eq '{"status":200,'
|
153
|
+
@message_output.seek 0
|
154
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
context "passess callback as parameter" do
|
163
|
+
context "gets valid json in response" do
|
164
|
+
context "gets status 200 in response" do
|
165
|
+
context "uses sync connection" do
|
166
|
+
it 'works fine' do
|
167
|
+
VCR.use_cassette("audit-ssl-parameter-valid-200-sync", :record => :none) do
|
168
|
+
@pn.audit(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
169
|
+
|
170
|
+
@after_callback.should eq true
|
171
|
+
@response_output.seek 0
|
172
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
173
|
+
@message_output.seek 0
|
174
|
+
@message_output.read.should eq 'Success'
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
context "uses async connection" do
|
179
|
+
it 'works fine' do
|
180
|
+
VCR.use_cassette("audit-ssl-parameter-valid-200-async", :record => :none) do
|
181
|
+
@pn.audit(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
182
|
+
|
183
|
+
eventually do
|
184
|
+
@after_callback.should eq true
|
185
|
+
@response_output.seek 0
|
186
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
187
|
+
@message_output.seek 0
|
188
|
+
@message_output.read.should eq 'Success'
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
context "gets status non-200 in response" do
|
195
|
+
context "uses sync connection" do
|
196
|
+
it 'works fine' do
|
197
|
+
VCR.use_cassette("audit-ssl-parameter-valid-non-200-sync", :record => :none) do
|
198
|
+
@pn.audit(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
199
|
+
|
200
|
+
@after_error_callback.should eq true
|
201
|
+
@response_output.seek 0
|
202
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
203
|
+
@message_output.seek 0
|
204
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
context "uses async connection" do
|
209
|
+
it 'works fine' do
|
210
|
+
VCR.use_cassette("audit-ssl-parameter-valid-non-200-async", :record => :none) do
|
211
|
+
@pn.audit(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
212
|
+
|
213
|
+
eventually do
|
214
|
+
@after_error_callback.should eq true
|
215
|
+
@response_output.seek 0
|
216
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
217
|
+
@message_output.seek 0
|
218
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
context "gets invalid json in response" do
|
226
|
+
context "gets status 200 in response" do
|
227
|
+
context "uses sync connection" do
|
228
|
+
it 'works fine' do
|
229
|
+
VCR.use_cassette("audit-ssl-parameter-invalid-200-sync", :record => :none) do
|
230
|
+
@pn.audit(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
231
|
+
|
232
|
+
@after_error_callback.should eq true
|
233
|
+
@response_output.seek 0
|
234
|
+
@response_output.read.should eq '{"status":200,'
|
235
|
+
@message_output.seek 0
|
236
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
context "uses async connection" do
|
241
|
+
it 'works fine' do
|
242
|
+
VCR.use_cassette("audit-ssl-parameter-invalid-200-async", :record => :none) do
|
243
|
+
@pn.audit(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
244
|
+
|
245
|
+
eventually do
|
246
|
+
@after_error_callback.should eq true
|
247
|
+
@response_output.seek 0
|
248
|
+
@response_output.read.should eq '{"status":200,'
|
249
|
+
@message_output.seek 0
|
250
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
context "gets status non-200 in response" do
|
257
|
+
context "uses sync connection" do
|
258
|
+
it 'works fine' do
|
259
|
+
VCR.use_cassette("audit-ssl-parameter-invalid-non-200-sync", :record => :none) do
|
260
|
+
@pn.audit(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
261
|
+
|
262
|
+
@after_error_callback.should eq true
|
263
|
+
@response_output.seek 0
|
264
|
+
@response_output.read.should eq '{"status":200,'
|
265
|
+
@message_output.seek 0
|
266
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
context "uses async connection" do
|
271
|
+
it 'works fine' do
|
272
|
+
VCR.use_cassette("audit-ssl-parameter-invalid-non-200-async", :record => :none) do
|
273
|
+
@pn.audit(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
274
|
+
|
275
|
+
eventually do
|
276
|
+
@after_error_callback.should eq true
|
277
|
+
@response_output.seek 0
|
278
|
+
@response_output.read.should eq '{"status":200,'
|
279
|
+
@message_output.seek 0
|
280
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
context "uses non-ssl" do
|
290
|
+
before(:each) { @ssl = false }
|
291
|
+
context "passess callback as block" do
|
292
|
+
context "gets valid json in response" do
|
293
|
+
context "gets status 200 in response" do
|
294
|
+
context "uses sync connection" do
|
295
|
+
it 'works fine' do
|
296
|
+
VCR.use_cassette("audit-nonssl-block-valid-200-sync", :record => :none) do
|
297
|
+
@pn.audit(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", &@callback)
|
298
|
+
|
299
|
+
@after_callback.should eq true
|
300
|
+
@response_output.seek 0
|
301
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
302
|
+
@message_output.seek 0
|
303
|
+
@message_output.read.should eq 'Success'
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
context "uses async connection" do
|
308
|
+
it 'works fine' do
|
309
|
+
VCR.use_cassette("audit-nonssl-block-valid-200-async", :record => :none) do
|
310
|
+
@pn.audit(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", &@callback)
|
311
|
+
|
312
|
+
eventually do
|
313
|
+
@after_callback.should eq true
|
314
|
+
@response_output.seek 0
|
315
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
316
|
+
@message_output.seek 0
|
317
|
+
@message_output.read.should eq 'Success'
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
context "gets status non-200 in response" do
|
324
|
+
context "uses sync connection" do
|
325
|
+
it 'works fine' do
|
326
|
+
VCR.use_cassette("audit-nonssl-block-valid-non-200-sync", :record => :none) do
|
327
|
+
@pn.audit(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", &@callback)
|
328
|
+
|
329
|
+
@after_error_callback.should eq true
|
330
|
+
@response_output.seek 0
|
331
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
332
|
+
@message_output.seek 0
|
333
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
context "uses async connection" do
|
338
|
+
it 'works fine' do
|
339
|
+
VCR.use_cassette("audit-nonssl-block-valid-non-200-async", :record => :none) do
|
340
|
+
@pn.audit(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", &@callback)
|
341
|
+
|
342
|
+
eventually do
|
343
|
+
@after_error_callback.should eq true
|
344
|
+
@response_output.seek 0
|
345
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
346
|
+
@message_output.seek 0
|
347
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
context "gets invalid json in response" do
|
355
|
+
context "gets status 200 in response" do
|
356
|
+
context "uses sync connection" do
|
357
|
+
it 'works fine' do
|
358
|
+
VCR.use_cassette("audit-nonssl-block-invalid-200-sync", :record => :none) do
|
359
|
+
@pn.audit(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", &@callback)
|
360
|
+
|
361
|
+
@after_error_callback.should eq true
|
362
|
+
@response_output.seek 0
|
363
|
+
@response_output.read.should eq '{"status":200,'
|
364
|
+
@message_output.seek 0
|
365
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
context "uses async connection" do
|
370
|
+
it 'works fine' do
|
371
|
+
VCR.use_cassette("audit-nonssl-block-invalid-200-async", :record => :none) do
|
372
|
+
@pn.audit(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", &@callback)
|
373
|
+
|
374
|
+
eventually do
|
375
|
+
@after_error_callback.should eq true
|
376
|
+
@response_output.seek 0
|
377
|
+
@response_output.read.should eq '{"status":200,'
|
378
|
+
@message_output.seek 0
|
379
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
context "gets status non-200 in response" do
|
386
|
+
context "uses sync connection" do
|
387
|
+
it 'works fine' do
|
388
|
+
VCR.use_cassette("audit-nonssl-block-invalid-non-200-sync", :record => :none) do
|
389
|
+
@pn.audit(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", &@callback)
|
390
|
+
|
391
|
+
@after_error_callback.should eq true
|
392
|
+
@response_output.seek 0
|
393
|
+
@response_output.read.should eq '{"status":200,'
|
394
|
+
@message_output.seek 0
|
395
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
context "uses async connection" do
|
400
|
+
it 'works fine' do
|
401
|
+
VCR.use_cassette("audit-nonssl-block-invalid-non-200-async", :record => :none) do
|
402
|
+
@pn.audit(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", &@callback)
|
403
|
+
|
404
|
+
eventually do
|
405
|
+
@after_error_callback.should eq true
|
406
|
+
@response_output.seek 0
|
407
|
+
@response_output.read.should eq '{"status":200,'
|
408
|
+
@message_output.seek 0
|
409
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
context "passess callback as parameter" do
|
418
|
+
context "gets valid json in response" do
|
419
|
+
context "gets status 200 in response" do
|
420
|
+
context "uses sync connection" do
|
421
|
+
it 'works fine' do
|
422
|
+
VCR.use_cassette("audit-nonssl-parameter-valid-200-sync", :record => :none) do
|
423
|
+
@pn.audit(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
424
|
+
|
425
|
+
@after_callback.should eq true
|
426
|
+
@response_output.seek 0
|
427
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
428
|
+
@message_output.seek 0
|
429
|
+
@message_output.read.should eq 'Success'
|
430
|
+
end
|
431
|
+
end
|
432
|
+
end
|
433
|
+
context "uses async connection" do
|
434
|
+
it 'works fine' do
|
435
|
+
VCR.use_cassette("audit-nonssl-parameter-valid-200-async", :record => :none) do
|
436
|
+
@pn.audit(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
437
|
+
|
438
|
+
eventually do
|
439
|
+
@after_callback.should eq true
|
440
|
+
@response_output.seek 0
|
441
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
442
|
+
@message_output.seek 0
|
443
|
+
@message_output.read.should eq 'Success'
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
context "gets status non-200 in response" do
|
450
|
+
context "uses sync connection" do
|
451
|
+
it 'works fine' do
|
452
|
+
VCR.use_cassette("audit-nonssl-parameter-valid-non-200-sync", :record => :none) do
|
453
|
+
@pn.audit(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
454
|
+
|
455
|
+
@after_error_callback.should eq true
|
456
|
+
@response_output.seek 0
|
457
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
458
|
+
@message_output.seek 0
|
459
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
context "uses async connection" do
|
464
|
+
it 'works fine' do
|
465
|
+
VCR.use_cassette("audit-nonssl-parameter-valid-non-200-async", :record => :none) do
|
466
|
+
@pn.audit(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
467
|
+
|
468
|
+
eventually do
|
469
|
+
@after_error_callback.should eq true
|
470
|
+
@response_output.seek 0
|
471
|
+
@response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","channel":"demo","level":"user"},"service":"Access Manager"}'
|
472
|
+
@message_output.seek 0
|
473
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|
480
|
+
context "gets invalid json in response" do
|
481
|
+
context "gets status 200 in response" do
|
482
|
+
context "uses sync connection" do
|
483
|
+
it 'works fine' do
|
484
|
+
VCR.use_cassette("audit-nonssl-parameter-invalid-200-sync", :record => :none) do
|
485
|
+
@pn.audit(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
486
|
+
|
487
|
+
@after_error_callback.should eq true
|
488
|
+
@response_output.seek 0
|
489
|
+
@response_output.read.should eq '{"status":200,'
|
490
|
+
@message_output.seek 0
|
491
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|
495
|
+
context "uses async connection" do
|
496
|
+
it 'works fine' do
|
497
|
+
VCR.use_cassette("audit-nonssl-parameter-invalid-200-async", :record => :none) do
|
498
|
+
@pn.audit(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
499
|
+
|
500
|
+
eventually do
|
501
|
+
@after_error_callback.should eq true
|
502
|
+
@response_output.seek 0
|
503
|
+
@response_output.read.should eq '{"status":200,'
|
504
|
+
@message_output.seek 0
|
505
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
509
|
+
end
|
510
|
+
end
|
511
|
+
context "gets status non-200 in response" do
|
512
|
+
context "uses sync connection" do
|
513
|
+
it 'works fine' do
|
514
|
+
VCR.use_cassette("audit-nonssl-parameter-invalid-non-200-sync", :record => :none) do
|
515
|
+
@pn.audit(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
516
|
+
|
517
|
+
@after_error_callback.should eq true
|
518
|
+
@response_output.seek 0
|
519
|
+
@response_output.read.should eq '{"status":200,'
|
520
|
+
@message_output.seek 0
|
521
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
522
|
+
end
|
523
|
+
end
|
524
|
+
end
|
525
|
+
context "uses async connection" do
|
526
|
+
it 'works fine' do
|
527
|
+
VCR.use_cassette("audit-nonssl-parameter-invalid-non-200-async", :record => :none) do
|
528
|
+
@pn.audit(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :callback => @callback)
|
529
|
+
|
530
|
+
eventually do
|
531
|
+
@after_error_callback.should eq true
|
532
|
+
@response_output.seek 0
|
533
|
+
@response_output.read.should eq '{"status":200,'
|
534
|
+
@message_output.seek 0
|
535
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
536
|
+
end
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end
|
544
|
+
end
|