api-auth 1.5.0 → 2.6.0

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.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/main.yml +71 -0
  3. data/.gitignore +13 -44
  4. data/.rubocop.yml +39 -0
  5. data/.rubocop_todo.yml +83 -0
  6. data/Appraisals +12 -36
  7. data/CHANGELOG.md +75 -1
  8. data/README.md +155 -52
  9. data/Rakefile +1 -1
  10. data/VERSION +1 -1
  11. data/api_auth.gemspec +35 -23
  12. data/gemfiles/rails_60.gemfile +9 -0
  13. data/gemfiles/rails_61.gemfile +9 -0
  14. data/gemfiles/rails_70.gemfile +9 -0
  15. data/lib/api-auth.rb +1 -1
  16. data/lib/api_auth/base.rb +41 -35
  17. data/lib/api_auth/errors.rb +4 -3
  18. data/lib/api_auth/headers.rb +38 -42
  19. data/lib/api_auth/helpers.rb +7 -16
  20. data/lib/api_auth/railtie.rb +34 -74
  21. data/lib/api_auth/request_drivers/action_controller.rb +27 -27
  22. data/lib/api_auth/request_drivers/action_dispatch.rb +0 -6
  23. data/lib/api_auth/request_drivers/curb.rb +16 -21
  24. data/lib/api_auth/request_drivers/faraday.rb +25 -34
  25. data/lib/api_auth/request_drivers/faraday_env.rb +102 -0
  26. data/lib/api_auth/request_drivers/grape_request.rb +87 -0
  27. data/lib/api_auth/request_drivers/http.rb +96 -0
  28. data/lib/api_auth/request_drivers/httpi.rb +22 -27
  29. data/lib/api_auth/request_drivers/net_http.rb +21 -26
  30. data/lib/api_auth/request_drivers/rack.rb +23 -28
  31. data/lib/api_auth/request_drivers/rest_client.rb +24 -29
  32. data/lib/api_auth.rb +4 -0
  33. data/lib/faraday/api_auth/middleware.rb +35 -0
  34. data/lib/faraday/api_auth.rb +8 -0
  35. data/spec/api_auth_spec.rb +135 -96
  36. data/spec/faraday_middleware_spec.rb +17 -0
  37. data/spec/headers_spec.rb +148 -108
  38. data/spec/helpers_spec.rb +8 -10
  39. data/spec/railtie_spec.rb +80 -99
  40. data/spec/request_drivers/action_controller_spec.rb +122 -79
  41. data/spec/request_drivers/action_dispatch_spec.rb +212 -85
  42. data/spec/request_drivers/curb_spec.rb +36 -33
  43. data/spec/request_drivers/faraday_env_spec.rb +188 -0
  44. data/spec/request_drivers/faraday_spec.rb +87 -83
  45. data/spec/request_drivers/grape_request_spec.rb +280 -0
  46. data/spec/request_drivers/http_spec.rb +190 -0
  47. data/spec/request_drivers/httpi_spec.rb +59 -59
  48. data/spec/request_drivers/net_http_spec.rb +70 -66
  49. data/spec/request_drivers/rack_spec.rb +101 -97
  50. data/spec/request_drivers/rest_client_spec.rb +218 -144
  51. data/spec/spec_helper.rb +15 -12
  52. metadata +144 -83
  53. data/.travis.yml +0 -40
  54. data/Gemfile.lock +0 -115
  55. data/gemfiles/rails_23.gemfile +0 -9
  56. data/gemfiles/rails_23.gemfile.lock +0 -70
  57. data/gemfiles/rails_30.gemfile +0 -9
  58. data/gemfiles/rails_30.gemfile.lock +0 -92
  59. data/gemfiles/rails_31.gemfile +0 -9
  60. data/gemfiles/rails_31.gemfile.lock +0 -98
  61. data/gemfiles/rails_32.gemfile +0 -9
  62. data/gemfiles/rails_32.gemfile.lock +0 -97
  63. data/gemfiles/rails_4.gemfile +0 -9
  64. data/gemfiles/rails_4.gemfile.lock +0 -94
  65. data/gemfiles/rails_41.gemfile +0 -9
  66. data/gemfiles/rails_41.gemfile.lock +0 -98
  67. data/gemfiles/rails_42.gemfile +0 -9
  68. data/gemfiles/rails_42.gemfile.lock +0 -115
