koala 1.2.0beta1 → 1.2.1

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.
@@ -30,21 +30,21 @@ describe "Koala::Facebook::OAuth" do
30
30
  end
31
31
 
32
32
  # initialization
33
- it "should properly initialize" do
33
+ it "properly initializes" do
34
34
  @oauth.should
35
35
  end
36
36
 
37
- it "should properly set attributes" do
37
+ it "properly sets attributes" do
38
38
  (@oauth.app_id == @app_id &&
39
39
  @oauth.app_secret == @secret &&
40
40
  @oauth.oauth_callback_url == @callback_url).should be_true
41
41
  end
42
42
 
43
- it "should properly initialize without a callback_url" do
43
+ it "properly initializes without a callback_url" do
44
44
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
45
45
  end
46
46
 
47
- it "should properly set attributes without a callback URL" do
47
+ it "properly sets attributes without a callback URL" do
48
48
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
49
49
  (@oauth.app_id == @app_id &&
50
50
  @oauth.app_secret == @secret &&
@@ -53,60 +53,158 @@ describe "Koala::Facebook::OAuth" do
53
53
 
54
54
  describe "for cookie parsing" do
55
55
  describe "get_user_info_from_cookies" do
56
- it "should properly parse valid cookies" do
57
- result = @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["valid_cookies"])
58
- result.should be_a(Hash)
59
- end
56
+ context "for signed cookies" do
57
+ before :each do
58
+ # we don't actually want to make requests to Facebook to redeem the code
59
+ @cookie = KoalaTest.oauth_test_data["valid_signed_cookies"]
60
+ @token = "my token"
61
+ @oauth.stub(:get_access_token_info).and_return("access_token" => @token)
62
+ end
63
+
64
+ it "parses valid cookies" do
65
+ result = @oauth.get_user_info_from_cookies(@cookie)
66
+ result.should be_a(Hash)
67
+ end
60
68
 
61
- it "should return all the cookie components from valid cookie string" do
62
- cookie_data = KoalaTest.oauth_test_data["valid_cookies"]
63
- parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
64
- number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
65
- parsing_results.length.should == number_of_components
66
- end
69
+ it "returns all the components in the signed request" do
70
+ result = @oauth.get_user_info_from_cookies(@cookie)
71
+ @oauth.parse_signed_request(@cookie.values.first).each_pair do |k, v|
72
+ result[k].should == v
73
+ end
74
+ end
75
+
76
+ it "makes a request to Facebook to redeem the code if present" do
77
+ code = "foo"
78
+ @oauth.stub(:parse_signed_request).and_return({"code" => code})
79
+ @oauth.should_receive(:get_access_token_info).with(code, anything)
80
+ @oauth.get_user_info_from_cookies(@cookie)
81
+ end
67
82
 
68
- it "should properly parse valid offline access cookies (e.g. no expiration)" do
69
- result = @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["offline_access_cookies"])
70
- result["uid"].should
71
- end
83
+ it "sets the code redemption redirect_uri to ''" do
84
+ @oauth.should_receive(:get_access_token_info).with(anything, :redirect_uri => '')
85
+ @oauth.get_user_info_from_cookies(@cookie)
86
+ end
72
87
 
73
- it "should return all the cookie components from offline access cookies" do
74
- cookie_data = KoalaTest.oauth_test_data["offline_access_cookies"]
75
- parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
76
- number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
77
- parsing_results.length.should == number_of_components
88
+ context "if the code is missing" do
89
+ it "doesn't make a request to Facebook" do
90
+ @oauth.stub(:parse_signed_request).and_return({})
91
+ @oauth.should_receive(:get_access_token_info).never
92
+ @oauth.get_user_info_from_cookies(@cookie)
93
+ end
94
+
95
+ it "returns nil" do
96
+ @oauth.stub(:parse_signed_request).and_return({})
97
+ @oauth.get_user_info_from_cookies(@cookie).should be_nil
98
+ end
99
+ end
100
+
101
+ context "if the code is present" do
102
+ it "adds the access_token into the hash" do
103
+ @oauth.get_user_info_from_cookies(@cookie)["access_token"].should == @token
104
+ end
105
+
106
+ it "returns nil if the call to FB fails" do
107
+ @oauth.stub(:get_access_token_info).and_return(nil)
108
+ @oauth.get_user_info_from_cookies(@cookie).should be_nil
109
+ end
110
+ end
111
+
112
+ it "doesn't parse invalid cookies" do
113
+ # make an invalid string by replacing some values
114
+ bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
115
+ result = @oauth.get_user_info_from_cookies(bad_cookie_hash)
116
+ result.should be_nil
117
+ end
78
118
  end
