koala 1.11.1 → 2.0.0rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/changelog.md +21 -2
- data/lib/koala.rb +3 -11
- data/lib/koala/api.rb +1 -3
- data/lib/koala/api/graph_api.rb +1 -15
- data/lib/koala/api/graph_batch_api.rb +2 -2
- data/lib/koala/http_service.rb +1 -118
- data/lib/koala/oauth.rb +0 -56
- data/lib/koala/realtime_updates.rb +0 -6
- data/lib/koala/test_users.rb +0 -7
- data/lib/koala/version.rb +1 -1
- data/readme.md +1 -1
- data/spec/cases/graph_api_batch_spec.rb +15 -2
- data/spec/cases/http_service_spec.rb +0 -166
- data/spec/cases/koala_spec.rb +0 -29
- data/spec/cases/oauth_spec.rb +315 -482
- data/spec/cases/realtime_updates_spec.rb +0 -12
- data/spec/cases/test_users_spec.rb +8 -20
- data/spec/fixtures/mock_facebook_responses.yml +0 -10
- data/spec/support/graph_api_shared_examples.rb +1 -30
- data/spec/support/koala_test.rb +1 -4
- data/spec/support/rest_api_shared_examples.rb +1 -1
- metadata +3 -6
- data/lib/koala/api/legacy.rb +0 -26
- data/spec/cases/legacy_spec.rb +0 -115
data/spec/cases/koala_spec.rb
CHANGED
@@ -12,35 +12,6 @@ describe Koala do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context "for deprecated services" do
|
16
|
-
before :each do
|
17
|
-
@service = Koala.http_service
|
18
|
-
end
|
19
|
-
|
20
|
-
after :each do
|
21
|
-
Koala.http_service = @service
|
22
|
-
end
|
23
|
-
|
24
|
-
it "invokes deprecated_interface if present" do
|
25
|
-
mock_service = double("http service")
|
26
|
-
expect(mock_service).to receive(:deprecated_interface)
|
27
|
-
Koala.http_service = mock_service
|
28
|
-
end
|
29
|
-
|
30
|
-
it "does not set the service if it's deprecated" do
|
31
|
-
mock_service = double("http service")
|
32
|
-
allow(mock_service).to receive(:deprecated_interface)
|
33
|
-
Koala.http_service = mock_service
|
34
|
-
expect(Koala.http_service).to eq(@service)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "sets the service if it's not deprecated" do
|
38
|
-
mock_service = double("http service")
|
39
|
-
Koala.http_service = mock_service
|
40
|
-
expect(Koala.http_service).to eq(mock_service)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
15
|
describe "make_request" do
|
45
16
|
it "passes all its arguments to the http_service" do
|
46
17
|
path = "foo"
|
data/spec/cases/oauth_spec.rb
CHANGED
@@ -17,8 +17,8 @@ describe "Koala::Facebook::OAuth" do
|
|
17
17
|
|
18
18
|
# this should expanded to cover all variables
|
19
19
|
raise Exception, "Must supply app data to run FacebookOAuthTests!" unless @app_id && @secret && @callback_url &&
|
20
|
-
|
21
|
-
|
20
|
+
@raw_token_string &&
|
21
|
+
@raw_offline_access_token_string
|
22
22
|
|
23
23
|
# we can just test against the same key twice
|
24
24
|
@multiple_session_keys = [KoalaTest.session_key, KoalaTest.session_key] if KoalaTest.session_key
|
@@ -39,8 +39,8 @@ describe "Koala::Facebook::OAuth" do
|
|
39
39
|
|
40
40
|
it "properly sets attributes" do
|
41
41
|
expect(@oauth.app_id == @app_id &&
|
42
|
-
|
43
|
-
|
42
|
+
@oauth.app_secret == @secret &&
|
43
|
+
@oauth.oauth_callback_url == @callback_url).to be_truthy
|
44
44
|
end
|
45
45
|
|
46
46
|
it "properly initializes without a callback_url" do
|
@@ -50,8 +50,8 @@ describe "Koala::Facebook::OAuth" do
|
|
50
50
|
it "properly sets attributes without a callback URL" do
|
51
51
|
@oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
|
52
52
|
expect(@oauth.app_id == @app_id &&
|
53
|
-
|
54
|
-
|
53
|
+
@oauth.app_secret == @secret &&
|
54
|
+
@oauth.oauth_callback_url == nil).to be_truthy
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -120,14 +120,14 @@ describe "Koala::Facebook::OAuth" do
|
|
120
120
|
|
121
121
|
it "returns nil if the call to FB returns an expired code error" do
|
122
122
|
allow(@oauth).to receive(:get_access_token_info).and_raise(Koala::Facebook::OAuthTokenRequestError.new(400,
|
123
|
-
|
124
|
-
|
123
|
+
'{ "error": { "type": "OAuthException", "message": "Code was invalid or expired. Session has expired at unix time 1324044000. The current unix time is 1324300957." } }'
|
124
|
+
))
|
125
125
|
expect(@oauth.get_user_info_from_cookies(@cookie)).to be_nil
|
126
126
|
end
|
127
127
|
|
128
128
|
it "raises the error if the call to FB returns a different error" do
|
129
129
|
allow(@oauth).to receive(:get_access_token_info).and_raise(Koala::Facebook::OAuthTokenRequestError.new(400,
|
130
|
-
|
130
|
+
'{ "error": { "type": "OtherError", "message": "A Facebook Error" } }'))
|
131
131
|
expect { @oauth.get_user_info_from_cookies(@cookie) }.to raise_exception(Koala::Facebook::OAuthTokenRequestError)
|
132
132
|
end
|
133
133
|
end
|
@@ -180,596 +180,429 @@ describe "Koala::Facebook::OAuth" do
|
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
-
describe "
|
184
|
-
describe "
|
185
|
-
|
186
|
-
|
187
|
-
@
|
188
|
-
allow(@oauth).to receive(:get_access_token_info).and_return("access_token" => "my token")
|
183
|
+
describe "for URL generation" do
|
184
|
+
describe "#url_for_oauth_code" do
|
185
|
+
it "generates a properly formatted OAuth code URL with the default values" do
|
186
|
+
url = @oauth.url_for_oauth_code
|
187
|
+
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
|
189
188
|
end
|
190
189
|
|
191
|
-
it "
|
192
|
-
|
193
|
-
@oauth.
|
190
|
+
it "includes the api version if specified" do
|
191
|
+
version = Koala.config.api_version = "v.2.2.2.2"
|
192
|
+
url = @oauth.url_for_oauth_code
|
193
|
+
expect(url).to match_url("https://#{Koala.config.dialog_host}/#{version}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
|
194
194
|
end
|
195
195
|
|
196
|
-
it "
|
197
|
-
|
198
|
-
|
196
|
+
it "generates a properly formatted OAuth code URL when a callback is given" do
|
197
|
+
callback = "foo.com"
|
198
|
+
url = @oauth.url_for_oauth_code(:callback => callback)
|
199
|
+
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{callback}")
|
199
200
|
end
|
200
201
|
|
201
|
-
it "
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
expect(result).to be_nil
|
202
|
+
it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
|
203
|
+
permissions = "publish_stream,read_stream"
|
204
|
+
url = @oauth.url_for_oauth_code(:permissions => permissions)
|
205
|
+
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape @callback_url}")
|
206
206
|
end
|
207
207
|
|
208
|
-
it "
|
209
|
-
|
210
|
-
@oauth.
|
208
|
+
it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
|
209
|
+
permissions = ["publish_stream", "read_stream"]
|
210
|
+
url = @oauth.url_for_oauth_code(:permissions => permissions)
|
211
|
+
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions.join(",")}&redirect_uri=#{CGI.escape @callback_url}")
|
211
212
|
end
|
212
|
-
end
|
213
213
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
214
|
+
it "generates a properly formatted OAuth code URL when both permissions and callback are provided" do
|
215
|
+
permissions = "publish_stream,read_stream"
|
216
|
+
callback = "foo.com"
|
217
|
+
url = @oauth.url_for_oauth_code(:callback => callback, :permissions => permissions)
|
218
|
+
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape callback}")
|
218
219
|
end
|
219
220
|
|
220
|
-
it "
|
221
|
-
|
222
|
-
|
221
|
+
it "generates a properly formatted OAuth code URL when a display is given as a string" do
|
222
|
+
url = @oauth.url_for_oauth_code(:display => "page")
|
223
|
+
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&display=page&redirect_uri=#{CGI.escape @callback_url}")
|
223
224
|
end
|
224
225
|
|
225
|
-
it "
|
226
|
-
|
227
|
-
expect
|
226
|
+
it "raises an exception if no callback is given in initialization or the call" do
|
227
|
+
oauth2 = Koala::Facebook::OAuth.new(@app_id, @secret)
|
228
|
+
expect { oauth2.url_for_oauth_code }.to raise_error(ArgumentError)
|
228
229
|
end
|
229
230
|
|
230
|
-
it "
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
231
|
+
it "includes any additional options as URL parameters, appropriately escaped" do
|
232
|
+
params = {
|
233
|
+
:url => "http://foo.bar?c=2",
|
234
|
+
:email => "cdc@b.com"
|
235
|
+
}
|
236
|
+
url = @oauth.url_for_oauth_code(params)
|
237
|
+
params.each_pair do |key, value|
|
238
|
+
expect(url).to match(/[\&\?]#{key}=#{CGI.escape value}/)
|
239
|
+
end
|
235
240
|
end
|
236
241
|
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe "for URL generation" do
|
241
|
-
describe "#url_for_oauth_code" do
|
242
|
-
it "generates a properly formatted OAuth code URL with the default values" do
|
243
|
-
url = @oauth.url_for_oauth_code
|
244
|
-
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
|
245
|
-
end
|
246
|
-
|
247
|
-
it "includes the api version if specified" do
|
248
|
-
version = Koala.config.api_version = "v.2.2.2.2"
|
249
|
-
url = @oauth.url_for_oauth_code
|
250
|
-
expect(url).to match_url("https://#{Koala.config.dialog_host}/#{version}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
|
251
|
-
end
|
252
|
-
|
253
|
-
it "generates a properly formatted OAuth code URL when a callback is given" do
|
254
|
-
callback = "foo.com"
|
255
|
-
url = @oauth.url_for_oauth_code(:callback => callback)
|
256
|
-
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{callback}")
|
257
|
-
end
|
258
|
-
|
259
|
-
it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
|
260
|
-
permissions = "publish_stream,read_stream"
|
261
|
-
url = @oauth.url_for_oauth_code(:permissions => permissions)
|
262
|
-
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape @callback_url}")
|
263
|
-
end
|
264
|
-
|
265
|
-
it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
|
266
|
-
permissions = ["publish_stream", "read_stream"]
|
267
|
-
url = @oauth.url_for_oauth_code(:permissions => permissions)
|
268
|
-
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions.join(",")}&redirect_uri=#{CGI.escape @callback_url}")
|
269
|
-
end
|
270
242
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape callback}")
|
276
|
-
end
|
277
|
-
|
278
|
-
it "generates a properly formatted OAuth code URL when a display is given as a string" do
|
279
|
-
url = @oauth.url_for_oauth_code(:display => "page")
|
280
|
-
expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&display=page&redirect_uri=#{CGI.escape @callback_url}")
|
281
|
-
end
|
282
|
-
|
283
|
-
it "raises an exception if no callback is given in initialization or the call" do
|
284
|
-
oauth2 = Koala::Facebook::OAuth.new(@app_id, @secret)
|
285
|
-
expect { oauth2.url_for_oauth_code }.to raise_error(ArgumentError)
|
286
|
-
end
|
287
|
-
|
288
|
-
it "includes any additional options as URL parameters, appropriately escaped" do
|
289
|
-
params = {
|
290
|
-
:url => "http://foo.bar?c=2",
|
291
|
-
:email => "cdc@b.com"
|
292
|
-
}
|
293
|
-
url = @oauth.url_for_oauth_code(params)
|
294
|
-
params.each_pair do |key, value|
|
295
|
-
expect(url).to match(/[\&\?]#{key}=#{CGI.escape value}/)
|
243
|
+
describe "#url_for_access_token" do
|
244
|
+
before :each do
|
245
|
+
# since we're just composing a URL here, we don't need to have a real code
|
246
|
+
@code ||= "test_code"
|
296
247
|
end
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
describe "#url_for_access_token" do
|
301
|
-
before :each do
|
302
|
-
# since we're just composing a URL here, we don't need to have a real code
|
303
|
-
@code ||= "test_code"
|
304
|
-
end
|
305
248
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
end
|
310
|
-
|
311
|
-
it "includes the api version if specified" do
|
312
|
-
version = Koala.config.api_version = "v.2.2.2.2"
|
313
|
-
url = @oauth.url_for_access_token(@code)
|
314
|
-
expect(url).to match_url("https://#{Koala.config.graph_server}/#{version}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape @callback_url}")
|
315
|
-
end
|
316
|
-
|
317
|
-
it "generates a properly formatted OAuth token URL when provided a callback" do
|
318
|
-
callback = "foo.com"
|
319
|
-
url = @oauth.url_for_access_token(@code, :callback => callback)
|
320
|
-
expect(url).to match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape callback}")
|
321
|
-
end
|
322
|
-
|
323
|
-
it "includes any additional options as URL parameters, appropriately escaped" do
|
324
|
-
params = {
|
325
|
-
:url => "http://foo.bar?c=2",
|
326
|
-
:email => "cdc@b.com"
|
327
|
-
}
|
328
|
-
url = @oauth.url_for_access_token(@code, params)
|
329
|
-
params.each_pair do |key, value|
|
330
|
-
expect(url).to match(/[\&\?]#{key}=#{CGI.escape value}/)
|
249
|
+
it "generates a properly formatted OAuth token URL when provided a code" do
|
250
|
+
url = @oauth.url_for_access_token(@code)
|
251
|
+
expect(url).to match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape @callback_url}")
|
331
252
|
end
|
332
|
-
end
|
333
|
-
end
|
334
253
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
end
|
340
|
-
|
341
|
-
it "includes the api version if specified" do
|
342
|
-
version = Koala.config.api_version = "v.2.2.2.2"
|
343
|
-
dialog_type = "my_dialog_type"
|
344
|
-
expect(@oauth.url_for_dialog(dialog_type)).to match("https:\/\/#{Koala.config.dialog_host}\/#{version}\/dialog\/#{dialog_type}")
|
345
|
-
end
|
346
|
-
|
347
|
-
it "adds the app_id/client_id to the url" do
|
348
|
-
automatic_params = {:app_id => @app_id, :client_id => @client_id}
|
349
|
-
url = @oauth.url_for_dialog("foo", automatic_params)
|
350
|
-
automatic_params.each_pair do |key, value|
|
351
|
-
# we're slightly simplifying how encode_params works, but for strings/ints, it's okay
|
352
|
-
expect(url).to match(/[\&\?]#{key}=#{CGI.escape value.to_s}/)
|
254
|
+
it "includes the api version if specified" do
|
255
|
+
version = Koala.config.api_version = "v.2.2.2.2"
|
256
|
+
url = @oauth.url_for_access_token(@code)
|
257
|
+
expect(url).to match_url("https://#{Koala.config.graph_server}/#{version}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape @callback_url}")
|
353
258
|
end
|
354
|
-
end
|
355
259
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
}
|
361
|
-
url = @oauth.url_for_dialog("friends", params)
|
362
|
-
params.each_pair do |key, value|
|
363
|
-
# we're slightly simplifying how encode_params works, but strings/ints, it's okay
|
364
|
-
expect(url).to match(/[\&\?]#{key}=#{CGI.escape value.to_s}/)
|
260
|
+
it "generates a properly formatted OAuth token URL when provided a callback" do
|
261
|
+
callback = "foo.com"
|
262
|
+
url = @oauth.url_for_access_token(@code, :callback => callback)
|
263
|
+
expect(url).to match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape callback}")
|
365
264
|
end
|
366
|
-
end
|
367
265
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
url = @oauth.url_for_dialog("feed", :name => "People Argue Just to Win", :link => "http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html")
|
378
|
-
expect(url).to match_url("https://www.facebook.com/dialog/feed?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
|
266
|
+
it "includes any additional options as URL parameters, appropriately escaped" do
|
267
|
+
params = {
|
268
|
+
:url => "http://foo.bar?c=2",
|
269
|
+
:email => "cdc@b.com"
|
270
|
+
}
|
271
|
+
url = @oauth.url_for_access_token(@code, params)
|
272
|
+
params.each_pair do |key, value|
|
273
|
+
expect(url).to match(/[\&\?]#{key}=#{CGI.escape value}/)
|
274
|
+
end
|
379
275
|
end
|
276
|
+
end
|
380
277
|
|
381
|
-
|
382
|
-
|
383
|
-
|
278
|
+
describe "#url_for_dialog" do
|
279
|
+
it "builds the base properly" do
|
280
|
+
dialog_type = "my_dialog_type"
|
281
|
+
expect(@oauth.url_for_dialog(dialog_type)).to match(/^https:\/\/#{Koala.config.dialog_host}\/dialog\/#{dialog_type}/)
|
384
282
|
end
|
385
283
|
|
386
|
-
it "
|
387
|
-
|
388
|
-
|
284
|
+
it "includes the api version if specified" do
|
285
|
+
version = Koala.config.api_version = "v.2.2.2.2"
|
286
|
+
dialog_type = "my_dialog_type"
|
287
|
+
expect(@oauth.url_for_dialog(dialog_type)).to match("https:\/\/#{Koala.config.dialog_host}\/#{version}\/dialog\/#{dialog_type}")
|
389
288
|
end
|
390
|
-
end
|
391
|
-
end
|
392
|
-
end
|
393
289
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
290
|
+
it "adds the app_id/client_id to the url" do
|
291
|
+
automatic_params = {:app_id => @app_id, :client_id => @client_id}
|
292
|
+
url = @oauth.url_for_dialog("foo", automatic_params)
|
293
|
+
automatic_params.each_pair do |key, value|
|
294
|
+
# we're slightly simplifying how encode_params works, but for strings/ints, it's okay
|
295
|
+
expect(url).to match(/[\&\?]#{key}=#{CGI.escape value.to_s}/)
|
296
|
+
end
|
400
297
|
end
|
401
298
|
|
402
|
-
it
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
299
|
+
it "includes any additional options as URL parameters, appropriately escaped" do
|
300
|
+
params = {
|
301
|
+
:url => "http://foo.bar?c=2",
|
302
|
+
:email => "cdc@b.com"
|
303
|
+
}
|
304
|
+
url = @oauth.url_for_dialog("friends", params)
|
305
|
+
params.each_pair do |key, value|
|
306
|
+
# we're slightly simplifying how encode_params works, but strings/ints, it's okay
|
307
|
+
expect(url).to match(/[\&\?]#{key}=#{CGI.escape value.to_s}/)
|
308
|
+
end
|
407
309
|
end
|
408
310
|
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
311
|
+
describe "real examples from FB documentation" do
|
312
|
+
# see http://developers.facebook.com/docs/reference/dialogs/
|
313
|
+
# slightly brittle (e.g. if parameter order changes), but still useful
|
314
|
+
it "can generate a send dialog" do
|
315
|
+
url = @oauth.url_for_dialog("send", :name => "People Argue Just to Win", :link => "http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html")
|
316
|
+
expect(url).to match_url("https://www.facebook.com/dialog/send?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
|
317
|
+
end
|
413
318
|
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
319
|
+
it "can generate a feed dialog" do
|
320
|
+
url = @oauth.url_for_dialog("feed", :name => "People Argue Just to Win", :link => "http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html")
|
321
|
+
expect(url).to match_url("https://www.facebook.com/dialog/feed?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
|
322
|
+
end
|
418
323
|
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
324
|
+
it "can generate a oauth dialog" do
|
325
|
+
url = @oauth.url_for_dialog("oauth", :scope => "email", :response_type => "token")
|
326
|
+
expect(url).to match_url("https://www.facebook.com/dialog/oauth?app_id=#{@app_id}&client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}&response_type=token&scope=email")
|
327
|
+
end
|
423
328
|
|
424
|
-
|
425
|
-
|
426
|
-
|
329
|
+
it "can generate a pay dialog" do
|
330
|
+
url = @oauth.url_for_dialog("pay", :order_id => "foo", :credits_purchase => false)
|
331
|
+
expect(url).to match_url("https://www.facebook.com/dialog/pay?app_id=#{@app_id}&client_id=#{@app_id}&order_id=foo&credits_purchase=false&redirect_uri=#{CGI.escape @callback_url}")
|
332
|
+
end
|
427
333
|
end
|
428
|
-
else
|
429
|
-
pending "Some OAuth token exchange tests will not be run since the access token field in facebook_data.yml is blank."
|
430
334
|
end
|
431
335
|
end
|
432
|
-
end
|
433
|
-
|
434
|
-
describe "for fetching access tokens" do
|
435
|
-
describe "#get_access_token_info" do
|
436
|
-
it "uses options[:redirect_uri] if provided" do
|
437
|
-
uri = "foo"
|
438
|
-
expect(Koala).to receive(:make_request).with(anything, hash_including(:redirect_uri => uri), anything, anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
439
|
-
@oauth.get_access_token_info(@code, :redirect_uri => uri)
|
440
|
-
end
|
441
|
-
|
442
|
-
it "uses the redirect_uri used to create the @oauth if no :redirect_uri option is provided" do
|
443
|
-
expect(Koala).to receive(:make_request).with(anything, hash_including(:redirect_uri => @callback_url), anything, anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
444
|
-
@oauth.get_access_token_info(@code)
|
445
|
-
end
|
446
336
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
337
|
+
describe 'for generating a client code' do
|
338
|
+
describe '#generate_client_code' do
|
339
|
+
if KoalaTest.mock_interface? || KoalaTest.oauth_token
|
340
|
+
it 'makes a request using the correct endpoint' do
|
341
|
+
expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
|
342
|
+
@oauth.generate_client_code(KoalaTest.oauth_token)
|
343
|
+
end
|
451
344
|
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
allow(Koala).to receive(:make_request).and_return(
|
459
|
-
Koala::HTTPService::Response.new(
|
460
|
-
200,
|
461
|
-
MultiJson.dump(result),
|
462
|
-
{}
|
463
|
-
)
|
464
|
-
)
|
465
|
-
expect(@oauth.get_access_token_info(@code)).to eq(result)
|
466
|
-
end
|
345
|
+
it 'gets a valid client code returned' do
|
346
|
+
expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
|
347
|
+
result = @oauth.generate_client_code(KoalaTest.oauth_token)
|
348
|
+
expect(result).to be_a(String)
|
349
|
+
expect(result).to eq('fake_client_code')
|
350
|
+
end
|
467
351
|
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
)
|
473
|
-
expect(@oauth.get_access_token_info(@code)).to eq({
|
474
|
-
"access_token" => "foo",
|
475
|
-
"expires_in" => "baz",
|
476
|
-
"machine_id" => "bar"
|
477
|
-
})
|
478
|
-
end
|
352
|
+
it 'raises a BadFacebookResponse error when empty response body is returned' do
|
353
|
+
expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '', {}))
|
354
|
+
expect { @oauth.generate_client_code(KoalaTest.oauth_token) }.to raise_error(Koala::Facebook::BadFacebookResponse)
|
355
|
+
end
|
479
356
|
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
end
|
357
|
+
it 'raises an OAuthTokenRequestError when empty response body is returned' do
|
358
|
+
expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(400, '', {}))
|
359
|
+
expect { @oauth.generate_client_code(KoalaTest.oauth_token) }.to raise_error(Koala::Facebook::OAuthTokenRequestError)
|
360
|
+
end
|
485
361
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
362
|
+
it 'raises a ServerError when empty response body is returned' do
|
363
|
+
expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(500, '', {}))
|
364
|
+
expect { @oauth.generate_client_code(KoalaTest.oauth_token) }.to raise_error(Koala::Facebook::ServerError)
|
365
|
+
end
|
490
366
|
|
491
|
-
|
492
|
-
|
367
|
+
it 'raises a KoalaError when empty response body is returned' do
|
368
|
+
expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"client_code":"should_not_be_returned"}', {}))
|
369
|
+
expect { @oauth.generate_client_code(KoalaTest.oauth_token) }.to raise_error(Koala::KoalaError)
|
370
|
+
end
|
371
|
+
else
|
372
|
+
pending "Some OAuth token exchange tests will not be run since the access token field in facebook_data.yml is blank."
|
493
373
|
end
|
494
374
|
end
|
495
375
|
end
|
496
376
|
|
497
|
-
describe "
|
498
|
-
#
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
end
|
504
|
-
|
505
|
-
if KoalaTest.code
|
506
|
-
it "uses get_access_token_info to get and parse an access token token results" do
|
507
|
-
result = @oauth.get_access_token(@code)
|
508
|
-
expect(result).to be_a(String)
|
377
|
+
describe "for fetching access tokens" do
|
378
|
+
describe "#get_access_token_info" do
|
379
|
+
it "uses options[:redirect_uri] if provided" do
|
380
|
+
uri = "foo"
|
381
|
+
expect(Koala).to receive(:make_request).with(anything, hash_including(:redirect_uri => uri), anything, anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
382
|
+
@oauth.get_access_token_info(@code, :redirect_uri => uri)
|
509
383
|
end
|
510
384
|
|
511
|
-
it "
|
512
|
-
|
513
|
-
|
514
|
-
expect(result).to eq(original["access_token"])
|
385
|
+
it "uses the redirect_uri used to create the @oauth if no :redirect_uri option is provided" do
|
386
|
+
expect(Koala).to receive(:make_request).with(anything, hash_including(:redirect_uri => @callback_url), anything, anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
387
|
+
@oauth.get_access_token_info(@code)
|
515
388
|
end
|
516
389
|
|
517
|
-
it "
|
518
|
-
expect
|
390
|
+
it "makes a GET request" do
|
391
|
+
expect(Koala).to receive(:make_request).with(anything, anything, "get", anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
392
|
+
@oauth.get_access_token_info(@code)
|
519
393
|
end
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
unless KoalaTest.code
|
524
|
-
it "Some OAuth code tests will not be run since the code field in facebook_data.yml is blank."
|
525
|
-
end
|
526
|
-
|
527
|
-
describe "get_app_access_token_info" do
|
528
|
-
it "properly gets and parses an app's access token as a hash" do
|
529
|
-
result = @oauth.get_app_access_token_info
|
530
|
-
expect(result).to be_a(Hash)
|
531
|
-
end
|
532
394
|
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
result = @oauth.get_app_access_token
|
548
|
-
expect(result).to be_a(String)
|
549
|
-
end
|
550
|
-
|
551
|
-
it "returns the access token as a string" do
|
552
|
-
result = @oauth.get_app_access_token
|
553
|
-
original = @oauth.get_app_access_token_info
|
554
|
-
expect(result).to eq(original["access_token"])
|
555
|
-
end
|
556
|
-
|
557
|
-
it "passes on any options provided to make_request" do
|
558
|
-
options = {:a => 2}
|
559
|
-
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
560
|
-
@oauth.get_app_access_token(options)
|
561
|
-
end
|
562
|
-
end
|
563
|
-
|
564
|
-
describe "exchange_access_token_info" do
|
565
|
-
if KoalaTest.mock_interface? || KoalaTest.oauth_token
|
566
|
-
it "properly gets and parses an app's access token as a hash" do
|
567
|
-
result = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
|
568
|
-
expect(result).to be_a(Hash)
|
395
|
+
it "properly decodes JSON results" do
|
396
|
+
result = {
|
397
|
+
"access_token" => "foo",
|
398
|
+
"expires_in" => "baz",
|
399
|
+
"machine_id" => "bar"
|
400
|
+
}
|
401
|
+
allow(Koala).to receive(:make_request).and_return(
|
402
|
+
Koala::HTTPService::Response.new(
|
403
|
+
200,
|
404
|
+
MultiJson.dump(result),
|
405
|
+
{}
|
406
|
+
)
|
407
|
+
)
|
408
|
+
expect(@oauth.get_access_token_info(@code)).to eq(result)
|
569
409
|
end
|
570
410
|
|
571
|
-
it "
|
572
|
-
result =
|
573
|
-
|
411
|
+
it "falls back to URL-style parsing " do
|
412
|
+
result = "access_token=foo&expires_in=baz&machine_id=bar"
|
413
|
+
allow(Koala).to receive(:make_request).and_return(
|
414
|
+
Koala::HTTPService::Response.new(200, result, {})
|
415
|
+
)
|
416
|
+
expect(@oauth.get_access_token_info(@code)).to eq({
|
417
|
+
"access_token" => "foo",
|
418
|
+
"expires_in" => "baz",
|
419
|
+
"machine_id" => "bar"
|
420
|
+
})
|
574
421
|
end
|
575
|
-
else
|
576
|
-
pending "Some OAuth token exchange tests will not be run since the access token field in facebook_data.yml is blank."
|
577
|
-
end
|
578
|
-
|
579
|
-
it "passes on any options provided to make_request" do
|
580
|
-
options = {:a => 2}
|
581
|
-
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
582
|
-
@oauth.exchange_access_token_info(KoalaTest.oauth_token, options)
|
583
|
-
end
|
584
422
|
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
423
|
+
if KoalaTest.code
|
424
|
+
it "properly gets and parses an access token token results into a hash" do
|
425
|
+
result = @oauth.get_access_token_info(@code)
|
426
|
+
expect(result).to be_a(Hash)
|
427
|
+
end
|
589
428
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
expect(@oauth.exchange_access_token(KoalaTest.oauth_token)).to eq(hash["access_token"])
|
595
|
-
end
|
429
|
+
it "properly includes the access token results" do
|
430
|
+
result = @oauth.get_access_token_info(@code)
|
431
|
+
expect(result["access_token"]).to be_truthy
|
432
|
+
end
|
596
433
|
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
434
|
+
it "raises an error when get_access_token is called with a bad code" do
|
435
|
+
expect { @oauth.get_access_token_info("foo") }.to raise_error(Koala::Facebook::OAuthTokenRequestError)
|
436
|
+
end
|
437
|
+
end
|
601
438
|
end
|
602
|
-
end
|
603
439
|
|
604
|
-
|
605
|
-
|
606
|
-
|
440
|
+
describe "#get_access_token" do
|
441
|
+
# TODO refactor these to be proper tests with stubs and tests against real data
|
442
|
+
it "passes on any options provided to make_request" do
|
443
|
+
options = {:a => 2}
|
444
|
+
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
445
|
+
@oauth.get_access_token(@code, options)
|
446
|
+
end
|
607
447
|
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
end
|
448
|
+
if KoalaTest.code
|
449
|
+
it "uses get_access_token_info to get and parse an access token token results" do
|
450
|
+
result = @oauth.get_access_token(@code)
|
451
|
+
expect(result).to be_a(String)
|
452
|
+
end
|
614
453
|
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
454
|
+
it "returns the access token as a string" do
|
455
|
+
result = @oauth.get_access_token(@code)
|
456
|
+
original = @oauth.get_access_token_info(@code)
|
457
|
+
expect(result).to eq(original["access_token"])
|
458
|
+
end
|
620
459
|
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
if KoalaTest.code
|
625
|
-
it "fetches a proper token string from Facebook when given a code" do
|
626
|
-
result = @oauth.send(:fetch_token_string, :code => @code, :redirect_uri => @callback_url)
|
627
|
-
expect(result).to match(/^access_token/)
|
460
|
+
it "raises an error when get_access_token is called with a bad code" do
|
461
|
+
expect { @oauth.get_access_token("foo") }.to raise_error(Koala::Facebook::OAuthTokenRequestError)
|
462
|
+
end
|
628
463
|
end
|
629
|
-
else
|
630
|
-
it "fetch_token_string code test will not be run since the code field in facebook_data.yml is blank."
|
631
464
|
end
|
632
465
|
|
633
|
-
|
634
|
-
|
635
|
-
expect(result).to match(/^access_token/)
|
466
|
+
unless KoalaTest.code
|
467
|
+
it "Some OAuth code tests will not be run since the code field in facebook_data.yml is blank."
|
636
468
|
end
|
637
|
-
end
|
638
|
-
end
|
639
|
-
|
640
|
-
describe "for exchanging session keys" do
|
641
|
-
if KoalaTest.session_key
|
642
|
-
describe "with get_token_info_from_session_keys" do
|
643
|
-
it "gets an array of session keys from Facebook when passed a single key" do
|
644
|
-
result = @oauth.get_tokens_from_session_keys([KoalaTest.session_key])
|
645
|
-
expect(result).to be_an(Array)
|
646
|
-
expect(result.length).to eq(1)
|
647
|
-
end
|
648
469
|
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
expect(result
|
470
|
+
describe "get_app_access_token_info" do
|
471
|
+
it "properly gets and parses an app's access token as a hash" do
|
472
|
+
result = @oauth.get_app_access_token_info
|
473
|
+
expect(result).to be_a(Hash)
|
653
474
|
end
|
654
475
|
|
655
|
-
it "
|
656
|
-
result = @oauth.
|
657
|
-
expect(result[
|
476
|
+
it "includes the access token" do
|
477
|
+
result = @oauth.get_app_access_token_info
|
478
|
+
expect(result["access_token"]).to be_truthy
|
658
479
|
end
|
659
480
|
|
660
|
-
it "
|
661
|
-
|
662
|
-
|
663
|
-
|
481
|
+
it "passes on any options provided to make_request" do
|
482
|
+
options = {:a => 2}
|
483
|
+
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
484
|
+
@oauth.get_app_access_token_info(options)
|
664
485
|
end
|
486
|
+
end
|
665
487
|
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
488
|
+
describe "get_app_access_token" do
|
489
|
+
it "uses get_access_token_info to get and parse an access token token results" do
|
490
|
+
result = @oauth.get_app_access_token
|
491
|
+
expect(result).to be_a(String)
|
670
492
|
end
|
671
493
|
|
672
|
-
it "
|
673
|
-
|
674
|
-
|
494
|
+
it "returns the access token as a string" do
|
495
|
+
result = @oauth.get_app_access_token
|
496
|
+
original = @oauth.get_app_access_token_info
|
497
|
+
expect(result).to eq(original["access_token"])
|
675
498
|
end
|
676
499
|
|
677
500
|
it "passes on any options provided to make_request" do
|
678
501
|
options = {:a => 2}
|
679
|
-
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "
|
680
|
-
@oauth.
|
502
|
+
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
503
|
+
@oauth.get_app_access_token(options)
|
681
504
|
end
|
682
505
|
end
|
683
506
|
|
684
|
-
describe "
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
507
|
+
describe "exchange_access_token_info" do
|
508
|
+
if KoalaTest.mock_interface? || KoalaTest.oauth_token
|
509
|
+
it "properly gets and parses an app's access token as a hash" do
|
510
|
+
result = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
|
511
|
+
expect(result).to be_a(Hash)
|
512
|
+
end
|
513
|
+
|
514
|
+
it "includes the access token" do
|
515
|
+
result = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
|
516
|
+
expect(result["access_token"]).not_to be_nil
|
517
|
+
end
|
518
|
+
else
|
519
|
+
pending "Some OAuth token exchange tests will not be run since the access token field in facebook_data.yml is blank."
|
689
520
|
end
|
690
521
|
|
691
|
-
it "
|
692
|
-
|
693
|
-
|
694
|
-
|
522
|
+
it "passes on any options provided to make_request" do
|
523
|
+
options = {:a => 2}
|
524
|
+
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
525
|
+
@oauth.exchange_access_token_info(KoalaTest.oauth_token, options)
|
695
526
|
end
|
696
527
|
|
697
|
-
it "
|
698
|
-
|
699
|
-
# it should return nil for each of the invalid ones
|
700
|
-
result.each {|r| expect(r).to be_nil}
|
528
|
+
it "raises an error when exchange_access_token_info is called with a bad code" do
|
529
|
+
expect { @oauth.exchange_access_token_info("foo") }.to raise_error(Koala::Facebook::OAuthTokenRequestError)
|
701
530
|
end
|
531
|
+
end
|
702
532
|
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
533
|
+
describe "exchange_access_token" do
|
534
|
+
it "uses get_access_token_info to get and parse an access token token results" do
|
535
|
+
hash = {"access_token" => Time.now.to_i * rand}
|
536
|
+
allow(@oauth).to receive(:exchange_access_token_info).and_return(hash)
|
537
|
+
expect(@oauth.exchange_access_token(KoalaTest.oauth_token)).to eq(hash["access_token"])
|
707
538
|
end
|
708
539
|
|
709
540
|
it "passes on any options provided to make_request" do
|
710
541
|
options = {:a => 2}
|
711
|
-
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "
|
712
|
-
@oauth.
|
542
|
+
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
543
|
+
@oauth.exchange_access_token(KoalaTest.oauth_token, options)
|
713
544
|
end
|
714
545
|
end
|
715
546
|
|
716
|
-
describe "
|
717
|
-
|
718
|
-
|
719
|
-
expect(@oauth).to receive(:get_tokens_from_session_keys).with([key], anything).and_return([])
|
720
|
-
@oauth.get_token_from_session_key(key)
|
721
|
-
end
|
547
|
+
describe "protected methods" do
|
548
|
+
# protected methods
|
549
|
+
# since these are pretty fundamental and pretty testable, we want to test them
|
722
550
|
|
723
|
-
|
724
|
-
|
725
|
-
|
551
|
+
# parse_access_token
|
552
|
+
it "properly parses access token results" do
|
553
|
+
result = @oauth.send(:parse_access_token, @raw_token_string)
|
554
|
+
has_both_parts = result["access_token"] && result["expires"]
|
555
|
+
expect(has_both_parts).to be_truthy
|
726
556
|
end
|
727
557
|
|
728
|
-
it "
|
729
|
-
result = @oauth.
|
730
|
-
|
731
|
-
expect(
|
558
|
+
it "properly parses offline access token results" do
|
559
|
+
result = @oauth.send(:parse_access_token, @raw_offline_access_token_string)
|
560
|
+
has_both_parts = result["access_token"] && !result["expires"]
|
561
|
+
expect(has_both_parts).to be true
|
732
562
|
end
|
733
563
|
|
734
|
-
|
735
|
-
|
736
|
-
|
564
|
+
# fetch_token_string
|
565
|
+
# somewhat duplicative with the tests for get_access_token and get_app_access_token
|
566
|
+
# but no harm in thoroughness
|
567
|
+
if KoalaTest.code
|
568
|
+
it "fetches a proper token string from Facebook when given a code" do
|
569
|
+
result = @oauth.send(:fetch_token_string, :code => @code, :redirect_uri => @callback_url)
|
570
|
+
expect(result).to match(/^access_token/)
|
571
|
+
end
|
572
|
+
else
|
573
|
+
it "fetch_token_string code test will not be run since the code field in facebook_data.yml is blank."
|
737
574
|
end
|
738
575
|
|
739
|
-
it "
|
740
|
-
|
741
|
-
expect(
|
742
|
-
@oauth.get_token_from_session_key("", options)
|
576
|
+
it "fetches a proper token string from Facebook when asked for the app token" do
|
577
|
+
result = @oauth.send(:fetch_token_string, {:grant_type => 'client_credentials'}, true)
|
578
|
+
expect(result).to match(/^access_token/)
|
743
579
|
end
|
744
580
|
end
|
745
|
-
else
|
746
|
-
it "Session key exchange tests will not be run since the session key in facebook_data.yml is blank."
|
747
581
|
end
|
748
|
-
end
|
749
582
|
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
583
|
+
describe "for parsing signed requests" do
|
584
|
+
# the signed request code is ported directly from Facebook
|
585
|
+
# so we only need to test at a high level that it works
|
586
|
+
it "throws an error if the algorithm is unsupported" do
|
587
|
+
allow(MultiJson).to receive(:load).and_return("algorithm" => "my fun algorithm")
|
588
|
+
expect { @oauth.parse_signed_request(@signed_request) }.to raise_error
|
589
|
+
end
|
757
590
|
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
591
|
+
it "throws an error if the signature is invalid" do
|
592
|
+
allow(OpenSSL::HMAC).to receive(:hexdigest).and_return("i'm an invalid signature")
|
593
|
+
expect { @oauth.parse_signed_request(@signed_request) }.to raise_error
|
594
|
+
end
|
762
595
|
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
596
|
+
it "throws an error if the signature string is empty" do
|
597
|
+
# this occasionally happens due to Facebook error
|
598
|
+
expect { @oauth.parse_signed_request("") }.to raise_error
|
599
|
+
expect { @oauth.parse_signed_request("abc-def") }.to raise_error
|
600
|
+
end
|
768
601
|
|
769
|
-
|
770
|
-
|
771
|
-
|
602
|
+
it "properly parses requests" do
|
603
|
+
@oauth = Koala::Facebook::OAuth.new(@app_id, @secret || @app_secret)
|
604
|
+
expect(@oauth.parse_signed_request(@signed_params)).to eq(@signed_params_result)
|
605
|
+
end
|
772
606
|
end
|
773
607
|
end
|
774
|
-
|
775
608
|
end # describe
|