@@ -1,330 +1,404 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ApiAuth::RequestDrivers::RestClientRequest do
4
+ let(:timestamp) { Time.now.utc.httpdate }
4
5
 
5
- let(:timestamp){ Time.now.utc.httpdate }
6
+ let(:request_path) { 'https://localhost/resource.xml?foo=bar&bar=foo' }
6
7
 
7
- let(:request_path){ "/resource.xml?foo=bar&bar=foo" }
8
-
9
- let(:request_headers){
8
+ let(:request_headers) do
10
9
  {
11
- 'Authorization' => 'APIAuth 1044:12345',
12
- 'Content-MD5' => '1B2M2Y8AsgTpgAmY7PhCfg==',
10
+ 'Authorization' => 'APIAuth 1044:12345',
11
+ 'X-Authorization-Content-SHA256' => '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=',
13
12
  'Content-Type' => 'text/plain',
14
13
  'Date' => timestamp
15
14
  }
16
- }
15
+ end
17
16
 
18
17
  let(:request) do
19
18
  RestClient::Request.new(
20
- :url => "/resource.xml?foo=bar&bar=foo",
21
- :headers => request_headers,
22
- :method => :put,
23
- :payload => "hello\nworld"
19
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
20
+ headers: request_headers,
21
+ method: :put,
22
+ payload: "hello\nworld"
24
23
  )
25
24
  end
26
25
 
27
- subject(:driven_request){ ApiAuth::RequestDrivers::RestClientRequest.new(request) }
26
+ subject(:driven_request) { ApiAuth::RequestDrivers::RestClientRequest.new(request) }
28
27
 
29
- describe "getting headers correctly" do
30
- it "gets the content_type" do
28
+ describe 'getting headers correctly' do
29
+ it 'gets the content_type' do
31
30
  expect(driven_request.content_type).to eq('text/plain')
32
31
  end
33
32
 
34
- it "gets the content_md5" do
35
- expect(driven_request.content_md5).to eq('1B2M2Y8AsgTpgAmY7PhCfg==')
33
+ it 'gets the content_hash' do
34
+ expect(driven_request.content_hash).to eq('47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=')
36
35
  end
37
36
 
38
- it "gets the request_uri" do
39
- expect(driven_request.request_uri).to eq('/resource.xml?foo=bar&bar=foo')
37
+ it 'gets the request_uri' do
38
+ expect(driven_request.request_uri).to eq('https://localhost/resource.xml?foo=bar&bar=foo')
40
39
  end
41
40
 
42
- it "gets the timestamp" do
41
+ it 'gets the timestamp' do
43
42
  expect(driven_request.timestamp).to eq(timestamp)
44
43
  end
45
44
 
46
- it "gets the authorization_header" do
45
+ it 'gets the authorization_header' do
47
46
  expect(driven_request.authorization_header).to eq('APIAuth 1044:12345')
48
47
  end
49
48
 
50
- describe "#calculated_md5" do
51
- it "calculates md5 from the body" do
52
- expect(driven_request.calculated_md5).to eq('kZXQvrKoieG+Be1rsZVINw==')
49
+ describe '#calculated_hash' do
50
+ it 'calculates hash from the body' do
51
+ expect(driven_request.calculated_hash).to eq('JsYKYdAdtYNspw/v1EpqAWYgQTyO9fJZpsVhLU9507g=')
53
52
  end
54
53
 
55
- it "treats no body as empty string" do
54
+ it 'treats no body as empty string' do
56
55
  request = RestClient::Request.new(
57
- :url => "/resource.xml?foo=bar&bar=foo",
58
- :headers => request_headers,
59
- :method => :put
56
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
57
+ headers: request_headers,
58
+ method: :put
60
59
  )
61
60
  driven_request = ApiAuth::RequestDrivers::RestClientRequest.new(request)
62
- expect(driven_request.calculated_md5).to eq('1B2M2Y8AsgTpgAmY7PhCfg==')
61
+ expect(driven_request.calculated_hash).to eq('47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=')
63
62
  end
64
63
  end
65
64
 
66
- describe "http_method" do
67
- context "when put request" do
65
+ describe 'http_method' do
66
+ context 'when put request' do
68
67
  let(:request) do
69
68
  RestClient::Request.new(
70
- :url => "/resource.xml?foo=bar&bar=foo",
71
- :headers => request_headers,
72
- :method => :put
69
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
70
+ headers: request_headers,
71
+ method: :put
73
72
  )
