api-auth 1.5.0 → 2.0.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.
- checksums.yaml +4 -4
- data/.gitignore +10 -44
- data/.rubocop.yml +102 -0
- data/.travis.yml +1 -0
- data/Appraisals +8 -0
- data/CHANGELOG.md +8 -1
- data/Gemfile +3 -0
- data/README.md +33 -5
- data/VERSION +1 -1
- data/api_auth.gemspec +17 -17
- data/gemfiles/rails_23.gemfile +3 -0
- data/gemfiles/rails_30.gemfile +3 -0
- data/gemfiles/rails_31.gemfile +5 -0
- data/gemfiles/rails_32.gemfile +5 -0
- data/gemfiles/rails_4.gemfile +2 -0
- data/gemfiles/rails_41.gemfile +2 -0
- data/gemfiles/rails_42.gemfile +2 -0
- data/lib/api-auth.rb +1 -1
- data/lib/api_auth/base.rb +21 -25
- data/lib/api_auth/errors.rb +4 -3
- data/lib/api_auth/headers.rb +11 -27
- data/lib/api_auth/helpers.rb +2 -6
- data/lib/api_auth/railtie.rb +5 -50
- data/lib/api_auth/request_drivers/action_controller.rb +7 -13
- data/lib/api_auth/request_drivers/action_dispatch.rb +0 -6
- data/lib/api_auth/request_drivers/curb.rb +8 -14
- data/lib/api_auth/request_drivers/faraday.rb +11 -21
- data/lib/api_auth/request_drivers/httpi.rb +8 -14
- data/lib/api_auth/request_drivers/net_http.rb +8 -14
- data/lib/api_auth/request_drivers/rack.rb +10 -16
- data/lib/api_auth/request_drivers/rest_client.rb +9 -15
- data/spec/api_auth_spec.rb +90 -88
- data/spec/headers_spec.rb +69 -84
- data/spec/helpers_spec.rb +7 -9
- data/spec/railtie_spec.rb +42 -72
- data/spec/request_drivers/action_controller_spec.rb +53 -55
- data/spec/request_drivers/action_dispatch_spec.rb +52 -55
- data/spec/request_drivers/curb_spec.rb +25 -28
- data/spec/request_drivers/faraday_spec.rb +54 -56
- data/spec/request_drivers/httpi_spec.rb +42 -48
- data/spec/request_drivers/net_http_spec.rb +51 -53
- data/spec/request_drivers/rack_spec.rb +58 -60
- data/spec/request_drivers/rest_client_spec.rb +86 -89
- data/spec/spec_helper.rb +9 -9
- metadata +4 -11
- data/Gemfile.lock +0 -115
- data/gemfiles/rails_23.gemfile.lock +0 -70
- data/gemfiles/rails_30.gemfile.lock +0 -92
- data/gemfiles/rails_31.gemfile.lock +0 -98
- data/gemfiles/rails_32.gemfile.lock +0 -97
- data/gemfiles/rails_4.gemfile.lock +0 -94
- data/gemfiles/rails_41.gemfile.lock +0 -98
- data/gemfiles/rails_42.gemfile.lock +0 -115
@@ -1,60 +1,59 @@
|
|
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(:
|
6
|
+
let(:request_path) { '/resource.xml?foo=bar&bar=foo' }
|
6
7
|
|
7
|
-
let(:
|
8
|
-
|
9
|
-
let(:request_headers){
|
8
|
+
let(:request_headers) do
|
10
9
|
{
|
11
|
-
'Authorization'
|
10
|
+
'Authorization' => 'APIAuth 1044:12345',
|
12
11
|
'Content-MD5' => '1B2M2Y8AsgTpgAmY7PhCfg==',
|
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 =>
|
19
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
21
20
|
:headers => request_headers,
|
22
21
|
:method => :put,
|
23
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
|
30
|
-
it
|
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
|
33
|
+
it 'gets the content_md5' do
|
35
34
|
expect(driven_request.content_md5).to eq('1B2M2Y8AsgTpgAmY7PhCfg==')
|
36
35
|
end
|
37
36
|
|
38
|
-
it
|
37
|
+
it 'gets the request_uri' do
|
39
38
|
expect(driven_request.request_uri).to eq('/resource.xml?foo=bar&bar=foo')
|
40
39
|
end
|
41
40
|
|
42
|
-
it
|
41
|
+
it 'gets the timestamp' do
|
43
42
|
expect(driven_request.timestamp).to eq(timestamp)
|
44
43
|
end
|
45
44
|
|
46
|
-
it
|
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
|
51
|
-
it
|
49
|
+
describe '#calculated_md5' do
|
50
|
+
it 'calculates md5 from the body' do
|
52
51
|
expect(driven_request.calculated_md5).to eq('kZXQvrKoieG+Be1rsZVINw==')
|
53
52
|
end
|
54
53
|
|
55
|
-
it
|
54
|
+
it 'treats no body as empty string' do
|
56
55
|
request = RestClient::Request.new(
|
57
|
-
:url =>
|
56
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
58
57
|
:headers => request_headers,
|
59
58
|
:method => :put
|
60
59
|
)
|
@@ -63,49 +62,49 @@ describe ApiAuth::RequestDrivers::RestClientRequest do
|
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
|
-
describe
|
67
|
-
context
|
65
|
+
describe 'http_method' do
|
66
|
+
context 'when put request' do
|
68
67
|
let(:request) do
|
69
68
|
RestClient::Request.new(
|
70
|
-
:url =>
|
69
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
71
70
|
:headers => request_headers,
|
72
71
|
:method => :put
|
73
72
|
)
|
74
73
|
end
|
75
74
|
|
76
|
-
it
|
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
|
80
|
+
context 'when get request' do
|
82
81
|
let(:request) do
|
83
82
|
RestClient::Request.new(
|
84
|
-
:url =>
|
83
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
85
84
|
:headers => request_headers,
|
86
85
|
:method => :get
|
87
86
|
)
|
88
87
|
end
|
89
88
|
|
90
|
-
it
|
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
|
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
|
105
|
-
context
|
103
|
+
describe '#populate_content_md5' do
|
104
|
+
context 'when getting' do
|
106
105
|
let(:request) do
|
107
106
|
RestClient::Request.new(
|
108
|
-
:url =>
|
107
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
109
108
|
:headers => request_headers,
|
110
109
|
:method => :get
|
111
110
|
)
|
@@ -113,56 +112,56 @@ describe ApiAuth::RequestDrivers::RestClientRequest do
|
|
113
112
|
|
114
113
|
it "doesn't populate content-md5" do
|
115
114
|
driven_request.populate_content_md5
|
116
|
-
expect(request.headers[
|
115
|
+
expect(request.headers['Content-MD5']).to be_nil
|
117
116
|
end
|
118
117
|
end
|
119
118
|
|
120
|
-
context
|
119
|
+
context 'when posting' do
|
121
120
|
let(:request) do
|
122
121
|
RestClient::Request.new(
|
123
|
-
:url =>
|
122
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
124
123
|
:headers => request_headers,
|
125
124
|
:method => :post,
|
126
125
|
:payload => "hello\nworld"
|
127
126
|
)
|
128
127
|
end
|
129
128
|
|
130
|
-
it
|
129
|
+
it 'populates content-md5' do
|
131
130
|
driven_request.populate_content_md5
|
132
|
-
expect(request.headers[
|
131
|
+
expect(request.headers['Content-MD5']).to eq('kZXQvrKoieG+Be1rsZVINw==')
|
133
132
|
end
|
134
133
|
|
135
|
-
it
|
134
|
+
it 'refreshes the cached headers' do
|
136
135
|
driven_request.populate_content_md5
|
137
136
|
expect(driven_request.content_md5).to eq('kZXQvrKoieG+Be1rsZVINw==')
|
138
137
|
end
|
139
138
|
end
|
140
139
|
|
141
|
-
context
|
140
|
+
context 'when putting' do
|
142
141
|
let(:request) do
|
143
142
|
RestClient::Request.new(
|
144
|
-
:url =>
|
143
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
145
144
|
:headers => request_headers,
|
146
145
|
:method => :put,
|
147
146
|
:payload => "hello\nworld"
|
148
147
|
)
|
149
148
|
end
|
150
149
|
|
151
|
-
it
|
150
|
+
it 'populates content-md5' do
|
152
151
|
driven_request.populate_content_md5
|
153
|
-
expect(request.headers[
|
152
|
+
expect(request.headers['Content-MD5']).to eq('kZXQvrKoieG+Be1rsZVINw==')
|
154
153
|
end
|
155
154
|
|
156
|
-
it
|
155
|
+
it 'refreshes the cached headers' do
|
157
156
|
driven_request.populate_content_md5
|
158
157
|
expect(driven_request.content_md5).to eq('kZXQvrKoieG+Be1rsZVINw==')
|
159
158
|
end
|
160
159
|
end
|
161
160
|
|
162
|
-
context
|
161
|
+
context 'when deleting' do
|
163
162
|
let(:request) do
|
164
163
|
RestClient::Request.new(
|
165
|
-
:url =>
|
164
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
166
165
|
:headers => request_headers,
|
167
166
|
:method => :delete
|
168
167
|
)
|
@@ -170,160 +169,158 @@ describe ApiAuth::RequestDrivers::RestClientRequest do
|
|
170
169
|
|
171
170
|
it "doesn't populate content-md5" do
|
172
171
|
driven_request.populate_content_md5
|
173
|
-
expect(request.headers[
|
172
|
+
expect(request.headers['Content-MD5']).to be_nil
|
174
173
|
end
|
175
174
|
end
|
176
|
-
|
177
175
|
end
|
178
176
|
|
179
|
-
describe
|
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
|
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
|
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
|
197
|
-
it
|
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
|
205
|
-
|
206
|
-
context "when getting" do
|
202
|
+
describe 'md5_mismatch?' do
|
203
|
+
context 'when getting' do
|
207
204
|
let(:request) do
|
208
205
|
RestClient::Request.new(
|
209
|
-
:url =>
|
206
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
210
207
|
:headers => request_headers,
|
211
208
|
:method => :get
|
212
209
|
)
|
213
210
|
end
|
214
211
|
|
215
|
-
it
|
212
|
+
it 'is false' do
|
216
213
|
expect(driven_request.md5_mismatch?).to be false
|
217
214
|
end
|
218
215
|
end
|
219
216
|
|
220
|
-
context
|
217
|
+
context 'when posting' do
|
221
218
|
let(:request) do
|
222
219
|
RestClient::Request.new(
|
223
|
-
:url =>
|
220
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
224
221
|
:headers => request_headers,
|
225
222
|
:method => :post,
|
226
223
|
:payload => "hello\nworld"
|
227
224
|
)
|
228
225
|
end
|
229
226
|
|
230
|
-
context
|
231
|
-
let(:request_headers)
|
227
|
+
context 'when calculated matches sent' do
|
228
|
+
let(:request_headers) do
|
232
229
|
{
|
233
|
-
'Authorization'
|
230
|
+
'Authorization' => 'APIAuth 1044:12345',
|
234
231
|
'Content-MD5' => 'kZXQvrKoieG+Be1rsZVINw==',
|
235
232
|
'Content-Type' => 'text/plain',
|
236
233
|
'Date' => timestamp
|
237
234
|
}
|
238
|
-
|
235
|
+
end
|
239
236
|
|
240
|
-
it
|
237
|
+
it 'is false' do
|
241
238
|
expect(driven_request.md5_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'
|
245
|
+
'Authorization' => 'APIAuth 1044:12345',
|
249
246
|
'Content-MD5' => '3',
|
250
247
|
'Content-Type' => 'text/plain',
|
251
248
|
'Date' => timestamp
|
252
249
|
}
|
253
|
-
|
250
|
+
end
|
254
251
|
|
255
|
-
it
|
252
|
+
it 'is true' do
|
256
253
|
expect(driven_request.md5_mismatch?).to be true
|
257
254
|
end
|
258
255
|
end
|
259
256
|
end
|
260
257
|
|
261
|
-
context
|
258
|
+
context 'when putting' do
|
262
259
|
let(:request) do
|
263
260
|
RestClient::Request.new(
|
264
|
-
:url =>
|
261
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
265
262
|
:headers => request_headers,
|
266
263
|
:method => :put,
|
267
264
|
:payload => "hello\nworld"
|
268
265
|
)
|
269
266
|
end
|
270
267
|
|
271
|
-
context
|
272
|
-
let(:request_headers)
|
268
|
+
context 'when calculated matches sent' do
|
269
|
+
let(:request_headers) do
|
273
270
|
{
|
274
|
-
'Authorization'
|
271
|
+
'Authorization' => 'APIAuth 1044:12345',
|
275
272
|
'Content-MD5' => 'kZXQvrKoieG+Be1rsZVINw==',
|
276
273
|
'Content-Type' => 'text/plain',
|
277
274
|
'Date' => timestamp
|
278
275
|
}
|
279
|
-
|
276
|
+
end
|
280
277
|
|
281
|
-
it
|
278
|
+
it 'is false' do
|
282
279
|
expect(driven_request.md5_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'
|
286
|
+
'Authorization' => 'APIAuth 1044:12345',
|
290
287
|
'Content-MD5' => '3',
|
291
288
|
'Content-Type' => 'text/plain',
|
292
289
|
'Date' => timestamp
|
293
290
|
}
|
294
|
-
|
291
|
+
end
|
295
292
|
|
296
|
-
it
|
293
|
+
it 'is true' do
|
297
294
|
expect(driven_request.md5_mismatch?).to be true
|
298
295
|
end
|
299
296
|
end
|
300
297
|
end
|
301
298
|
|
302
|
-
context
|
299
|
+
context 'when deleting' do
|
303
300
|
let(:request) do
|
304
301
|
RestClient::Request.new(
|
305
|
-
:url =>
|
302
|
+
:url => '/resource.xml?foo=bar&bar=foo',
|
306
303
|
:headers => request_headers,
|
307
304
|
:method => :delete
|
308
305
|
)
|
309
306
|
end
|
310
307
|
|
311
|
-
it
|
308
|
+
it 'is false' do
|
312
309
|
expect(driven_request.md5_mismatch?).to be false
|
313
310
|
end
|
314
311
|
end
|
315
312
|
end
|
316
313
|
|
317
|
-
describe
|
314
|
+
describe 'edge cases' do
|
318
315
|
it "doesn't mess up symbol based headers" do
|
319
|
-
headers = { 'Content-MD5' =>
|
320
|
-
:content_type =>
|
321
|
-
'Date' =>
|
322
|
-
request = RestClient::Request.new(:url =>
|
323
|
-
|
324
|
-
|
316
|
+
headers = { 'Content-MD5' => 'e59ff97941044f85df5297e1c302d260',
|
317
|
+
:content_type => 'text/plain',
|
318
|
+
'Date' => 'Mon, 23 Jan 1984 03:29:56 GMT' }
|
319
|
+
request = RestClient::Request.new(:url => '/resource.xml?foo=bar&bar=foo',
|
320
|
+
:headers => headers,
|
321
|
+
:method => :put)
|
325
322
|
headers = ApiAuth::Headers.new(request)
|
326
|
-
ApiAuth.sign!(request,
|
323
|
+
ApiAuth.sign!(request, 'some access id', 'some secret key')
|
327
324
|
expect(request.processed_headers).to have_key('Content-Type')
|
328
325
|
end
|
329
326
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
|
-
require 'api_auth'
|
5
|
-
require 'amatch'
|
6
|
-
require 'rest_client'
|
7
|
-
require 'curb'
|
8
|
-
require 'httpi'
|
9
|
-
require 'faraday'
|
10
|
-
require 'net/http/post/multipart'
|
11
4
|
|
12
5
|
require 'active_support'
|
13
6
|
require 'active_support/test_case'
|
@@ -16,10 +9,17 @@ require 'action_controller/test_case'
|
|
16
9
|
require 'active_resource'
|
17
10
|
require 'active_resource/http_mock'
|
18
11
|
|
12
|
+
require 'api_auth'
|
13
|
+
require 'amatch'
|
14
|
+
require 'rest_client'
|
15
|
+
require 'curb'
|
16
|
+
require 'httpi'
|
17
|
+
require 'faraday'
|
18
|
+
require 'net/http/post/multipart'
|
19
|
+
|
19
20
|
# Requires supporting files with custom matchers and macros, etc,
|
20
21
|
# in ./support/ and its subdirectories.
|
21
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
22
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
22
23
|
|
23
24
|
RSpec.configure do |config|
|
24
|
-
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauricio Gomes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -199,30 +199,23 @@ files:
|
|
199
199
|
- ".document"
|
200
200
|
- ".gitignore"
|
201
201
|
- ".rspec"
|
202
|
+
- ".rubocop.yml"
|
202
203
|
- ".travis.yml"
|
203
204
|
- Appraisals
|
204
205
|
- CHANGELOG.md
|
205
206
|
- Gemfile
|
206
|
-
- Gemfile.lock
|
207
207
|
- LICENSE.txt
|
208
208
|
- README.md
|
209
209
|
- Rakefile
|
210
210
|
- VERSION
|
211
211
|
- api_auth.gemspec
|
212
212
|
- gemfiles/rails_23.gemfile
|
213
|
-
- gemfiles/rails_23.gemfile.lock
|
214
213
|
- gemfiles/rails_30.gemfile
|
215
|
-
- gemfiles/rails_30.gemfile.lock
|
216
214
|
- gemfiles/rails_31.gemfile
|
217
|
-
- gemfiles/rails_31.gemfile.lock
|
218
215
|
- gemfiles/rails_32.gemfile
|
219
|
-
- gemfiles/rails_32.gemfile.lock
|
220
216
|
- gemfiles/rails_4.gemfile
|
221
|
-
- gemfiles/rails_4.gemfile.lock
|
222
217
|
- gemfiles/rails_41.gemfile
|
223
|
-
- gemfiles/rails_41.gemfile.lock
|
224
218
|
- gemfiles/rails_42.gemfile
|
225
|
-
- gemfiles/rails_42.gemfile.lock
|
226
219
|
- lib/api-auth.rb
|
227
220
|
- lib/api_auth.rb
|
228
221
|
- lib/api_auth/base.rb
|
@@ -271,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
264
|
version: '0'
|
272
265
|
requirements: []
|
273
266
|
rubyforge_project:
|
274
|
-
rubygems_version: 2.
|
267
|
+
rubygems_version: 2.5.1
|
275
268
|
signing_key:
|
276
269
|
specification_version: 4
|
277
270
|
summary: Simple HMAC authentication for your APIs
|