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.

@@ -0,0 +1,555 @@
1
+ require 'spec_helper'
2
+
3
+ describe "#revoke" 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::Revoke.any_instance.stub(:current_time).and_return 1234567890
31
+ Pubnub::Revoke.any_instance.stub(:signature).and_return 'kdDh/sFC3rSR%2Bt5AEymIc57d1velIr562V7usa5M4k0='
32
+
33
+ end
34
+ context "uses ssl" do
35
+ before(:each) { @ssl = true }
36
+ it "Generates valid url for application level" do
37
+ VCR.use_cassette("revoke-application-level", :record => :none) do
38
+ @pn.revoke(:http_sync => true, &@callback)
39
+
40
+ @after_callback.should eq true
41
+ @response_output.seek 0
42
+ @response_output.read.should eq '{"status":200,"service":"Access Manager","message":"Success","payload":{"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","r":0,"ttl":1440,"w":0,"level":"subkey"}}'
43
+ @message_output.seek 0
44
+ @message_output.read.should eq 'Success'
45
+ end
46
+ end
47
+ context "passess callback as block" do
48
+ context "gets valid json in response" do
49
+ context "gets status 200 in response" do
50
+ context "uses sync connection" do
51
+ it 'works fine' do
52
+ VCR.use_cassette("revoke-ssl-block-valid-200-sync", :record => :none) do
53
+ @pn.revoke(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
54
+
55
+ @after_callback.should eq true
56
+ @response_output.seek 0
57
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
58
+ @message_output.seek 0
59
+ @message_output.read.should eq 'Success'
60
+ end
61
+ end
62
+ end
63
+ context "uses async connection" do
64
+ it 'works fine' do
65
+ VCR.use_cassette("revoke-ssl-block-valid-200-async", :record => :none) do
66
+ @pn.revoke(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
67
+
68
+ eventually do
69
+ @after_callback.should eq true
70
+ @response_output.seek 0
71
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
72
+ @message_output.seek 0
73
+ @message_output.read.should eq 'Success'
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ context "gets status non-200 in response" do
80
+ context "uses sync connection" do
81
+ it 'works fine' do
82
+ VCR.use_cassette("revoke-ssl-block-valid-non-200-sync", :record => :none) do
83
+ @pn.revoke(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
84
+
85
+ @after_error_callback.should eq true
86
+ @response_output.seek 0
87
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
88
+ @message_output.seek 0
89
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
90
+ end
91
+ end
92
+ end
93
+ context "uses async connection" do
94
+ it 'works fine' do
95
+ VCR.use_cassette("revoke-ssl-block-valid-non-200-async", :record => :none) do
96
+ @pn.revoke(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
97
+
98
+ eventually do
99
+ @after_error_callback.should eq true
100
+ @response_output.seek 0
101
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
102
+ @message_output.seek 0
103
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ context "gets invalid json in response" do
111
+ context "gets status 200 in response" do
112
+ context "uses sync connection" do
113
+ it 'works fine' do
114
+ VCR.use_cassette("revoke-ssl-block-invalid-200-sync", :record => :none) do
115
+ @pn.revoke(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
116
+
117
+ @after_error_callback.should eq true
118
+ @response_output.seek 0
119
+ @response_output.read.should eq '{"status":200,'
120
+ @message_output.seek 0
121
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
122
+ end
123
+ end
124
+ end
125
+ context "uses async connection" do
126
+ it 'works fine' do
127
+ VCR.use_cassette("revoke-ssl-block-invalid-200-async", :record => :none) do
128
+ @pn.revoke(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
129
+
130
+ eventually do
131
+ @after_error_callback.should eq true
132
+ @response_output.seek 0
133
+ @response_output.read.should eq '{"status":200,'
134
+ @message_output.seek 0
135
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+ context "gets status non-200 in response" do
142
+ context "uses sync connection" do
143
+ it 'works fine' do
144
+ VCR.use_cassette("revoke-ssl-block-invalid-non-200-sync", :record => :none) do
145
+ @pn.revoke(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
146
+
147
+ @after_error_callback.should eq true
148
+ @response_output.seek 0
149
+ @response_output.read.should eq '{"status":200,'
150
+ @message_output.seek 0
151
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
152
+ end
153
+ end
154
+ end
155
+ context "uses async connection" do
156
+ it 'works fine' do
157
+ VCR.use_cassette("revoke-ssl-block-invalid-non-200-async", :record => :none) do
158
+ @pn.revoke(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
159
+
160
+ eventually do
161
+ @after_error_callback.should eq true
162
+ @response_output.seek 0
163
+ @response_output.read.should eq '{"status":200,'
164
+ @message_output.seek 0
165
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
173
+ context "passess callback as parameter" do
174
+ context "gets valid json in response" do
175
+ context "gets status 200 in response" do
176
+ context "uses sync connection" do
177
+ it 'works fine' do
178
+ VCR.use_cassette("revoke-ssl-parameter-valid-200-sync", :record => :none) do
179
+ @pn.revoke(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
180
+
181
+ @after_callback.should eq true
182
+ @response_output.seek 0
183
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
184
+ @message_output.seek 0
185
+ @message_output.read.should eq 'Success'
186
+ end
187
+ end
188
+ end
189
+ context "uses async connection" do
190
+ it 'works fine' do
191
+ VCR.use_cassette("revoke-ssl-parameter-valid-200-async", :record => :none) do
192
+ @pn.revoke(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
193
+
194
+ eventually do
195
+ @after_callback.should eq true
196
+ @response_output.seek 0
197
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
198
+ @message_output.seek 0
199
+ @message_output.read.should eq 'Success'
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end
205
+ context "gets status non-200 in response" do
206
+ context "uses sync connection" do
207
+ it 'works fine' do
208
+ VCR.use_cassette("revoke-ssl-parameter-valid-non-200-sync", :record => :none) do
209
+ @pn.revoke(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
210
+
211
+ @after_error_callback.should eq true
212
+ @response_output.seek 0
213
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
214
+ @message_output.seek 0
215
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
216
+ end
217
+ end
218
+ end
219
+ context "uses async connection" do
220
+ it 'works fine' do
221
+ VCR.use_cassette("revoke-ssl-parameter-valid-non-200-async", :record => :none) do
222
+ @pn.revoke(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
223
+
224
+ eventually do
225
+ @after_error_callback.should eq true
226
+ @response_output.seek 0
227
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
228
+ @message_output.seek 0
229
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
230
+ end
231
+ end
232
+ end
233
+ end
234
+ end
235
+ end
236
+ context "gets invalid json in response" do
237
+ context "gets status 200 in response" do
238
+ context "uses sync connection" do
239
+ it 'works fine' do
240
+ VCR.use_cassette("revoke-ssl-parameter-invalid-200-sync", :record => :none) do
241
+ @pn.revoke(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
242
+
243
+ @after_error_callback.should eq true
244
+ @response_output.seek 0
245
+ @response_output.read.should eq '{"status":200,'
246
+ @message_output.seek 0
247
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
248
+ end
249
+ end
250
+ end
251
+ context "uses async connection" do
252
+ it 'works fine' do
253
+ VCR.use_cassette("revoke-ssl-parameter-invalid-200-async", :record => :none) do
254
+ @pn.revoke(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
255
+
256
+ eventually do
257
+ @after_error_callback.should eq true
258
+ @response_output.seek 0
259
+ @response_output.read.should eq '{"status":200,'
260
+ @message_output.seek 0
261
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
262
+ end
263
+ end
264
+ end
265
+ end
266
+ end
267
+ context "gets status non-200 in response" do
268
+ context "uses sync connection" do
269
+ it 'works fine' do
270
+ VCR.use_cassette("revoke-ssl-parameter-invalid-non-200-sync", :record => :none) do
271
+ @pn.revoke(:ssl => true, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
272
+
273
+ @after_error_callback.should eq true
274
+ @response_output.seek 0
275
+ @response_output.read.should eq '{"status":200,'
276
+ @message_output.seek 0
277
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
278
+ end
279
+ end
280
+ end
281
+ context "uses async connection" do
282
+ it 'works fine' do
283
+ VCR.use_cassette("revoke-ssl-parameter-invalid-non-200-async", :record => :none) do
284
+ @pn.revoke(:ssl => true, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
285
+
286
+ eventually do
287
+ @after_error_callback.should eq true
288
+ @response_output.seek 0
289
+ @response_output.read.should eq '{"status":200,'
290
+ @message_output.seek 0
291
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
292
+ end
293
+ end
294
+ end
295
+ end
296
+ end
297
+ end
298
+ end
299
+ end
300
+ context "uses non-ssl" do
301
+ before(:each) { @ssl = false }
302
+ context "passess callback as block" do
303
+ context "gets valid json in response" do
304
+ context "gets status 200 in response" do
305
+ context "uses sync connection" do
306
+ it 'works fine' do
307
+ VCR.use_cassette("revoke-nonssl-block-valid-200-sync", :record => :none) do
308
+ @pn.revoke(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
309
+
310
+ @after_callback.should eq true
311
+ @response_output.seek 0
312
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
313
+ @message_output.seek 0
314
+ @message_output.read.should eq 'Success'
315
+ end
316
+ end
317
+ end
318
+ context "uses async connection" do
319
+ it 'works fine' do
320
+ VCR.use_cassette("revoke-nonssl-block-valid-200-async", :record => :none) do
321
+ @pn.revoke(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
322
+
323
+ eventually do
324
+ @after_callback.should eq true
325
+ @response_output.seek 0
326
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
327
+ @message_output.seek 0
328
+ @message_output.read.should eq 'Success'
329
+ end
330
+ end
331
+ end
332
+ end
333
+ end
334
+ context "gets status non-200 in response" do
335
+ context "uses sync connection" do
336
+ it 'works fine' do
337
+ VCR.use_cassette("revoke-nonssl-block-valid-non-200-sync", :record => :none) do
338
+ @pn.revoke(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
339
+
340
+ @after_error_callback.should eq true
341
+ @response_output.seek 0
342
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
343
+ @message_output.seek 0
344
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
345
+ end
346
+ end
347
+ end
348
+ context "uses async connection" do
349
+ it 'works fine' do
350
+ VCR.use_cassette("revoke-nonssl-block-valid-non-200-async", :record => :none) do
351
+ @pn.revoke(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
352
+
353
+ eventually do
354
+ @after_error_callback.should eq true
355
+ @response_output.seek 0
356
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
357
+ @message_output.seek 0
358
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
359
+ end
360
+ end
361
+ end
362
+ end
363
+ end
364
+ end
365
+ context "gets invalid json in response" do
366
+ context "gets status 200 in response" do
367
+ context "uses sync connection" do
368
+ it 'works fine' do
369
+ VCR.use_cassette("revoke-nonssl-block-invalid-200-sync", :record => :none) do
370
+ @pn.revoke(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
371
+
372
+ @after_error_callback.should eq true
373
+ @response_output.seek 0
374
+ @response_output.read.should eq '{"status":200,'
375
+ @message_output.seek 0
376
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
377
+ end
378
+ end
379
+ end
380
+ context "uses async connection" do
381
+ it 'works fine' do
382
+ VCR.use_cassette("revoke-nonssl-block-invalid-200-async", :record => :none) do
383
+ @pn.revoke(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
384
+
385
+ eventually do
386
+ @after_error_callback.should eq true
387
+ @response_output.seek 0
388
+ @response_output.read.should eq '{"status":200,'
389
+ @message_output.seek 0
390
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
391
+ end
392
+ end
393
+ end
394
+ end
395
+ end
396
+ context "gets status non-200 in response" do
397
+ context "uses sync connection" do
398
+ it 'works fine' do
399
+ VCR.use_cassette("revoke-nonssl-block-invalid-non-200-sync", :record => :none) do
400
+ @pn.revoke(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
401
+
402
+ @after_error_callback.should eq true
403
+ @response_output.seek 0
404
+ @response_output.read.should eq '{"status":200,'
405
+ @message_output.seek 0
406
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
407
+ end
408
+ end
409
+ end
410
+ context "uses async connection" do
411
+ it 'works fine' do
412
+ VCR.use_cassette("revoke-nonssl-block-invalid-non-200-async", :record => :none) do
413
+ @pn.revoke(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, &@callback)
414
+
415
+ eventually do
416
+ @after_error_callback.should eq true
417
+ @response_output.seek 0
418
+ @response_output.read.should eq '{"status":200,'
419
+ @message_output.seek 0
420
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
421
+ end
422
+ end
423
+ end
424
+ end
425
+ end
426
+ end
427
+ end
428
+ context "passess callback as parameter" do
429
+ context "gets valid json in response" do
430
+ context "gets status 200 in response" do
431
+ context "uses sync connection" do
432
+ it 'works fine' do
433
+ VCR.use_cassette("revoke-nonssl-parameter-valid-200-sync", :record => :none) do
434
+ @pn.revoke(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
435
+
436
+ @after_callback.should eq true
437
+ @response_output.seek 0
438
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
439
+ @message_output.seek 0
440
+ @message_output.read.should eq 'Success'
441
+ end
442
+ end
443
+ end
444
+ context "uses async connection" do
445
+ it 'works fine' do
446
+ VCR.use_cassette("revoke-nonssl-parameter-valid-200-async", :record => :none) do
447
+ @pn.revoke(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
448
+
449
+ eventually do
450
+ @after_callback.should eq true
451
+ @response_output.seek 0
452
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
453
+ @message_output.seek 0
454
+ @message_output.read.should eq 'Success'
455
+ end
456
+ end
457
+ end
458
+ end
459
+ end
460
+ context "gets status non-200 in response" do
461
+ context "uses sync connection" do
462
+ it 'works fine' do
463
+ VCR.use_cassette("revoke-nonssl-parameter-valid-non-200-sync", :record => :none) do
464
+ @pn.revoke(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
465
+
466
+ @after_error_callback.should eq true
467
+ @response_output.seek 0
468
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
469
+ @message_output.seek 0
470
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
471
+ end
472
+ end
473
+ end
474
+ context "uses async connection" do
475
+ it 'works fine' do
476
+ VCR.use_cassette("revoke-nonssl-parameter-valid-non-200-async", :record => :none) do
477
+ @pn.revoke(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
478
+
479
+ eventually do
480
+ @after_error_callback.should eq true
481
+ @response_output.seek 0
482
+ @response_output.read.should eq '{"status":200,"message":"Success","payload":{"auths":{"authkey":{"r":0,"w":0}},"subscribe_key":"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe","ttl":1,"channel":"demo","level":"user"},"service":"Access Manager"}'
483
+ @message_output.seek 0
484
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
485
+ end
486
+ end
487
+ end
488
+ end
489
+ end
490
+ end
491
+ context "gets invalid json in response" do
492
+ context "gets status 200 in response" do
493
+ context "uses sync connection" do
494
+ it 'works fine' do
495
+ VCR.use_cassette("revoke-nonssl-parameter-invalid-200-sync", :record => :none) do
496
+ @pn.revoke(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
497
+
498
+ @after_error_callback.should eq true
499
+ @response_output.seek 0
500
+ @response_output.read.should eq '{"status":200,'
501
+ @message_output.seek 0
502
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
503
+ end
504
+ end
505
+ end
506
+ context "uses async connection" do
507
+ it 'works fine' do
508
+ VCR.use_cassette("revoke-nonssl-parameter-invalid-200-async", :record => :none) do
509
+ @pn.revoke(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
510
+
511
+ eventually do
512
+ @after_error_callback.should eq true
513
+ @response_output.seek 0
514
+ @response_output.read.should eq '{"status":200,'
515
+ @message_output.seek 0
516
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
517
+ end
518
+ end
519
+ end
520
+ end
521
+ end
522
+ context "gets status non-200 in response" do
523
+ context "uses sync connection" do
524
+ it 'works fine' do
525
+ VCR.use_cassette("revoke-nonssl-parameter-invalid-non-200-sync", :record => :none) do
526
+ @pn.revoke(:ssl => false, :http_sync => true, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
527
+
528
+ @after_error_callback.should eq true
529
+ @response_output.seek 0
530
+ @response_output.read.should eq '{"status":200,'
531
+ @message_output.seek 0
532
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
533
+ end
534
+ end
535
+ end
536
+ context "uses async connection" do
537
+ it 'works fine' do
538
+ VCR.use_cassette("revoke-nonssl-parameter-invalid-non-200-async", :record => :none) do
539
+ @pn.revoke(:ssl => false, :http_sync => false, :channel => "demo", :auth_key => "authkey", :write => true, :read => true, :callback => @callback)
540
+
541
+ eventually do
542
+ @after_error_callback.should eq true
543
+ @response_output.seek 0
544
+ @response_output.read.should eq '{"status":200,'
545
+ @message_output.seek 0
546
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
547
+ end
548
+ end
549
+ end
550
+ end
551
+ end
552
+ end
553
+ end
554
+ end
555
+ end