74
73
  end
75
74
 
76
- it "returns upcased put" do
75
+ it 'returns upcased put' do
77
76
  expect(driven_request.http_method).to eq('PUT')
78
77
  end
79
78
  end
80
79
 
81
- context "when get request" do
80
+ context 'when get request' do
82
81
  let(:request) do
83
82
  RestClient::Request.new(
84
- :url => "/resource.xml?foo=bar&bar=foo",
85
- :headers => request_headers,
86
- :method => :get
83
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
84
+ headers: request_headers,
85
+ method: :get
87
86
  )
88
87
  end
89
88
 
90
- it "returns upcased get" do
89
+ it 'returns upcased get' do
91
90
  expect(driven_request.http_method).to eq('GET')
92
91
  end
93
92
  end
94
93
  end
95
94
  end
96
95
 
97
- describe "setting headers correctly" do
98
- let(:request_headers){
96
+ describe 'setting headers correctly' do
97
+ let(:request_headers) do
99
98
  {
100
99
  'Content-Type' => 'text/plain'
101
100
  }
102
- }
101
+ end
103
102
 
104
- describe "#populate_content_md5" do
105
- context "when getting" do
103
+ describe '#populate_content_hash' do
104
+ context 'when getting' do
106
105
  let(:request) do
107
106
  RestClient::Request.new(
108
- :url => "/resource.xml?foo=bar&bar=foo",
109
- :headers => request_headers,
110
- :method => :get
107
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
108
+ headers: request_headers,
109
+ method: :get
111
110
  )
112
111
  end
113
112
 
114
- it "doesn't populate content-md5" do
115
- driven_request.populate_content_md5
116
- expect(request.headers["Content-MD5"]).to be_nil
113
+ it "doesn't populate content hash" do
114
+ driven_request.populate_content_hash
115
+ expect(request.headers['X-Authorization-Content-SHA256']).to be_nil
117
116
  end
118
117
  end
119
118
 
120
- context "when posting" do
119
+ context 'when posting' do
121
120
  let(:request) do
122
121
  RestClient::Request.new(
123
- :url => "/resource.xml?foo=bar&bar=foo",
124
- :headers => request_headers,
125
- :method => :post,
126
- :payload => "hello\nworld"
122
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
123
+ headers: request_headers,
124
+ method: :post,
125
+ payload: "hello\nworld"
127
126
  )
128
127
  end
129
128
 
130
- it "populates content-md5" do
131
- driven_request.populate_content_md5
132
- expect(request.headers["Content-MD5"]).to eq('kZXQvrKoieG+Be1rsZVINw==')
129
+ it 'populates content hash' do
130
+ driven_request.populate_content_hash
131
+ expect(request.headers['X-Authorization-Content-SHA256']).to eq('JsYKYdAdtYNspw/v1EpqAWYgQTyO9fJZpsVhLU9507g=')
133
132
  end
134
133
 
135
- it "refreshes the cached headers" do
136
- driven_request.populate_content_md5
137
- expect(driven_request.content_md5).to eq('kZXQvrKoieG+Be1rsZVINw==')
134
+ it 'refreshes the cached headers' do
135
+ driven_request.populate_content_hash
136
+ expect(driven_request.content_hash).to eq('JsYKYdAdtYNspw/v1EpqAWYgQTyO9fJZpsVhLU9507g=')
138
137
  end
139
138
  end
140
139
 
141
- context "when putting" do
140
+ context 'when putting' do
142
141
  let(:request) do
143
142
  RestClient::Request.new(
144
- :url => "/resource.xml?foo=bar&bar=foo",
145
- :headers => request_headers,
146
- :method => :put,
147
- :payload => "hello\nworld"
143
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
144
+ headers: request_headers,
145
+ method: :put,
146
+ payload: "hello\nworld"
148
147
  )
149
148
  end
150
149
 
151
- it "populates content-md5" do
152
- driven_request.populate_content_md5
153
- expect(request.headers["Content-MD5"]).to eq('kZXQvrKoieG+Be1rsZVINw==')
150
+ it 'populates content hash' do
151
+ driven_request.populate_content_hash
152
+ expect(request.headers['X-Authorization-Content-SHA256']).to eq('JsYKYdAdtYNspw/v1EpqAWYgQTyO9fJZpsVhLU9507g=')
154
153
  end
