koala 2.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +32 -0
- data/Gemfile +5 -3
- data/ISSUE_TEMPLATE +25 -0
- data/PULL_REQUEST_TEMPLATE +11 -0
- data/changelog.md +161 -4
- data/code_of_conduct.md +64 -12
- data/koala.gemspec +5 -1
- data/lib/koala/api/batch_operation.rb +3 -6
- data/lib/koala/api/{graph_api.rb → graph_api_methods.rb} +29 -104
- data/lib/koala/api/graph_batch_api.rb +112 -65
- data/lib/koala/api/graph_collection.rb +19 -12
- data/lib/koala/api/graph_error_checker.rb +4 -3
- data/lib/koala/api.rb +65 -26
- data/lib/koala/configuration.rb +56 -0
- data/lib/koala/errors.rb +22 -2
- data/lib/koala/http_service/request.rb +133 -0
- data/lib/koala/http_service/response.rb +6 -4
- data/lib/koala/http_service/uploadable_io.rb +0 -5
- data/lib/koala/http_service.rb +29 -76
- data/lib/koala/oauth.rb +8 -8
- data/lib/koala/realtime_updates.rb +26 -21
- data/lib/koala/test_users.rb +9 -8
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +7 -9
- data/readme.md +83 -109
- data/spec/cases/api_spec.rb +176 -69
- data/spec/cases/configuration_spec.rb +11 -0
- data/spec/cases/error_spec.rb +16 -3
- data/spec/cases/graph_api_batch_spec.rb +75 -44
- data/spec/cases/graph_api_spec.rb +15 -29
- data/spec/cases/graph_collection_spec.rb +47 -34
- data/spec/cases/graph_error_checker_spec.rb +31 -2
- data/spec/cases/http_service/request_spec.rb +250 -0
- data/spec/cases/http_service/response_spec.rb +24 -0
- data/spec/cases/http_service_spec.rb +126 -286
- data/spec/cases/koala_spec.rb +7 -5
- data/spec/cases/oauth_spec.rb +41 -2
- data/spec/cases/realtime_updates_spec.rb +51 -13
- data/spec/cases/test_users_spec.rb +56 -2
- data/spec/cases/uploadable_io_spec.rb +31 -31
- data/spec/fixtures/cat.m4v +0 -0
- data/spec/fixtures/facebook_data.yml +4 -6
- data/spec/fixtures/mock_facebook_responses.yml +41 -78
- data/spec/fixtures/vcr_cassettes/app_test_accounts.yml +97 -0
- data/spec/integration/graph_collection_spec.rb +8 -5
- data/spec/spec_helper.rb +2 -2
- data/spec/support/graph_api_shared_examples.rb +152 -337
- data/spec/support/koala_test.rb +11 -13
- data/spec/support/mock_http_service.rb +11 -14
- data/spec/support/uploadable_io_shared_examples.rb +4 -4
- metadata +47 -48
- data/.autotest +0 -12
- data/.travis.yml +0 -17
- data/Guardfile +0 -6
- data/autotest/discover.rb +0 -1
- data/lib/koala/api/rest_api.rb +0 -135
- data/lib/koala/http_service/multipart_request.rb +0 -41
- data/spec/cases/multipart_request_spec.rb +0 -65
- data/spec/support/rest_api_shared_examples.rb +0 -168
@@ -16,32 +16,31 @@ describe Koala::HTTPService do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "DEFAULT_MIDDLEWARE" do
|
19
|
-
|
20
|
-
|
21
|
-
allow(@builder).to receive(:request)
|
22
|
-
allow(@builder).to receive(:adapter)
|
23
|
-
allow(@builder).to receive(:use)
|
24
|
-
end
|
19
|
+
class FakeBuilder
|
20
|
+
attr_reader :requests, :uses, :adapters
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
def use(arg)
|
23
|
+
@uses ||= []
|
24
|
+
@uses << arg
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
def request(arg)
|
28
|
+
@requests ||= []
|
29
|
+
@requests << arg
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
def adapter(arg)
|
33
|
+
@adapters ||= []
|
34
|
+
@adapters << arg
|
35
|
+
end
|
38
36
|
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
let(:builder) { FakeBuilder.new }
|
39
|
+
|
40
|
+
it "adds the right default middleware" do
|
41
|
+
Koala::HTTPService::DEFAULT_MIDDLEWARE.call(builder)
|
42
|
+
expect(builder.requests).to eq([:multipart, :url_encoded])
|
43
|
+
expect(builder.adapters).to eq([Faraday.default_adapter])
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
@@ -52,10 +51,6 @@ describe Koala::HTTPService do
|
|
52
51
|
expect(defaults[:graph_server]).to eq("graph.facebook.com")
|
53
52
|
end
|
54
53
|
|
55
|
-
it "defines the rest server" do
|
56
|
-
expect(defaults[:rest_server]).to eq("api.facebook.com")
|
57
|
-
end
|
58
|
-
|
59
54
|
it "defines the dialog host" do
|
60
55
|
expect(defaults[:dialog_host]).to eq("www.facebook.com")
|
61
56
|
end
|
@@ -73,86 +68,21 @@ describe Koala::HTTPService do
|
|
73
68
|
end
|
74
69
|
end
|
75
70
|
|
76
|
-
describe "server" do
|
77
|
-
describe "with no options" do
|
78
|
-
it "returns the REST server if options[:rest_api]" do
|
79
|
-
expect(Koala::HTTPService.server(:rest_api => true)).to eq(
|
80
|
-
"http://#{Koala.config.rest_server}"
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "returns the graph server if !options[:rest_api]" do
|
85
|
-
expect(Koala::HTTPService.server(:rest_api => false)).to eq(
|
86
|
-
"http://#{Koala.config.graph_server}"
|
87
|
-
)
|
88
|
-
expect(Koala::HTTPService.server({})).to eq(
|
89
|
-
"http://#{Koala.config.graph_server}"
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
context "with use_ssl" do
|
94
|
-
it "includes https" do
|
95
|
-
expect(Koala::HTTPService.server(use_ssl: true)).to eq(
|
96
|
-
"https://#{Koala.config.graph_server}"
|
97
|
-
)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "with options[:beta]" do
|
103
|
-
before :each do
|
104
|
-
@options = {:beta => true}
|
105
|
-
end
|
106
|
-
|
107
|
-
it "returns the beta REST server if options[:rest_api]" do
|
108
|
-
server = Koala::HTTPService.server(@options.merge(:rest_api => true))
|
109
|
-
expect(server).to match(Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, ".beta.facebook")))
|
110
|
-
end
|
111
|
-
|
112
|
-
it "returns the beta rest server if !options[:rest_api]" do
|
113
|
-
server = Koala::HTTPService.server(@options)
|
114
|
-
expect(server).to match(Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, ".beta.facebook")))
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "with options[:video]" do
|
119
|
-
before :each do
|
120
|
-
@options = {:video => true}
|
121
|
-
end
|
122
|
-
|
123
|
-
it "returns the REST video server if options[:rest_api]" do
|
124
|
-
server = Koala::HTTPService.server(@options.merge(:rest_api => true))
|
125
|
-
expect(server).to match(Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, "-video.facebook")))
|
126
|
-
end
|
127
|
-
|
128
|
-
it "returns the graph video server if !options[:rest_api]" do
|
129
|
-
server = Koala::HTTPService.server(@options)
|
130
|
-
expect(server).to match(Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, "-video.facebook")))
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
71
|
describe ".encode_params" do
|
136
72
|
it "returns an empty string if param_hash evaluates to false" do
|
137
73
|
expect(Koala::HTTPService.encode_params(nil)).to eq('')
|
138
74
|
end
|
139
75
|
|
140
76
|
it "converts values to JSON if the value is not a String" do
|
141
|
-
|
142
|
-
not_a_string = 'not_a_string'
|
143
|
-
allow(not_a_string).to receive(:is_a?).and_return(false)
|
144
|
-
expect(MultiJson).to receive(:dump).with(not_a_string).and_return(val)
|
145
|
-
|
146
|
-
string = "hi"
|
77
|
+
not_a_string = {not_a_string: 2}
|
147
78
|
|
148
79
|
args = {
|
149
|
-
|
150
|
-
string => string
|
80
|
+
:arg => not_a_string,
|
151
81
|
}
|
152
82
|
|
153
83
|
result = Koala::HTTPService.encode_params(args)
|
154
84
|
expect(result.split('&').find do |key_and_val|
|
155
|
-
key_and_val.match("
|
85
|
+
key_and_val.match("arg=#{CGI.escape not_a_string.to_json}")
|
156
86
|
end).to be_truthy
|
157
87
|
end
|
158
88
|
|
@@ -185,244 +115,154 @@ describe Koala::HTTPService do
|
|
185
115
|
end
|
186
116
|
|
187
117
|
describe ".make_request" do
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
@mock_headers_hash = double({:value => "headers hash"})
|
192
|
-
@mock_http_response = double("Faraday Response", :status => 200, :headers => @mock_headers_hash, :body => @mock_body)
|
193
|
-
|
194
|
-
@mock_connection = double("Faraday connection")
|
195
|
-
allow(@mock_connection).to receive(:get).and_return(@mock_http_response)
|
196
|
-
allow(@mock_connection).to receive(:post).and_return(@mock_http_response)
|
197
|
-
allow(Faraday).to receive(:new).and_return(@mock_connection)
|
198
|
-
end
|
199
|
-
|
200
|
-
describe "creating the Faraday connection" do
|
201
|
-
it "creates a Faraday connection using the server" do
|
202
|
-
server = "foo"
|
203
|
-
allow(Koala::HTTPService).to receive(:server).and_return(server)
|
204
|
-
expect(Faraday).to receive(:new).with(server, anything).and_return(@mock_connection)
|
205
|
-
Koala::HTTPService.make_request("anything", {}, "anything")
|
206
|
-
end
|
207
|
-
|
208
|
-
it "merges Koala::HTTPService.http_options into the request params" do
|
209
|
-
http_options = {:proxy => "http://user:password@example.org/", :request => { :timeout => 3 }}
|
210
|
-
Koala::HTTPService.http_options = http_options
|
211
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(http_options)).and_return(@mock_connection)
|
212
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
213
|
-
end
|
118
|
+
let(:mock_body) { "a body" }
|
119
|
+
let(:mock_headers_hash) { double(value: "headers hash") }
|
120
|
+
let(:mock_http_response) { double("Faraday Response", status: 200, headers: mock_headers_hash, body: mock_body) }
|
214
121
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
220
|
-
end
|
122
|
+
let(:verb) { "get" }
|
123
|
+
let(:options) { {} }
|
124
|
+
let(:args) { {"an" => :arg } }
|
125
|
+
let(:request) { Koala::HTTPService::Request.new(path: "/foo", verb: verb, args: args, options: options) }
|
221
126
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
127
|
+
shared_examples_for :making_a_request do
|
128
|
+
before :each do
|
129
|
+
allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(mock_http_response)
|
130
|
+
allow_any_instance_of(Faraday::Connection).to receive(:post).and_return(mock_http_response)
|
226
131
|
end
|
227
132
|
|
228
|
-
it "
|
229
|
-
|
230
|
-
|
231
|
-
|
133
|
+
it "makes a Faraday request appropriately" do
|
134
|
+
expect_any_instance_of(Faraday::Connection).to receive(verb) do |instance, path, post_params|
|
135
|
+
expect(path).to eq(request.path)
|
136
|
+
expect(post_params).to eq(request.post_args)
|
137
|
+
expect(instance.params).to eq(request.options[:params])
|
138
|
+
expect(instance.url_prefix).to eq(URI.parse(request.server))
|
232
139
|
|
233
|
-
|
234
|
-
|
235
|
-
end
|
140
|
+
mock_http_response
|
141
|
+
end
|
236
142
|
|
237
|
-
|
238
|
-
options = {:use_ssl => false}
|
239
|
-
allow(Koala::HTTPService).to receive(:http_options).and_return(:use_ssl => false)
|
240
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => {:verify => true})).and_return(@mock_connection)
|
241
|
-
Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get", options)
|
143
|
+
Koala::HTTPService.make_request(request)
|
242
144
|
end
|
243
145
|
|
244
|
-
it "
|
245
|
-
|
246
|
-
|
247
|
-
|
146
|
+
it "returns the right response" do
|
147
|
+
response = Koala::HTTPService.make_request(request)
|
148
|
+
expect(response.status).to eq(mock_http_response.status)
|
149
|
+
expect(response.headers).to eq(mock_http_response.headers)
|
150
|
+
expect(response.body).to eq(mock_http_response.body)
|
248
151
|
|
249
|
-
it "allows you to set other verify modes if you really want" do
|
250
|
-
options = {:ssl => {:verify => :foo}}
|
251
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(options)).and_return(@mock_connection)
|
252
|
-
Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get", options)
|
253
152
|
end
|
254
153
|
|
255
|
-
it "
|
256
|
-
|
257
|
-
|
154
|
+
it "logs verb, url and params to debug" do
|
155
|
+
log_message = "#{verb.upcase}: #{request.path} params: #{request.raw_args.inspect}"
|
156
|
+
expect(Koala::Utils.logger).to receive(:debug).with("STARTED => #{log_message}")
|
157
|
+
expect(Koala::Utils.logger).to receive(:debug).with("FINISHED => #{log_message}")
|
258
158
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
@headers = {}
|
263
|
-
end
|
264
|
-
end
|
159
|
+
Koala::HTTPService.make_request(request)
|
160
|
+
end
|
161
|
+
end
|
265
162
|
|
266
|
-
|
267
|
-
|
163
|
+
context "for gets" do
|
164
|
+
it_should_behave_like :making_a_request
|
165
|
+
end
|
268
166
|
|
269
|
-
|
270
|
-
|
167
|
+
# we don't need to test delete and put since those are translated into posts
|
168
|
+
context "for posts" do
|
169
|
+
let(:verb) { "post" }
|
271
170
|
|
272
|
-
|
171
|
+
it_should_behave_like :making_a_request
|
172
|
+
end
|
273
173
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
end
|
174
|
+
context "for JSON requests" do
|
175
|
+
let(:verb) { "post" }
|
176
|
+
let(:options) { {format: :json} }
|
278
177
|
|
279
|
-
it "
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
178
|
+
it "makes a Faraday request appropriately" do
|
179
|
+
expect_any_instance_of(Faraday::Connection).to receive(verb) do |instance, path, &block|
|
180
|
+
faraday_request = Faraday::Request.new
|
181
|
+
faraday_request.headers = {}
|
182
|
+
block.call(faraday_request)
|
183
|
+
expect(faraday_request.path).to eq(request.path)
|
184
|
+
expect(faraday_request.body).to eq(request.post_args.to_json)
|
185
|
+
expect(faraday_request.headers).to include("Content-Type" => "application/json")
|
286
186
|
|
287
|
-
|
288
|
-
|
289
|
-
stub_const("Koala::HTTPService::DEFAULT_MIDDLEWARE", block)
|
290
|
-
allow(Koala::HTTPService).to receive(:faraday_middleware).and_return(nil)
|
291
|
-
expect(Faraday).to receive(:new).with(anything, anything, &block).and_return(@mock_connection)
|
292
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
293
|
-
end
|
187
|
+
mock_http_response
|
188
|
+
end
|
294
189
|
|
295
|
-
|
296
|
-
block = Proc.new { }
|
297
|
-
expect(Koala::HTTPService).to receive(:faraday_middleware).and_return(block)
|
298
|
-
expect(Faraday).to receive(:new).with(anything, anything, &block).and_return(@mock_connection)
|
299
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
190
|
+
Koala::HTTPService.make_request(request)
|
300
191
|
end
|
301
192
|
end
|
302
193
|
|
194
|
+
it "uses the default builder block if HTTPService.faraday_middleware block is not defined" do
|
195
|
+
block = Proc.new { |builder|
|
196
|
+
builder.request :multipart
|
197
|
+
builder.request :url_encoded
|
198
|
+
}
|
199
|
+
stub_const("Koala::HTTPService::DEFAULT_MIDDLEWARE", block)
|
200
|
+
allow(Koala::HTTPService).to receive(:faraday_middleware).and_return(nil)
|
303
201
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
202
|
+
expect_any_instance_of(Faraday::Connection).to receive(:get) do |instance|
|
203
|
+
expect(instance.builder.handlers).to eq([
|
204
|
+
Faraday::Multipart::Middleware,
|
205
|
+
Faraday::Request::UrlEncoded,
|
206
|
+
])
|
207
|
+
mock_http_response
|
309
208
|
end
|
310
209
|
|
311
|
-
|
312
|
-
|
313
|
-
allow(Koala::HTTPService).to receive(:http_options).and_return({ api_version: 'v12' })
|
314
|
-
expect(@mock_connection).to receive(:get).with("/v12/anything", anything)
|
315
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
316
|
-
end
|
210
|
+
Koala::HTTPService.make_request(request)
|
211
|
+
end
|
317
212
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
213
|
+
it "uses the defined HTTPService.faraday_middleware block if defined" do
|
214
|
+
block = Proc.new { |builder|
|
215
|
+
builder.request :multipart
|
216
|
+
builder.request :url_encoded
|
217
|
+
}
|
218
|
+
expect(Koala::HTTPService).to receive(:faraday_middleware).and_return(block)
|
323
219
|
|
324
|
-
|
325
|
-
expect(
|
326
|
-
|
327
|
-
|
220
|
+
expect_any_instance_of(Faraday::Connection).to receive(:get) do |instance|
|
221
|
+
expect(instance.builder.handlers).to eq([
|
222
|
+
Faraday::Multipart::Middleware,
|
223
|
+
Faraday::Request::UrlEncoded,
|
224
|
+
])
|
225
|
+
mock_http_response
|
328
226
|
end
|
329
|
-
end
|
330
227
|
|
331
|
-
|
332
|
-
expect(@mock_connection).to receive(:post).and_return(@mock_http_response)
|
333
|
-
Koala::HTTPService.make_request("anything", {}, "anything")
|
228
|
+
Koala::HTTPService.make_request(request)
|
334
229
|
end
|
335
230
|
|
336
|
-
|
337
|
-
|
338
|
-
expect(@mock_connection).to receive(:post).with(anything, hash_including("method" => verb)).and_return(@mock_http_response)
|
339
|
-
Koala::HTTPService.make_request("anything", {}, verb)
|
340
|
-
end
|
341
|
-
|
342
|
-
it "makes a GET request if the verb is get" do
|
343
|
-
expect(@mock_connection).to receive(:get).and_return(@mock_http_response)
|
344
|
-
Koala::HTTPService.make_request("anything", {}, "get")
|
345
|
-
end
|
231
|
+
context 'log_tokens configuration' do
|
232
|
+
let(:args) { { "an" => :arg, "access_token" => "myvisbleaccesstoken" } }
|
346
233
|
|
347
|
-
|
348
|
-
|
349
|
-
# technically this is done for all requests, but you don't send GET requests with files
|
350
|
-
args = {"a" => :b, "c" => 3}
|
351
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(:params => args)).and_return(@mock_connection)
|
352
|
-
Koala::HTTPService.make_request("anything", args, "get")
|
234
|
+
before(:each) do
|
235
|
+
allow_any_instance_of(Faraday::Connection).to receive(:get) { double(status: '200', body: 'ok', headers: {}) }
|
353
236
|
end
|
354
237
|
|
355
|
-
it
|
356
|
-
|
357
|
-
args = {"a" => :b, "c" => 3}
|
358
|
-
expect(@mock_connection).to receive(:get).with(anything, {}).and_return(@mock_http_response)
|
359
|
-
Koala::HTTPService.make_request("anything", args, "get")
|
360
|
-
end
|
238
|
+
it 'logs tokens' do
|
239
|
+
allow(Koala.config).to receive(:mask_tokens) { false }
|
361
240
|
|
362
|
-
|
363
|
-
|
364
|
-
log_message_stem = "GET: anything params: "
|
365
|
-
expect(Koala::Utils.logger).to receive(:debug) do |log_message|
|
366
|
-
# unordered hashes are a bane
|
367
|
-
# Ruby in 1.8 modes tends to return different hash orderings,
|
368
|
-
# which makes checking the content of the stringified hash hard
|
369
|
-
# it's enough just to ensure that there's hash content in the string, I think
|
370
|
-
expect(log_message).to include(log_message_stem)
|
371
|
-
expect(log_message.match(/\{.*\}/)).not_to be_nil
|
372
|
-
end
|
241
|
+
expect(Koala::Utils).to receive(:debug).with('STARTED => GET: /foo params: {"an"=>:arg, "access_token"=>"myvisbleaccesstoken"}')
|
242
|
+
expect(Koala::Utils).to receive(:debug).with('FINISHED => GET: /foo params: {"an"=>:arg, "access_token"=>"myvisbleaccesstoken"}')
|
373
243
|
|
374
|
-
Koala::HTTPService.make_request(
|
244
|
+
Koala::HTTPService.make_request(request)
|
375
245
|
end
|
376
|
-
end
|
377
246
|
|
378
|
-
|
379
|
-
|
380
|
-
# technically this is done for all requests, but you don't send GET requests with files
|
381
|
-
args = {"a" => :b, "c" => 3}
|
382
|
-
expect(@mock_connection).to receive(:post).with(anything, hash_including(args)).and_return(@mock_http_response)
|
383
|
-
Koala::HTTPService.make_request("anything", args, "post")
|
384
|
-
end
|
247
|
+
it 'doesnt log tokens' do
|
248
|
+
allow(Koala.config).to receive(:mask_tokens) { true }
|
385
249
|
|
386
|
-
|
387
|
-
|
388
|
-
upload_io = double("UploadIO")
|
389
|
-
u = Koala::UploadableIO.new("/path/to/stuff", "img/jpg")
|
390
|
-
allow(u).to receive(:to_upload_io).and_return(upload_io)
|
391
|
-
expect(@mock_connection).to receive(:post).with(anything, hash_including("source" => upload_io)).and_return(@mock_http_response)
|
392
|
-
Koala::HTTPService.make_request("anything", {:source => u}, "post")
|
393
|
-
end
|
250
|
+
expect(Koala::Utils).to receive(:debug).with('STARTED => GET: /foo params: {"an"=>:arg, "access_token"=>"myvisbleac*****token"}')
|
251
|
+
expect(Koala::Utils).to receive(:debug).with('FINISHED => GET: /foo params: {"an"=>:arg, "access_token"=>"myvisbleac*****token"}')
|
394
252
|
|
395
|
-
|
396
|
-
args = {"a" => :b, "c" => 3}
|
397
|
-
log_message_stem = "POST: anything params: "
|
398
|
-
expect(Koala::Utils.logger).to receive(:debug) do |log_message|
|
399
|
-
# unordered hashes are a bane
|
400
|
-
# Ruby in 1.8 modes tends to return different hash orderings,
|
401
|
-
# which makes checking the content of the stringified hash hard
|
402
|
-
# it's enough just to ensure that there's hash content in the string, I think
|
403
|
-
expect(log_message).to include(log_message_stem)
|
404
|
-
expect(log_message.match(/\{.*\}/)).not_to be_nil
|
405
|
-
end
|
406
|
-
Koala::HTTPService.make_request("anything", args, "post")
|
253
|
+
Koala::HTTPService.make_request(request)
|
407
254
|
end
|
408
|
-
end
|
409
|
-
end
|
410
255
|
|
411
|
-
|
412
|
-
|
413
|
-
expect(Koala::HTTPService.path_contains_api_version?('/v2.1/anything')).to be true
|
414
|
-
end
|
256
|
+
it 'hides the token for the debug_token api endpoint' do
|
257
|
+
request = Koala::HTTPService::Request.new(path: "/debug_token", verb: verb, args: { input_token: 'myvisibleaccesstoken', 'access_token' => 'myvisibleaccesstoken' }, options: options)
|
415
258
|
|
416
|
-
|
417
|
-
expect(Koala::HTTPService.path_contains_api_version?('v2.1/anything')).to be true
|
418
|
-
end
|
259
|
+
allow(Koala.config).to receive(:mask_tokens) { true }
|
419
260
|
|
420
|
-
|
421
|
-
|
422
|
-
end
|
261
|
+
expect(Koala::Utils).to receive(:debug).with('STARTED => GET: /debug_token params: {"input_token"=>"myvisiblea*****token", "access_token"=>"myvisiblea*****token"}')
|
262
|
+
expect(Koala::Utils).to receive(:debug).with('FINISHED => GET: /debug_token params: {"input_token"=>"myvisiblea*****token", "access_token"=>"myvisiblea*****token"}')
|
423
263
|
|
424
|
-
|
425
|
-
|
264
|
+
Koala::HTTPService.make_request(request)
|
265
|
+
end
|
426
266
|
end
|
427
267
|
end
|
428
268
|
end
|
data/spec/cases/koala_spec.rb
CHANGED
@@ -19,16 +19,19 @@ describe Koala do
|
|
19
19
|
verb = "get"
|
20
20
|
options = {:c => :d}
|
21
21
|
|
22
|
-
expect(Koala.http_service).to receive(:make_request)
|
22
|
+
expect(Koala.http_service).to receive(:make_request) do |request|
|
23
|
+
expect(request.raw_path).to eq(path)
|
24
|
+
expect(request.raw_args).to eq(args)
|
25
|
+
expect(request.raw_verb).to eq(verb)
|
26
|
+
expect(request.raw_options).to eq(options)
|
27
|
+
end
|
23
28
|
Koala.make_request(path, args, verb, options)
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
32
|
describe ".configure" do
|
28
33
|
it "yields a configurable object" do
|
29
|
-
expect
|
30
|
-
Koala.configure {|c| c.foo = "bar"}
|
31
|
-
}.not_to raise_exception
|
34
|
+
Koala.configure {|c| expect(c).to be_a(Koala::Configuration)}
|
32
35
|
end
|
33
36
|
|
34
37
|
it "caches the config (singleton)" do
|
@@ -51,5 +54,4 @@ describe Koala do
|
|
51
54
|
expect(Koala.config.graph_server).to eq("some-new.graph_server.com")
|
52
55
|
end
|
53
56
|
end
|
54
|
-
|
55
57
|
end
|
data/spec/cases/oauth_spec.rb
CHANGED
@@ -53,6 +53,45 @@ describe "Koala::Facebook::OAuth" do
|
|
53
53
|
@oauth.app_secret == @secret &&
|
54
54
|
@oauth.oauth_callback_url == nil).to be_truthy
|
55
55
|
end
|
56
|
+
|
57
|
+
context "with global defaults" do
|
58
|
+
let(:app_id) { :app_id }
|
59
|
+
let(:app_secret) { :app_secret }
|
60
|
+
let(:oauth_callback_url) { :oauth_callback_url }
|
61
|
+
|
62
|
+
before :each do
|
63
|
+
Koala.configure do |config|
|
64
|
+
config.app_id = app_id
|
65
|
+
config.app_secret = app_secret
|
66
|
+
config.oauth_callback_url = oauth_callback_url
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "defaults to the configured data if not otherwise provided" do
|
71
|
+
oauth = Koala::Facebook::OAuth.new
|
72
|
+
expect(oauth.app_id).to eq(app_id)
|
73
|
+
expect(oauth.app_secret).to eq(app_secret)
|
74
|
+
expect(oauth.oauth_callback_url).to eq(oauth_callback_url)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "lets you override app_id" do
|
78
|
+
other_value = :another_id
|
79
|
+
oauth = Koala::Facebook::OAuth.new(other_value)
|
80
|
+
expect(oauth.app_id).to eq(other_value)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "lets you override secret" do
|
84
|
+
other_value = :another_secret
|
85
|
+
oauth = Koala::Facebook::OAuth.new(nil, other_value)
|
86
|
+
expect(oauth.app_secret).to eq(other_value)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "lets you override app_id" do
|
90
|
+
other_value = :another_token
|
91
|
+
oauth = Koala::Facebook::OAuth.new(nil, nil, other_value)
|
92
|
+
expect(oauth.oauth_callback_url).to eq(other_value)
|
93
|
+
end
|
94
|
+
end
|
56
95
|
end
|
57
96
|
|
58
97
|
describe "for cookie parsing" do
|
@@ -401,7 +440,7 @@ describe "Koala::Facebook::OAuth" do
|
|
401
440
|
allow(Koala).to receive(:make_request).and_return(
|
402
441
|
Koala::HTTPService::Response.new(
|
403
442
|
200,
|
404
|
-
|
443
|
+
JSON.dump(result),
|
405
444
|
{}
|
406
445
|
)
|
407
446
|
)
|
@@ -584,7 +623,7 @@ describe "Koala::Facebook::OAuth" do
|
|
584
623
|
# the signed request code is ported directly from Facebook
|
585
624
|
# so we only need to test at a high level that it works
|
586
625
|
it "throws an error if the algorithm is unsupported" do
|
587
|
-
allow(
|
626
|
+
allow(JSON).to receive(:parse).and_return("algorithm" => "my fun algorithm")
|
588
627
|
expect { @oauth.parse_signed_request(@signed_params) }.to raise_error(Koala::Facebook::OAuthSignatureError)
|
589
628
|
end
|
590
629
|
|