119
+
120
+ context "for unsigned cookies" do
121
+ it "properly parses valid cookies" do
122
+ result = @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["valid_cookies"])
123
+ result.should be_a(Hash)
124
+ end
79
125
 
80
- it "shouldn't parse expired cookies" do
81
- result = @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["expired_cookies"])
82
- result.should be_nil
83
- end
126
+ it "returns all the cookie components from valid cookie string" do
127
+ cookie_data = KoalaTest.oauth_test_data["valid_cookies"]
128
+ parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
129
+ number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
130
+ parsing_results.length.should == number_of_components
131
+ end
132
+
133
+ it "properly parses valid offline access cookies (e.g. no expiration)" do
134
+ result = @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["offline_access_cookies"])
135
+ result["uid"].should
136
+ end
137
+
138
+ it "returns all the cookie components from offline access cookies" do
139
+ cookie_data = KoalaTest.oauth_test_data["offline_access_cookies"]
140
+ parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
141
+ number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
142
+ parsing_results.length.should == number_of_components
143
+ end
84
144
 
85
- it "shouldn't parse invalid cookies" do
86
- # make an invalid string by replacing some values
87
- bad_cookie_hash = KoalaTest.oauth_test_data["valid_cookies"].inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
88
- result = @oauth.get_user_info_from_cookies(bad_cookie_hash)
89
- result.should be_nil
145
+ it "doesn't parse expired cookies" do
146
+ new_time = @time.to_i * 2
147
+ @time.stub(:to_i).and_return(new_time)
148
+ @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["valid_cookies"]).should be_nil
149
+ end
150
+
151
+ it "doesn't parse invalid cookies" do
152
+ # make an invalid string by replacing some values
153
+ bad_cookie_hash = KoalaTest.oauth_test_data["valid_cookies"].inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
154
+ result = @oauth.get_user_info_from_cookies(bad_cookie_hash)
155
+ result.should be_nil
156
+ end
90
157
  end
91
158
  end
92
159
 
93
160
  describe "get_user_from_cookies" do
94
- it "should use get_user_info_from_cookies to parse the cookies" do
95
- data = KoalaTest.oauth_test_data["valid_cookies"]
96
- @oauth.should_receive(:get_user_info_from_cookies).with(data).and_return({})
97
- @oauth.get_user_from_cookies(data)
98
- end
161
+ describe "for signed cookies" do
162
+ before :each do
163
+ # we don't actually want to make requests to Facebook to redeem the code
164
+ @cookie = KoalaTest.oauth_test_data["valid_signed_cookies"]
165
+ @oauth.stub(:get_access_token_info).and_return("access_token" => "my token")
166
+ end
99
167
 
100
- it "should use return a string if the cookies are valid" do
101
- result = @oauth.get_user_from_cookies(KoalaTest.oauth_test_data["valid_cookies"])
102
- result.should be_a(String)
168
+ it "uses get_user_info_from_cookies to parse the cookies" do
169
+ @oauth.should_receive(:get_user_info_from_cookies).with(@cookie).and_return({})
170
+ @oauth.get_user_from_cookies(@cookie)
171
+ end
172
+
173
+ it "uses return the token string if the cookies are valid" do
174
+ result = @oauth.get_user_from_cookies(@cookie)
175
+ result.should == "2905623" # the user who generated the original test cookie
176
+ end
177
+
178
+ it "returns nil if the cookies are invalid" do
179
+ # make an invalid string by replacing some values
180
+ bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
181
+ result = @oauth.get_user_from_cookies(bad_cookie_hash)
182
+ result.should be_nil
183
+ end
103
184
  end