155
154
 
156
- it "refreshes the cached headers" do
157
- driven_request.populate_content_md5
158
- expect(driven_request.content_md5).to eq('kZXQvrKoieG+Be1rsZVINw==')
155
+ it 'refreshes the cached headers' do
156
+ driven_request.populate_content_hash
157
+ expect(driven_request.content_hash).to eq('JsYKYdAdtYNspw/v1EpqAWYgQTyO9fJZpsVhLU9507g=')
159
158
  end
160
159
  end
161
160
 
162
- context "when deleting" do
161
+ context 'when deleting' do
163
162
  let(:request) do
164
163
  RestClient::Request.new(
165
- :url => "/resource.xml?foo=bar&bar=foo",
166
- :headers => request_headers,
167
- :method => :delete
164
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
165
+ headers: request_headers,
166
+ method: :delete
168
167
  )
169
168
  end
170
169
 
171
- it "doesn't populate content-md5" do
172
- driven_request.populate_content_md5
173
- expect(request.headers["Content-MD5"]).to be_nil
170
+ it "doesn't populate content hash" do
171
+ driven_request.populate_content_hash
172
+ expect(request.headers['X-Authorization-Content-SHA256']).to be_nil
174
173
  end
175
174
  end
176
-
177
175
  end
178
176
 
179
- describe "#set_date" do
177
+ describe '#set_date' do
180
178
  before do
181
179
  allow(Time).to receive_message_chain(:now, :utc, :httpdate).and_return(timestamp)
182
180
  end
183
181
 
184
- it "sets the date header of the request" do
182
+ it 'sets the date header of the request' do
185
183
  allow(Time).to receive_message_chain(:now, :utc, :httpdate).and_return(timestamp)
186
184
  driven_request.set_date
187
185
  expect(request.headers['DATE']).to eq(timestamp)
188
186
  end
189
187
 
190
- it "refreshes the cached headers" do
188
+ it 'refreshes the cached headers' do
191
189
  driven_request.set_date
192
190
  expect(driven_request.timestamp).to eq(timestamp)
193
191
  end
194
192
  end
195
193
 
196
- describe "#set_auth_header" do
197
- it "sets the auth header" do
194
+ describe '#set_auth_header' do
195
+ it 'sets the auth header' do
198
196
  driven_request.set_auth_header('APIAuth 1044:54321')
199
197
  expect(request.headers['Authorization']).to eq('APIAuth 1044:54321')
200
198
  end
201
199
  end
202
200
  end
203
201
 
204
- describe "md5_mismatch?" do
205
-
206
- context "when getting" do
202
+ describe 'content_hash_mismatch?' do
203
+ context 'when getting' do
207
204
  let(:request) do
208
205
  RestClient::Request.new(
209
- :url => "/resource.xml?foo=bar&bar=foo",
210
- :headers => request_headers,
211
- :method => :get
206
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
207
+ headers: request_headers,
208
+ method: :get
212
209
  )
213
210
  end
214
211
 
215
- it "is false" do
216
- expect(driven_request.md5_mismatch?).to be false
212
+ it 'is false' do
213
+ expect(driven_request.content_hash_mismatch?).to be false
217
214
  end
218
215
  end
219
216
 
220
- context "when posting" do
217
+ context 'when posting' do
221
218
  let(:request) do
222
219
  RestClient::Request.new(
223
- :url => "/resource.xml?foo=bar&bar=foo",
224
- :headers => request_headers,
225
- :method => :post,
226
- :payload => "hello\nworld"
220
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
221
+ headers: request_headers,
222
+ method: :post,
223
+ payload: "hello\nworld"
227
224
  )
228
225
  end
229
226
 
230
- context "when calculated matches sent" do
231
- let(:request_headers){
227
+ context 'when calculated matches sent' do
228
+ let(:request_headers) do
232
229
  {
233
- 'Authorization' => 'APIAuth 1044:12345',
234
- 'Content-MD5' => 'kZXQvrKoieG+Be1rsZVINw==',
230
+ 'Authorization' => 'APIAuth 1044:12345',
231
+ 'X-Authorization-Content-SHA256' => 'JsYKYdAdtYNspw/v1EpqAWYgQTyO9fJZpsVhLU9507g=',
235
232
  'Content-Type' => 'text/plain',
236
233
  'Date' => timestamp
237
234
  }
238
- }
235
+ end
239
236
 
