koala 1.0.0.beta2.1 → 1.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG +6 -1
- data/Gemfile +3 -0
- data/Rakefile +13 -14
- data/koala.gemspec +35 -20
- data/lib/koala.rb +8 -17
- data/lib/koala/graph_api.rb +2 -2
- data/lib/koala/http_services.rb +32 -27
- data/lib/koala/test_users.rb +4 -4
- data/lib/koala/uploadable_io.rb +1 -1
- data/spec/cases/api_base_spec.rb +101 -0
- data/spec/cases/graph_and_rest_api_spec.rb +31 -0
- data/spec/cases/graph_api_spec.rb +25 -0
- data/spec/{koala/http_services/http_service_tests.rb → cases/http_services/http_service_spec.rb} +8 -5
- data/spec/cases/http_services/net_http_service_spec.rb +350 -0
- data/spec/cases/http_services/typhoeus_service_spec.rb +144 -0
- data/spec/cases/oauth_spec.rb +374 -0
- data/spec/cases/realtime_updates_spec.rb +184 -0
- data/spec/cases/rest_api_spec.rb +25 -0
- data/spec/{koala/test_users/test_users_tests.rb → cases/test_users_spec.rb} +34 -29
- data/spec/cases/uploadable_io_spec.rb +151 -0
- data/spec/{koala/assets → fixtures}/beach.jpg +0 -0
- data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +5 -5
- data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +311 -311
- data/spec/spec_helper.rb +18 -0
- data/spec/support/graph_api_shared_examples.rb +424 -0
- data/spec/{koala → support}/live_testing_data_helper.rb +39 -42
- data/spec/{mock_http_service.rb → support/mock_http_service.rb} +94 -94
- data/spec/{koala/rest_api/rest_api_tests.rb → support/rest_api_shared_examples.rb} +43 -0
- data/spec/support/setup_mocks_or_live.rb +52 -0
- data/spec/support/uploadable_io_shared_examples.rb +76 -0
- metadata +109 -53
- data/init.rb +0 -2
- data/spec/koala/api_base_tests.rb +0 -102
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -14
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -16
- data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -65
- data/spec/koala/graph_api/graph_api_tests.rb +0 -85
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -194
- data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
- data/spec/koala/http_services/net_http_service_tests.rb +0 -339
- data/spec/koala/http_services/typhoeus_service_tests.rb +0 -162
- data/spec/koala/oauth/oauth_tests.rb +0 -372
- data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -25
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -38
- data/spec/koala/uploadable_io/uploadable_io_tests.rb +0 -246
- data/spec/koala_spec.rb +0 -18
- data/spec/koala_spec_helper.rb +0 -74
- data/spec/koala_spec_without_mocks.rb +0 -19
@@ -1,372 +0,0 @@
|
|
1
|
-
class FacebookOAuthTests < Test::Unit::TestCase
|
2
|
-
describe "Koala OAuth tests" do
|
3
|
-
before :each do
|
4
|
-
# make the relevant test data easily accessible
|
5
|
-
@oauth_data = $testing_data["oauth_test_data"]
|
6
|
-
@app_id = @oauth_data["app_id"]
|
7
|
-
@secret = @oauth_data["secret"]
|
8
|
-
@code = @oauth_data["code"]
|
9
|
-
@callback_url = @oauth_data["callback_url"]
|
10
|
-
@raw_token_string = @oauth_data["raw_token_string"]
|
11
|
-
@raw_offline_access_token_string = @oauth_data["raw_offline_access_token_string"]
|
12
|
-
|
13
|
-
# for signed requests (http://developers.facebook.com/docs/authentication/canvas/encryption_proposal)
|
14
|
-
@signed_params = @oauth_data["signed_params"]
|
15
|
-
@signed_params_result = @oauth_data["signed_params_result"]
|
16
|
-
|
17
|
-
# this should expanded to cover all variables
|
18
|
-
raise Exception, "Must supply app data to run FacebookOAuthTests!" unless @app_id && @secret && @callback_url &&
|
19
|
-
@code && @raw_token_string &&
|
20
|
-
@raw_offline_access_token_string
|
21
|
-
|
22
|
-
@oauth = Koala::Facebook::OAuth.new(@app_id, @secret, @callback_url)
|
23
|
-
|
24
|
-
@time = Time.now
|
25
|
-
Time.stub!(:now).and_return(@time)
|
26
|
-
@time.stub!(:to_i).and_return(1273363199)
|
27
|
-
end
|
28
|
-
|
29
|
-
# initialization
|
30
|
-
it "should properly initialize" do
|
31
|
-
@oauth.should
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should properly set attributes" do
|
35
|
-
(@oauth.app_id == @app_id &&
|
36
|
-
@oauth.app_secret == @secret &&
|
37
|
-
@oauth.oauth_callback_url == @callback_url).should be_true
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should properly initialize without a callback_url" do
|
41
|
-
@oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should properly set attributes without a callback URL" do
|
45
|
-
@oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
|
46
|
-
(@oauth.app_id == @app_id &&
|
47
|
-
@oauth.app_secret == @secret &&
|
48
|
-
@oauth.oauth_callback_url == nil).should be_true
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "for cookie parsing" do
|
52
|
-
describe "get_user_info_from_cookies" do
|
53
|
-
it "should properly parse valid cookies" do
|
54
|
-
result = @oauth.get_user_info_from_cookies(@oauth_data["valid_cookies"])
|
55
|
-
result.should be_a(Hash)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should return all the cookie components from valid cookie string" do
|
59
|
-
cookie_data = @oauth_data["valid_cookies"]
|
60
|
-
parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
|
61
|
-
number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
|
62
|
-
parsing_results.length.should == number_of_components
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should properly parse valid offline access cookies (e.g. no expiration)" do
|
66
|
-
result = @oauth.get_user_info_from_cookies(@oauth_data["offline_access_cookies"])
|
67
|
-
result["uid"].should
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should return all the cookie components from offline access cookies" do
|
71
|
-
cookie_data = @oauth_data["offline_access_cookies"]
|
72
|
-
parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
|
73
|
-
number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
|
74
|
-
parsing_results.length.should == number_of_components
|
75
|
-
end
|
76
|
-
|
77
|
-
it "shouldn't parse expired cookies" do
|
78
|
-
result = @oauth.get_user_info_from_cookies(@oauth_data["expired_cookies"])
|
79
|
-
result.should be_nil
|
80
|
-
end
|
81
|
-
|
82
|
-
it "shouldn't parse invalid cookies" do
|
83
|
-
# make an invalid string by replacing some values
|
84
|
-
bad_cookie_hash = @oauth_data["valid_cookies"].inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
|
85
|
-
result = @oauth.get_user_info_from_cookies(bad_cookie_hash)
|
86
|
-
result.should be_nil
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "get_user_from_cookies" do
|
91
|
-
it "should use get_user_info_from_cookies to parse the cookies" do
|
92
|
-
data = @oauth_data["valid_cookies"]
|
93
|
-
@oauth.should_receive(:get_user_info_from_cookies).with(data).and_return({})
|
94
|
-
@oauth.get_user_from_cookies(data)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should use return a string if the cookies are valid" do
|
98
|
-
result = @oauth.get_user_from_cookies(@oauth_data["valid_cookies"])
|
99
|
-
result.should be_a(String)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should return nil if the cookies are invalid" do
|
103
|
-
# make an invalid string by replacing some values
|
104
|
-
bad_cookie_hash = @oauth_data["valid_cookies"].inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
|
105
|
-
result = @oauth.get_user_from_cookies(bad_cookie_hash)
|
106
|
-
result.should be_nil
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# OAuth URLs
|
112
|
-
|
113
|
-
describe "for URL generation" do
|
114
|
-
|
115
|
-
describe "for OAuth codes" do
|
116
|
-
# url_for_oauth_code
|
117
|
-
it "should generate a properly formatted OAuth code URL with the default values" do
|
118
|
-
url = @oauth.url_for_oauth_code
|
119
|
-
url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}"
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should generate a properly formatted OAuth code URL when a callback is given" do
|
123
|
-
callback = "foo.com"
|
124
|
-
url = @oauth.url_for_oauth_code(:callback => callback)
|
125
|
-
url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}"
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should generate a properly formatted OAuth code URL when permissions are requested as a string" do
|
129
|
-
permissions = "publish_stream,read_stream"
|
130
|
-
url = @oauth.url_for_oauth_code(:permissions => permissions)
|
131
|
-
url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}&scope=#{permissions}"
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should generate a properly formatted OAuth code URL when permissions are requested as a string" do
|
135
|
-
permissions = ["publish_stream", "read_stream"]
|
136
|
-
url = @oauth.url_for_oauth_code(:permissions => permissions)
|
137
|
-
url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{@callback_url}&scope=#{permissions.join(",")}"
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should generate a properly formatted OAuth code URL when both permissions and callback are provided" do
|
141
|
-
permissions = "publish_stream,read_stream"
|
142
|
-
callback = "foo.com"
|
143
|
-
url = @oauth.url_for_oauth_code(:callback => callback, :permissions => permissions)
|
144
|
-
url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}&scope=#{permissions}"
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should raise an exception if no callback is given in initialization or the call" do
|
148
|
-
oauth2 = Koala::Facebook::OAuth.new(@app_id, @secret)
|
149
|
-
lambda { oauth2.url_for_oauth_code }.should raise_error(ArgumentError)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe "for access token URLs" do
|
154
|
-
|
155
|
-
# url_for_access_token
|
156
|
-
it "should generate a properly formatted OAuth token URL when provided a code" do
|
157
|
-
url = @oauth.url_for_access_token(@code)
|
158
|
-
url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{@callback_url}&client_secret=#{@secret}&code=#{@code}"
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should generate a properly formatted OAuth token URL when provided a callback" do
|
162
|
-
callback = "foo.com"
|
163
|
-
url = @oauth.url_for_access_token(@code, :callback => callback)
|
164
|
-
url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{callback}&client_secret=#{@secret}&code=#{@code}"
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "for fetching access tokens" do
|
170
|
-
describe "get_access_token_info" do
|
171
|
-
it "should properly get and parse an access token token results into a hash" do
|
172
|
-
result = @oauth.get_access_token_info(@code)
|
173
|
-
result.should be_a(Hash)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should properly include the access token results" do
|
177
|
-
result = @oauth.get_access_token_info(@code)
|
178
|
-
result["access_token"].should
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should raise an error when get_access_token is called with a bad code" do
|
182
|
-
lambda { @oauth.get_access_token_info("foo") }.should raise_error(Koala::Facebook::APIError)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
describe "get_access_token" do
|
187
|
-
it "should use get_access_token_info to get and parse an access token token results" do
|
188
|
-
result = @oauth.get_access_token(@code)
|
189
|
-
result.should be_a(String)
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should return the access token as a string" do
|
193
|
-
result = @oauth.get_access_token(@code)
|
194
|
-
original = @oauth.get_access_token_info(@code)
|
195
|
-
result.should == original["access_token"]
|
196
|
-
end
|
197
|
-
|
198
|
-
it "should raise an error when get_access_token is called with a bad code" do
|
199
|
-
lambda { @oauth.get_access_token("foo") }.should raise_error(Koala::Facebook::APIError)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
describe "get_app_access_token_info" do
|
204
|
-
it "should properly get and parse an app's access token as a hash" do
|
205
|
-
result = @oauth.get_app_access_token_info
|
206
|
-
result.should be_a(Hash)
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should include the access token" do
|
210
|
-
result = @oauth.get_app_access_token_info
|
211
|
-
result["access_token"].should
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe "get_app_acess_token" do
|
216
|
-
it "should use get_access_token_info to get and parse an access token token results" do
|
217
|
-
result = @oauth.get_app_access_token
|
218
|
-
result.should be_a(String)
|
219
|
-
end
|
220
|
-
|
221
|
-
it "should return the access token as a string" do
|
222
|
-
result = @oauth.get_app_access_token
|
223
|
-
original = @oauth.get_app_access_token_info
|
224
|
-
result.should == original["access_token"]
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe "protected methods" do
|
229
|
-
|
230
|
-
# protected methods
|
231
|
-
# since these are pretty fundamental and pretty testable, we want to test them
|
232
|
-
|
233
|
-
# parse_access_token
|
234
|
-
it "should properly parse access token results" do
|
235
|
-
result = @oauth.send(:parse_access_token, @raw_token_string)
|
236
|
-
has_both_parts = result["access_token"] && result["expires"]
|
237
|
-
has_both_parts.should
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should properly parse offline access token results" do
|
241
|
-
result = @oauth.send(:parse_access_token, @raw_offline_access_token_string)
|
242
|
-
has_both_parts = result["access_token"] && !result["expires"]
|
243
|
-
has_both_parts.should
|
244
|
-
end
|
245
|
-
|
246
|
-
# fetch_token_string
|
247
|
-
# somewhat duplicative with the tests for get_access_token and get_app_access_token
|
248
|
-
# but no harm in thoroughness
|
249
|
-
it "should fetch a proper token string from Facebook when given a code" do
|
250
|
-
result = @oauth.send(:fetch_token_string, :code => @code, :redirect_uri => @callback_url)
|
251
|
-
result.should =~ /^access_token/
|
252
|
-
end
|
253
|
-
|
254
|
-
it "should fetch a proper token string from Facebook when asked for the app token" do
|
255
|
-
result = @oauth.send(:fetch_token_string, {:type => 'client_cred'}, true)
|
256
|
-
result.should =~ /^access_token/
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
describe "for exchanging session keys" do
|
262
|
-
describe "with get_token_info_from_session_keys" do
|
263
|
-
it "should get an array of session keys from Facebook when passed a single key" do
|
264
|
-
result = @oauth.get_tokens_from_session_keys([@oauth_data["session_key"]])
|
265
|
-
result.should be_an(Array)
|
266
|
-
result.length.should == 1
|
267
|
-
end
|
268
|
-
|
269
|
-
it "should get an array of session keys from Facebook when passed multiple keys" do
|
270
|
-
result = @oauth.get_tokens_from_session_keys(@oauth_data["multiple_session_keys"])
|
271
|
-
result.should be_an(Array)
|
272
|
-
result.length.should == 2
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should return the original hashes" do
|
276
|
-
result = @oauth.get_token_info_from_session_keys(@oauth_data["multiple_session_keys"])
|
277
|
-
result[0].should be_a(Hash)
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should properly handle invalid session keys" do
|
281
|
-
result = @oauth.get_token_info_from_session_keys(["foo", "bar"])
|
282
|
-
#it should return nil for each of the invalid ones
|
283
|
-
result.each {|r| r.should be_nil}
|
284
|
-
end
|
285
|
-
|
286
|
-
it "should properly handle a mix of valid and invalid session keys" do
|
287
|
-
result = @oauth.get_token_info_from_session_keys(["foo"].concat(@oauth_data["multiple_session_keys"]))
|
288
|
-
# it should return nil for each of the invalid ones
|
289
|
-
result.each_with_index {|r, index| index > 0 ? r.should(be_a(Hash)) : r.should(be_nil)}
|
290
|
-
end
|
291
|
-
|
292
|
-
it "should throw an APIError if Facebook returns an empty body (as happens for instance when the API breaks)" do
|
293
|
-
@oauth.should_receive(:fetch_token_string).and_return("")
|
294
|
-
lambda { @oauth.get_token_info_from_session_keys(@oauth_data["multiple_session_keys"]) }.should raise_error(Koala::Facebook::APIError)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
describe "with get_tokens_from_session_keys" do
|
299
|
-
it "should call get_token_info_from_session_keys" do
|
300
|
-
args = @oauth_data["multiple_session_keys"]
|
301
|
-
@oauth.should_receive(:get_token_info_from_session_keys).with(args).and_return([])
|
302
|
-
@oauth.get_tokens_from_session_keys(args)
|
303
|
-
end
|
304
|
-
|
305
|
-
it "should return an array of strings" do
|
306
|
-
args = @oauth_data["multiple_session_keys"]
|
307
|
-
result = @oauth.get_tokens_from_session_keys(args)
|
308
|
-
result.each {|r| r.should be_a(String) }
|
309
|
-
end
|
310
|
-
|
311
|
-
it "should properly handle invalid session keys" do
|
312
|
-
result = @oauth.get_tokens_from_session_keys(["foo", "bar"])
|
313
|
-
# it should return nil for each of the invalid ones
|
314
|
-
result.each {|r| r.should be_nil}
|
315
|
-
end
|
316
|
-
|
317
|
-
it "should properly handle a mix of valid and invalid session keys" do
|
318
|
-
result = @oauth.get_tokens_from_session_keys(["foo"].concat(@oauth_data["multiple_session_keys"]))
|
319
|
-
# it should return nil for each of the invalid ones
|
320
|
-
result.each_with_index {|r, index| index > 0 ? r.should(be_a(String)) : r.should(be_nil)}
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
describe "get_token_from_session_key" do
|
325
|
-
it "should call get_tokens_from_session_keys when the get_token_from_session_key is called" do
|
326
|
-
key = @oauth_data["session_key"]
|
327
|
-
@oauth.should_receive(:get_tokens_from_session_keys).with([key]).and_return([])
|
328
|
-
@oauth.get_token_from_session_key(key)
|
329
|
-
end
|
330
|
-
|
331
|
-
it "should get back the access token string from get_token_from_session_key" do
|
332
|
-
result = @oauth.get_token_from_session_key(@oauth_data["session_key"])
|
333
|
-
result.should be_a(String)
|
334
|
-
end
|
335
|
-
|
336
|
-
it "should be the first value in the array" do
|
337
|
-
result = @oauth.get_token_from_session_key(@oauth_data["session_key"])
|
338
|
-
array = @oauth.get_tokens_from_session_keys([@oauth_data["session_key"]])
|
339
|
-
result.should == array[0]
|
340
|
-
end
|
341
|
-
|
342
|
-
it "should properly handle an invalid session key" do
|
343
|
-
result = @oauth.get_token_from_session_key("foo")
|
344
|
-
result.should be_nil
|
345
|
-
end
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
describe "for parsing signed requests" do
|
350
|
-
# the signed request code comes directly from Facebook
|
351
|
-
# so we only need to test at a high level that it works
|
352
|
-
# signed params refers to http://developers.facebook.com/docs/authentication/canvas
|
353
|
-
# signed request refers to http://developers.facebook.com/docs/authentication/canvas/encryption_proposal
|
354
|
-
it "should throw an error if the algorithm is unsupported" do
|
355
|
-
JSON.stub!(:parse).and_return("algorithm" => "my fun algorithm")
|
356
|
-
lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
|
357
|
-
end
|
358
|
-
|
359
|
-
it "should throw an error if the signature is invalid" do
|
360
|
-
OpenSSL::HMAC.stub!(:hexdigest).and_return("i'm an invalid signature")
|
361
|
-
lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
|
362
|
-
end
|
363
|
-
|
364
|
-
it "properly parses requests" do
|
365
|
-
@oauth = Koala::Facebook::OAuth.new(@app_id, @secret || @app_secret)
|
366
|
-
@oauth.parse_signed_request(@signed_params).should == @signed_params_result
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
end # describe
|
371
|
-
|
372
|
-
end #class
|
@@ -1,187 +0,0 @@
|
|
1
|
-
class FacebookRealtimeUpdatesTests < Test::Unit::TestCase
|
2
|
-
include Koala
|
3
|
-
|
4
|
-
describe "Koala RealtimeUpdates" do
|
5
|
-
before :all do
|
6
|
-
# get oauth data
|
7
|
-
@oauth_data = $testing_data["oauth_test_data"]
|
8
|
-
@app_id = @oauth_data["app_id"]
|
9
|
-
@secret = @oauth_data["secret"]
|
10
|
-
@callback_url = @oauth_data["callback_url"]
|
11
|
-
@app_access_token = @oauth_data["app_access_token"]
|
12
|
-
|
13
|
-
# check OAuth data
|
14
|
-
unless @app_id && @secret && @callback_url && @app_access_token
|
15
|
-
raise Exception, "Must supply OAuth app id, secret, app_access_token, and callback to run live subscription tests!"
|
16
|
-
end
|
17
|
-
|
18
|
-
# get subscription data
|
19
|
-
@subscription_data = $testing_data["subscription_test_data"]
|
20
|
-
@verify_token = @subscription_data["verify_token"]
|
21
|
-
@challenge_data = @subscription_data["challenge_data"]
|
22
|
-
@subscription_path = @subscription_data["subscription_path"]
|
23
|
-
|
24
|
-
# check subscription data
|
25
|
-
unless @verify_token && @challenge_data && @subscription_path
|
26
|
-
raise Exception, "Must supply verify_token and equivalent challenge_data to run live subscription tests!"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "when initializing" do
|
31
|
-
# basic initialization
|
32
|
-
it "should initialize properly with an app_id and an app_access_token" do
|
33
|
-
updates = Facebook::RealtimeUpdates.new(:app_id => @app_id, :app_access_token => @app_access_token)
|
34
|
-
updates.should be_a(Facebook::RealtimeUpdates)
|
35
|
-
end
|
36
|
-
|
37
|
-
# attributes
|
38
|
-
it "should allow read access to app_id, app_access_token, and secret" do
|
39
|
-
updates = Facebook::RealtimeUpdates.new(:app_id => @app_id, :app_access_token => @app_access_token)
|
40
|
-
# this should not throw errors
|
41
|
-
updates.app_id && updates.app_access_token && updates.secret
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should not allow write access to app_id" do
|
45
|
-
updates = Facebook::RealtimeUpdates.new(:app_id => @app_id, :app_access_token => @app_access_token)
|
46
|
-
# this should not throw errors
|
47
|
-
lambda { updates.app_id = 2 }.should raise_error(NoMethodError)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should not allow write access to app_access_token" do
|
51
|
-
updates = Facebook::RealtimeUpdates.new(:app_id => @app_id, :app_access_token => @app_access_token)
|
52
|
-
# this should not throw errors
|
53
|
-
lambda { updates.app_access_token = 2 }.should raise_error(NoMethodError)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should not allow write access to secret" do
|
57
|
-
updates = Facebook::RealtimeUpdates.new(:app_id => @app_id, :app_access_token => @app_access_token)
|
58
|
-
# this should not throw errors
|
59
|
-
lambda { updates.secret = 2 }.should raise_error(NoMethodError)
|
60
|
-
end
|
61
|
-
|
62
|
-
# init with secret / fetching the token
|
63
|
-
it "should initialize properly with an app_id and a secret" do
|
64
|
-
updates = Facebook::RealtimeUpdates.new(:app_id => @app_id, :secret => @secret)
|
65
|
-
updates.should be_a(Facebook::RealtimeUpdates)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should fetch an app_token from Facebook when provided an app_id and a secret" do
|
69
|
-
updates = Facebook::RealtimeUpdates.new(:app_id => @app_id, :secret => @secret)
|
70
|
-
updates.app_access_token.should_not be_nil
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should use the OAuth class to fetch a token when provided an app_id and a secret" do
|
74
|
-
oauth = Facebook::OAuth.new(@app_id, @secret)
|
75
|
-
token = oauth.get_app_access_token
|
76
|
-
oauth.should_receive(:get_app_access_token).and_return(token)
|
77
|
-
Facebook::OAuth.should_receive(:new).with(@app_id, @secret).and_return(oauth)
|
78
|
-
updates = Facebook::RealtimeUpdates.new(:app_id => @app_id, :secret => @secret)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "when used" do
|
83
|
-
before :each do
|
84
|
-
@updates = Facebook::RealtimeUpdates.new(:app_id => @app_id, :secret => @secret)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should send a subscription request to a valid server" do
|
88
|
-
result = @updates.subscribe("user", "name", @subscription_path, @verify_token)
|
89
|
-
result.should be_true
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should send a subscription request to a valid server" do
|
93
|
-
result = @updates.subscribe("user", "name", @subscription_path, @verify_token)
|
94
|
-
result.should be_true
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should send a subscription request to an invalid path on a valid server" do
|
98
|
-
lambda { result = @updates.subscribe("user", "name", @subscription_path + "foo", @verify_token) }.should raise_exception(Koala::Facebook::APIError)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should fail to send a subscription request to an invalid server" do
|
102
|
-
lambda { @updates.subscribe("user", "name", "foo", @verify_token) }.should raise_exception(Koala::Facebook::APIError)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should unsubscribe a valid individual object successfully" do
|
106
|
-
@updates.unsubscribe("user").should be_true
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should unsubscribe all subscriptions successfully" do
|
110
|
-
@updates.unsubscribe.should be_true
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should fail when an invalid object is provided to unsubscribe" do
|
114
|
-
lambda { @updates.unsubscribe("kittens") }.should raise_error(Koala::Facebook::APIError)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should is subscriptions properly" do
|
118
|
-
@updates.list_subscriptions.should be_a(Array)
|
119
|
-
end
|
120
|
-
end # describe "when used"
|
121
|
-
|
122
|
-
describe "when meeting challenge" do
|
123
|
-
it "should return false if hub.mode isn't subscribe" do
|
124
|
-
params = {'hub.mode' => 'not subscribe'}
|
125
|
-
Facebook::RealtimeUpdates.meet_challenge(params).should be_false
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should return false if not given a verify_token or block" do
|
129
|
-
params = {'hub.mode' => 'subscribe'}
|
130
|
-
Facebook::RealtimeUpdates.meet_challenge(params).should be_false
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "and mode is 'subscribe'" do
|
134
|
-
before(:each) do
|
135
|
-
@params = {'hub.mode' => 'subscribe'}
|
136
|
-
end
|
137
|
-
|
138
|
-
describe "and a token is given" do
|
139
|
-
before(:each) do
|
140
|
-
@token = 'token'
|
141
|
-
@params['hub.verify_token'] = @token
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should return false if the given verify token doesn't match" do
|
145
|
-
Facebook::RealtimeUpdates.meet_challenge(@params, @token + '1').should be_false
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should return the challenge if the given verify token matches" do
|
149
|
-
@params['hub.challenge'] = 'challenge val'
|
150
|
-
Facebook::RealtimeUpdates.meet_challenge(@params, @token).should == @params['hub.challenge']
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe "and a block is given" do
|
155
|
-
it "should give the block the token as a parameter" do
|
156
|
-
Facebook::RealtimeUpdates.meet_challenge(@params)do |token|
|
157
|
-
token.should == @token
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should return false if the given block return false" do
|
162
|
-
Facebook::RealtimeUpdates.meet_challenge(@params)do |token|
|
163
|
-
false
|
164
|
-
end.should be_false
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should return false if the given block returns nil" do
|
168
|
-
Facebook::RealtimeUpdates.meet_challenge(@params)do |token|
|
169
|
-
nil
|
170
|
-
end.should be_false
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should return the challenge if the given block returns true" do
|
174
|
-
@params['hub.challenge'] = 'challenge val'
|
175
|
-
Facebook::RealtimeUpdates.meet_challenge(@params) do |token|
|
176
|
-
true
|
177
|
-
end.should be_true
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
end # describe "and mode is subscribe"
|
182
|
-
|
183
|
-
end # describe "when meeting challenge"
|
184
|
-
|
185
|
-
end # describe
|
186
|
-
|
187
|
-
end #class
|