185
+
186
+ describe "for unsigned cookies" do
187
+ before :each do
188
+ # we don't actually want to make requests to Facebook to redeem the code
189
+ @cookie = KoalaTest.oauth_test_data["valid_cookies"]
190
+ end
191
+
192
+ it "uses get_user_info_from_cookies to parse the cookies" do
193
+ @oauth.should_receive(:get_user_info_from_cookies).with(@cookie).and_return({})
194
+ @oauth.get_user_from_cookies(@cookie)
195
+ end
104
196
 
105
- it "should return nil if the cookies are invalid" do
106
- # make an invalid string by replacing some values
107
- bad_cookie_hash = KoalaTest.oauth_test_data["valid_cookies"].inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
108
- result = @oauth.get_user_from_cookies(bad_cookie_hash)
109
- result.should be_nil
197
+ it "uses return a string if the cookies are valid" do
198
+ result = @oauth.get_user_from_cookies(@cookie)
199
+ result.should == "2905623" # the user who generated the original test cookie
200
+ end
201
+
202
+ it "returns nil if the cookies are invalid" do
203
+ # make an invalid string by replacing some values
204
+ bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
205
+ result = @oauth.get_user_from_cookies(bad_cookie_hash)
206
+ result.should be_nil
207
+ end
110
208
  end
111
209
  end
112
210
  end
@@ -117,42 +215,42 @@ describe "Koala::Facebook::OAuth" do
117
215
 
118
216
  describe "for OAuth codes" do
119
217
  # url_for_oauth_code
120
- it "should generate a properly formatted OAuth code URL with the default values" do
218
+ it "generates a properly formatted OAuth code URL with the default values" do
121
219
  url = @oauth.url_for_oauth_code
122
220
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}"
123
221
  end
124
222
 
125
- it "should generate a properly formatted OAuth code URL when a callback is given" do
223
+ it "generates a properly formatted OAuth code URL when a callback is given" do
126
224
  callback = "foo.com"
127
225
  url = @oauth.url_for_oauth_code(:callback => callback)
128
226
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}"
129
227
  end
130
228
 
131
- it "should generate a properly formatted OAuth code URL when permissions are requested as a string" do
229
+ it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
132
230
  permissions = "publish_stream,read_stream"
133
231
  url = @oauth.url_for_oauth_code(:permissions => permissions)
134
232
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}&scope=#{permissions}"
135
233
  end
136
234
 
137
- it "should generate a properly formatted OAuth code URL when permissions are requested as a string" do
235
+ it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
138
236
  permissions = ["publish_stream", "read_stream"]
139
237
  url = @oauth.url_for_oauth_code(:permissions => permissions)
140
238
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}&scope=#{permissions.join(",")}"
141
239
  end
142
240
 
143
- it "should generate a properly formatted OAuth code URL when both permissions and callback are provided" do
241
+ it "generates a properly formatted OAuth code URL when both permissions and callback are provided" do
144
242
  permissions = "publish_stream,read_stream"
145
243
  callback = "foo.com"
146
244
  url = @oauth.url_for_oauth_code(:callback => callback, :permissions => permissions)
147
245
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}&scope=#{permissions}"
148
246
  end
149
247
 
150
- it "should generate a properly formatted OAuth code URL when a display is given as a string" do
248
+ it "generates a properly formatted OAuth code URL when a display is given as a string" do
151
249
  url = @oauth.url_for_oauth_code(:display => "page")
152
250
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}&display=page"
153
251
  end
154
252
 
155
- it "should raise an exception if no callback is given in initialization or the call" do
253
+ it "raises an exception if no callback is given in initialization or the call" do
156
254
  oauth2 = Koala::Facebook::OAuth.new(@app_id, @secret)
157
255
  lambda { oauth2.url_for_oauth_code }.should raise_error(ArgumentError)
158
256
  end