240
- it "is false" do
241
- expect(driven_request.md5_mismatch?).to be false
237
+ it 'is false' do
238
+ expect(driven_request.content_hash_mismatch?).to be false
242
239
  end
243
240
  end
244
241
 
245
242
  context "when calculated doesn't match sent" do
246
- let(:request_headers){
243
+ let(:request_headers) do
247
244
  {
248
- 'Authorization' => 'APIAuth 1044:12345',
249
- 'Content-MD5' => '3',
245
+ 'Authorization' => 'APIAuth 1044:12345',
246
+ 'X-Authorization-Content-SHA256' => '3',
250
247
  'Content-Type' => 'text/plain',
251
248
  'Date' => timestamp
252
249
  }
253
- }
250
+ end
254
251
 
255
- it "is true" do
256
- expect(driven_request.md5_mismatch?).to be true
252
+ it 'is true' do
253
+ expect(driven_request.content_hash_mismatch?).to be true
257
254
  end
258
255
  end
259
256
  end
260
257
 
261
- context "when putting" do
258
+ context 'when putting' do
262
259
  let(:request) do
263
260
  RestClient::Request.new(
264
- :url => "/resource.xml?foo=bar&bar=foo",
265
- :headers => request_headers,
266
- :method => :put,
267
- :payload => "hello\nworld"
261
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
262
+ headers: request_headers,
263
+ method: :put,
264
+ payload: "hello\nworld"
268
265
  )
269
266
  end
270
267
 
271
- context "when calculated matches sent" do
272
- let(:request_headers){
268
+ context 'when calculated matches sent' do
269
+ let(:request_headers) do
273
270
  {
274
- 'Authorization' => 'APIAuth 1044:12345',
275
- 'Content-MD5' => 'kZXQvrKoieG+Be1rsZVINw==',
271
+ 'Authorization' => 'APIAuth 1044:12345',
272
+ 'X-Authorization-Content-SHA256' => 'JsYKYdAdtYNspw/v1EpqAWYgQTyO9fJZpsVhLU9507g=',
276
273
  'Content-Type' => 'text/plain',
277
274
  'Date' => timestamp
278
275
  }
279
- }
276
+ end
280
277
 
281
- it "is false" do
282
- expect(driven_request.md5_mismatch?).to be false
278
+ it 'is false' do
279
+ expect(driven_request.content_hash_mismatch?).to be false
283
280
  end
284
281
  end
285
282
 
286
283
  context "when calculated doesn't match sent" do
287
- let(:request_headers){
284
+ let(:request_headers) do
288
285
  {
289
- 'Authorization' => 'APIAuth 1044:12345',
290
- 'Content-MD5' => '3',
286
+ 'Authorization' => 'APIAuth 1044:12345',
287
+ 'X-Authorization-Content-SHA256' => '3',
291
288
  'Content-Type' => 'text/plain',
292
289
  'Date' => timestamp
293
290
  }
294
- }
291
+ end
295
292
 
296
- it "is true" do
297
- expect(driven_request.md5_mismatch?).to be true
293
+ it 'is true' do
294
+ expect(driven_request.content_hash_mismatch?).to be true
298
295
  end
299
296
  end
300
297
  end
301
298
 
302
- context "when deleting" do
299
+ context 'when deleting' do
300
+ let(:request) do
301
+ RestClient::Request.new(
302
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
303
+ headers: request_headers,
304
+ method: :delete
305
+ )
306
+ end
307
+
308
+ it 'is false' do
309
+ expect(driven_request.content_hash_mismatch?).to be false
310
+ end
311
+ end
312
+ end
313
+
314
+ describe 'authentics?' do
315
+ context 'when getting' do
316
+ let(:request) do
317
+ RestClient::Request.new(
318
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
319
+ method: :get
320
+ )
321
+ end
322
+
323
+ let(:signed_request) do
324
+ ApiAuth.sign!(request, '1044', '123')
325
+ end
326
+
327
+ it 'validates that the signature in the request header matches the way we sign it' do
328
+ expect(ApiAuth.authentic?(signed_request, '123')).to eq true
329
+ end
330
+ end
331
+
332
+ context 'when posting' do
333
+ let(:request) do
334
+ RestClient::Request.new(
335
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
336
+ method: :post,
337
+ payload: "hello\nworld"
338
+ )
339
+ end
340
+
341
+ let(:signed_request) do
342
+ ApiAuth.sign!(request, '1044', '123')
343
+ end
344
+
345
+ it 'validates that the signature in the request header matches the way we sign it' do
346
+ expect(ApiAuth.authentic?(signed_request, '123')).to eq true
347
+ end
348
+ end
349
+
350
+ context 'when putting' do
303
351
  let(:request) do