@@ -165,12 +263,12 @@ describe "Koala::Facebook::OAuth" do
165
263
  end
166
264
 
167
265
  # url_for_access_token
168
- it "should generate a properly formatted OAuth token URL when provided a code" do
266
+ it "generates a properly formatted OAuth token URL when provided a code" do
169
267
  url = @oauth.url_for_access_token(@code)
170
268
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{@callback_url}&client_secret=#{@secret}&code=#{@code}"
171
269
  end
172
270
 
173
- it "should generate a properly formatted OAuth token URL when provided a callback" do
271
+ it "generates a properly formatted OAuth token URL when provided a callback" do
174
272
  callback = "foo.com"
175
273
  url = @oauth.url_for_access_token(@code, :callback => callback)
176
274
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{callback}&client_secret=#{@secret}&code=#{@code}"
@@ -179,61 +277,82 @@ describe "Koala::Facebook::OAuth" do
179
277
  end
180
278
 
181
279
  describe "for fetching access tokens" do
182
- if KoalaTest.code
183
- describe "get_access_token_info" do
184
- it "should properly get and parse an access token token results into a hash" do
280
+ describe ".get_access_token_info" do
281
+ it "uses options[:redirect_uri] if provided" do
282
+ uri = "foo"
283
+ Koala.should_receive(:make_request).with(anything, hash_including(:redirect_uri => uri), anything, anything).and_return(Koala::Response.new(200, "", {}))
284
+ @oauth.get_access_token_info(@code, :redirect_uri => uri)
285
+ end
286
+
287
+ it "uses the redirect_uri used to create the @oauth if no :redirect_uri option is provided" do
288
+ Koala.should_receive(:make_request).with(anything, hash_including(:redirect_uri => @callback_url), anything, anything).and_return(Koala::Response.new(200, "", {}))
289
+ @oauth.get_access_token_info(@code)
290
+ end
291
+
292
+ it "makes a GET request" do
293
+ Koala.should_receive(:make_request).with(anything, anything, "get", anything).and_return(Koala::Response.new(200, "", {}))
294
+ @oauth.get_access_token_info(@code)
295
+ end
296
+
297
+ if KoalaTest.code
298
+ it "properly gets and parses an access token token results into a hash" do
185
299
  result = @oauth.get_access_token_info(@code)
186
300
  result.should be_a(Hash)
187
301
  end
188
302
 
189
- it "should properly include the access token results" do
303
+ it "properly includes the access token results" do
190
304
  result = @oauth.get_access_token_info(@code)
191
305
  result["access_token"].should
192
306
  end
193
-
194
- it "should raise an error when get_access_token is called with a bad code" do
307
+
308
+ it "raises an error when get_access_token is called with a bad code" do
195
309
  lambda { @oauth.get_access_token_info("foo") }.should raise_error(Koala::Facebook::APIError)
196
310
  end
197
311
  end
312
+ end
313
+
314
+ describe ".get_access_token" do
315
+ # TODO refactor these to be proper tests with stubs and tests against real data
316
+ it "passes on any options provided to make_request" do
317
+ options = {:a => 2}
318
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
319
+ @oauth.get_access_token(@code, options)
320
+ end
198
321
 
199
- describe "get_access_token" do
200
- it "should use get_access_token_info to get and parse an access token token results" do
322
+ if KoalaTest.code
323
+ it "uses get_access_token_info to get and parse an access token token results" do
201
324
  result = @oauth.get_access_token(@code)
202
325
  result.should be_a(String)
203
326
  end
204
327
 
205
- it "should return the access token as a string" do
328
+ it "returns the access token as a string" do
206
329
  result = @oauth.get_access_token(@code)
207
330
  original = @oauth.get_access_token_info(@code)
208
331
  result.should == original["access_token"]
209
332
  end
210
333
 
211
- it "should raise an error when get_access_token is called with a bad code" do
334
+ it "raises an error when get_access_token is called with a bad code" do
212
335
  lambda { @oauth.get_access_token("foo") }.should raise_error(Koala::Facebook::APIError)
213
336
  end
214
-
215
- it "should pass on any options provided to make_request" do
216
- options = {:a => 2}
217
- Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
218
- @oauth.get_access_token(@code, options)
219
- end
220
337
  end
221
- else
222
- it "OAuth code tests will not be run since the code field in facebook_data.yml is blank."
338
+ end
339
+
340
+ unless KoalaTest.code
341
+ it "Some OAuth code tests will not be run since the code field in facebook_data.yml is blank."
223
342
  end
224
343
 
225
344
  describe "get_app_access_token_info" do
226
- it "should properly get and parse an app's access token as a hash" do
345
+ it "properly gets and parses an app's access token as a hash" do
227
346
  result = @oauth.get_app_access_token_info
228
347
  result.should be_a(Hash)
229
348
  end
230
349
 
231
- it "should include the access token" do
350
+ it "includes the access token" do
232
351
  result = @oauth.get_app_access_token_info
233
352
  result["access_token"].should
234
353
  end
235
354
 
236
- it "should pass on any options provided to make_request" do
355
+ it "passes on any options provided to make_request" do
237
356
  options = {:a => 2}
238
357
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
239
358
  @oauth.get_app_access_token_info(options)
@@ -241,18 +360,18 @@ describe "Koala::Facebook::OAuth" do
241
360
  end
242
361
 
243
362
  describe "get_app_acess_token" do
244
- it "should use get_access_token_info to get and parse an access token token results" do
363
+ it "uses get_access_token_info to get and parse an access token token results" do
245
364
  result = @oauth.get_app_access_token
246
365
  result.should be_a(String)
247
366
  end
248
367
 
249
- it "should return the access token as a string" do
368
+ it "returns the access token as a string" do
250
369
  result = @oauth.get_app_access_token
251
370
  original = @oauth.get_app_access_token_info
252
371
  result.should == original["access_token"]
253
372
  end
254
373
 
255
- it "should pass on any options provided to make_request" do
374
+ it "passes on any options provided to make_request" do
256
375
  options = {:a => 2}
257
376
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
258
377
  @oauth.get_app_access_token(options)
@@ -265,13 +384,13 @@ describe "Koala::Facebook::OAuth" do
265
384
  # since these are pretty fundamental and pretty testable, we want to test them
266
385
 
267
386
  # parse_access_token
268
- it "should properly parse access token results" do
387
+ it "properly parses access token results" do
269
388
  result = @oauth.send(:parse_access_token, @raw_token_string)
270
389
  has_both_parts = result["access_token"] && result["expires"]
271
390
  has_both_parts.should
272
391
  end
273
392
 
274
- it "should properly parse offline access token results" do
393
+ it "properly parses offline access token results" do
275
394
  result = @oauth.send(:parse_access_token, @raw_offline_access_token_string)
276
395
  has_both_parts = result["access_token"] && !result["expires"]
277
396
  has_both_parts.should
@@ -281,7 +400,7 @@ describe "Koala::Facebook::OAuth" do
281
400
  # somewhat duplicative with the tests for get_access_token and get_app_access_token
282
401
  # but no harm in thoroughness
283
402
  if KoalaTest.code
284
- it "should fetch a proper token string from Facebook when given a code" do
403
+ it "fetches a proper token string from Facebook when given a code" do
285
404
  result = @oauth.send(:fetch_token_string, :code => @code, :redirect_uri => @callback_url)
286
405
  result.should =~ /^access_token/
287
406
  end
@@ -289,7 +408,7 @@ describe "Koala::Facebook::OAuth" do
289
408
  it "fetch_token_string code test will not be run since the code field in facebook_data.yml is blank."
290
409
  end
291
410
 
292
- it "should fetch a proper token string from Facebook when asked for the app token" do
411
+ it "fetches a proper token string from Facebook when asked for the app token" do
293
412
  result = @oauth.send(:fetch_token_string, {:type => 'client_cred'}, true)
294
413
  result.should =~ /^access_token/
295
414
  end
@@ -299,41 +418,41 @@ describe "Koala::Facebook::OAuth" do
299
418
  describe "for exchanging session keys" do
300
419
  if KoalaTest.session_key
301
420
  describe "with get_token_info_from_session_keys" do
302
- it "should get an array of session keys from Facebook when passed a single key" do
421
+ it "gets an array of session keys from Facebook when passed a single key" do
303
422
  result = @oauth.get_tokens_from_session_keys([KoalaTest.session_key])
304
423
  result.should be_an(Array)
305
424
  result.length.should == 1
306
425
  end
307
426
 
308
- it "should get an array of session keys from Facebook when passed multiple keys" do
427
+ it "gets an array of session keys from Facebook when passed multiple keys" do
309
428
  result = @oauth.get_tokens_from_session_keys(@multiple_session_keys)
310
429
  result.should be_an(Array)
311
430
  result.length.should == 2
312
431
  end
313
432
 
314
- it "should return the original hashes" do
433
+ it "returns the original hashes" do
315
434
  result = @oauth.get_token_info_from_session_keys(@multiple_session_keys)
316
435
  result[0].should be_a(Hash)
317
436
  end
318
437
 
319
- it "should properly handle invalid session keys" do
438
+ it "properly handles invalid session keys" do
320
439
  result = @oauth.get_token_info_from_session_keys(["foo", "bar"])
321
440
  #it should return nil for each of the invalid ones
322
441
  result.each {|r| r.should be_nil}
323
442
  end
324
443
 
325
- it "should properly handle a mix of valid and invalid session keys" do
444
+ it "properly handles a mix of valid and invalid session keys" do
326
445
  result = @oauth.get_token_info_from_session_keys(["foo"].concat(@multiple_session_keys))
327
446
  # it should return nil for each of the invalid ones
328
447
  result.each_with_index {|r, index| index > 0 ? r.should(be_a(Hash)) : r.should(be_nil)}
329
448
  end
330
449
 
331
- it "should throw an APIError if Facebook returns an empty body (as happens for instance when the API breaks)" do
450
+ it "throws an APIError if Facebook returns an empty body (as happens for instance when the API breaks)" do
332
451
  @oauth.should_receive(:fetch_token_string).and_return("")
333
452
  lambda { @oauth.get_token_info_from_session_keys(@multiple_session_keys) }.should raise_error(Koala::Facebook::APIError)
334
453
  end
335
454
 
336
- it "should pass on any options provided to make_request" do
455
+ it "passes on any options provided to make_request" do
337
456
  options = {:a => 2}
338
457
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
339
458
  @oauth.get_token_info_from_session_keys([], options)
@@ -341,31 +460,31 @@ describe "Koala::Facebook::OAuth" do
341
460
  end
342
461
 
343
462
  describe "with get_tokens_from_session_keys" do
344
- it "should call get_token_info_from_session_keys" do
463
+ it "calls get_token_info_from_session_keys" do
345
464
  args = @multiple_session_keys
346
465
  @oauth.should_receive(:get_token_info_from_session_keys).with(args, anything).and_return([])
347
466
  @oauth.get_tokens_from_session_keys(args)
348
467
  end
349
468
 
350
- it "should return an array of strings" do
469
+ it "returns an array of strings" do
351
470
  args = @multiple_session_keys
352
471
  result = @oauth.get_tokens_from_session_keys(args)
353
472
  result.each {|r| r.should be_a(String) }
354
473
  end
355
474
 
356
- it "should properly handle invalid session keys" do
475
+ it "properly handles invalid session keys" do
357
476
  result = @oauth.get_tokens_from_session_keys(["foo", "bar"])
358
477
  # it should return nil for each of the invalid ones
359
478
  result.each {|r| r.should be_nil}
360
479
  end
361
480
 
362
- it "should properly handle a mix of valid and invalid session keys" do
481
+ it "properly handles a mix of valid and invalid session keys" do
363
482
  result = @oauth.get_tokens_from_session_keys(["foo"].concat(@multiple_session_keys))
364
483
  # it should return nil for each of the invalid ones
365
484
  result.each_with_index {|r, index| index > 0 ? r.should(be_a(String)) : r.should(be_nil)}
366
485
  end
367
486
 
368
- it "should pass on any options provided to make_request" do
487
+ it "passes on any options provided to make_request" do
369
488
  options = {:a => 2}
370
489
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
371
490
  @oauth.get_tokens_from_session_keys([], options)
@@ -373,29 +492,29 @@ describe "Koala::Facebook::OAuth" do
373
492
  end
374
493
 
375
494
  describe "get_token_from_session_key" do
376
- it "should call get_tokens_from_session_keys when the get_token_from_session_key is called" do
495
+ it "calls get_tokens_from_session_keys when the get_token_from_session_key is called" do
377
496
  key = KoalaTest.session_key
378
497
  @oauth.should_receive(:get_tokens_from_session_keys).with([key], anything).and_return([])
379
498
  @oauth.get_token_from_session_key(key)
380
499
  end
381
500
 
382
- it "should get back the access token string from get_token_from_session_key" do
501
+ it "gets back the access token string from get_token_from_session_key" do
383
502
  result = @oauth.get_token_from_session_key(KoalaTest.session_key)
384
503
  result.should be_a(String)
385
504
  end
386
505
 
387
- it "should be the first value in the array" do
506
+ it "returns the first value in the array" do
388
507
  result = @oauth.get_token_from_session_key(KoalaTest.session_key)
389
508
  array = @oauth.get_tokens_from_session_keys([KoalaTest.session_key])
390
509
  result.should == array[0]
391
510
  end
392
511
 
393
- it "should properly handle an invalid session key" do
512
+ it "properly handles an invalid session key" do
394
513
  result = @oauth.get_token_from_session_key("foo")
395
514
  result.should be_nil
396
515
  end
397
516
 
398
- it "should pass on any options provided to make_request" do
517
+ it "passes on any options provided to make_request" do
399
518
  options = {:a => 2}
400
519
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
401
520
  @oauth.get_token_from_session_key("", options)
@@ -409,15 +528,21 @@ describe "Koala::Facebook::OAuth" do
409
528
  describe "for parsing signed requests" do
410
529
  # the signed request code is ported directly from Facebook
411
530
  # so we only need to test at a high level that it works
412
- it "should throw an error if the algorithm is unsupported" do
531
+ it "throws an error if the algorithm is unsupported" do
413
532
  MultiJson.stub(:decode).and_return("algorithm" => "my fun algorithm")
414
533
  lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
415
534
  end
416
535
 
417
- it "should throw an error if the signature is invalid" do
536
+ it "throws an error if the signature is invalid" do
418
537
  OpenSSL::HMAC.stub!(:hexdigest).and_return("i'm an invalid signature")
419
538
  lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
420
539
  end
540
+
541
+ it "throws an error if the signature string is empty" do
542
+ # this occasionally happens due to Facebook error
543
+ lambda { @oauth.parse_signed_request("") }.should raise_error
544
+ lambda { @oauth.parse_signed_request("abc-def") }.should raise_error
545
+ end
421
546
 
422
547
  it "properly parses requests" do
423
548
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret || @app_secret)
@@ -425,4 +550,4 @@ describe "Koala::Facebook::OAuth" do
425
550
  end
426
551
  end
427
552
 
428
- end # describe
553
+ end # describe
@@ -19,23 +19,4 @@ describe "Koala::Facebook::RestAPI" do
19
19
  api = Koala::Facebook::RestAPI.new("token")
20
20
  end
21
21
  end
22
-
23
- context "without an access token" do
24
- before :each do
25
- @api = Koala::Facebook::API.new
26
- end
27
-
28
- it_should_behave_like "Koala RestAPI"
29
- it_should_behave_like "Koala RestAPI without an access token"
30
- end
31
-
32
- context "with an access token" do
33
- before :each do
34
- @api = Koala::Facebook::API.new(@token)
35
- end
36
-
37
- it_should_behave_like "Koala RestAPI"
38
- it_should_behave_like "Koala RestAPI with an access token"
39
- end
40
-
41
22
  end