304
352
  RestClient::Request.new(
305
- :url => "/resource.xml?foo=bar&bar=foo",
306
- :headers => request_headers,
307
- :method => :delete
353
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
354
+ method: :put,
355
+ payload: "hello\nworld"
308
356
  )
309
357
  end
310
358
 
311
- it "is false" do
312
- expect(driven_request.md5_mismatch?).to be false
359
+ let(:signed_request) do
360
+ ApiAuth.sign!(request, '1044', '123')
361
+ end
362
+
363
+ it 'validates that the signature in the request header matches the way we sign it' do
364
+ expect(ApiAuth.authentic?(signed_request, '123')).to eq true
365
+ end
366
+ end
367
+
368
+ context 'when deleting' do
369
+ let(:request) do
370
+ RestClient::Request.new(
371
+ url: 'https://localhost/resource.xml?foo=bar&bar=foo',
372
+ method: :delete
373
+ )
374
+ end
375
+
376
+ let(:signed_request) do
377
+ ApiAuth.sign!(request, '1044', '123')
378
+ end
379
+
380
+ it 'validates that the signature in the request header matches the way we sign it' do
381
+ expect(ApiAuth.authentic?(signed_request, '123')).to eq true
313
382
  end
314
383
  end
315
384
  end
316
385
 
317
- describe "edge cases" do
386
+ describe 'edge cases' do
318
387
  it "doesn't mess up symbol based headers" do
319
- headers = { 'Content-MD5' => "e59ff97941044f85df5297e1c302d260",
320
- :content_type => "text/plain",
321
- 'Date' => "Mon, 23 Jan 1984 03:29:56 GMT" }
322
- request = RestClient::Request.new(:url => "/resource.xml?foo=bar&bar=foo",
323
- :headers => headers,
324
- :method => :put)
325
- headers = ApiAuth::Headers.new(request)
326
- ApiAuth.sign!(request, "some access id", "some secret key")
388
+ headers = { 'X-Authorization-Content-SHA256' => 'e59ff97941044f85df5297e1c302d260',
389
+ :content_type => 'text/plain',
390
+ 'Date' => 'Mon, 23 Jan 1984 03:29:56 GMT' }
391
+ request = RestClient::Request.new(url: 'https://localhost/resource.xml?foo=bar&bar=foo',
392
+ headers: headers,
393
+ method: :put)
394
+ ApiAuth.sign!(request, 'some access id', 'some secret key')
327
395
  expect(request.processed_headers).to have_key('Content-Type')
328
396
  end
329
397
  end
398
+
399
+ describe 'fetch_headers' do
400
+ it 'returns request headers' do
401
+ expect(driven_request.fetch_headers).to include('CONTENT-TYPE' => 'text/plain')
402
+ end
403
+ end
330
404
  end
data/spec/spec_helper.rb CHANGED
@@ -1,25 +1,28 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
+
5
+ # Fix for Rails 6.1 compatibility issue
6
+ # ActiveSupport 6.1 expects Logger to be available in the global namespace
7
+ require 'logger'
8
+
9
+ require 'active_support'
10
+ require 'active_support/core_ext/numeric/time'
11
+ require 'action_controller'
12
+ require 'action_dispatch'
13
+ require 'active_resource'
14
+ require 'active_resource/http_mock'
15
+
4
16
  require 'api_auth'
5
17
  require 'amatch'
6
18
  require 'rest_client'
7
19
  require 'curb'
20
+ require 'http'
8
21
  require 'httpi'
9
22
  require 'faraday'
23
+ require 'grape'
10
24
  require 'net/http/post/multipart'
11
25
 
12
- require 'active_support'
13
- require 'active_support/test_case'
14
- require 'action_controller'
15
- require 'action_controller/test_case'
16
- require 'active_resource'
17
- require 'active_resource/http_mock'
18
-
19
26
  # Requires supporting files with custom matchers and macros, etc,
20
27
  # in ./support/ and its subdirectories.
21
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
22
-
23
- RSpec.configure do |config|
24
-
25
- end
28
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }