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.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +71 -0
- data/.gitignore +13 -44
- data/.rubocop.yml +39 -0
- data/.rubocop_todo.yml +83 -0
- data/Appraisals +12 -36
- data/CHANGELOG.md +75 -1
- data/README.md +155 -52
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/api_auth.gemspec +35 -23
- data/gemfiles/rails_60.gemfile +9 -0
- data/gemfiles/rails_61.gemfile +9 -0
- data/gemfiles/rails_70.gemfile +9 -0
- data/lib/api-auth.rb +1 -1
- data/lib/api_auth/base.rb +41 -35
- data/lib/api_auth/errors.rb +4 -3
- data/lib/api_auth/headers.rb +38 -42
- data/lib/api_auth/helpers.rb +7 -16
- data/lib/api_auth/railtie.rb +34 -74
- data/lib/api_auth/request_drivers/action_controller.rb +27 -27
- data/lib/api_auth/request_drivers/action_dispatch.rb +0 -6
- data/lib/api_auth/request_drivers/curb.rb +16 -21
- data/lib/api_auth/request_drivers/faraday.rb +25 -34
- data/lib/api_auth/request_drivers/faraday_env.rb +102 -0
- data/lib/api_auth/request_drivers/grape_request.rb +87 -0
- data/lib/api_auth/request_drivers/http.rb +96 -0
- data/lib/api_auth/request_drivers/httpi.rb +22 -27
- data/lib/api_auth/request_drivers/net_http.rb +21 -26
- data/lib/api_auth/request_drivers/rack.rb +23 -28
- data/lib/api_auth/request_drivers/rest_client.rb +24 -29
- data/lib/api_auth.rb +4 -0
- data/lib/faraday/api_auth/middleware.rb +35 -0
- data/lib/faraday/api_auth.rb +8 -0
- data/spec/api_auth_spec.rb +135 -96
- data/spec/faraday_middleware_spec.rb +17 -0
- data/spec/headers_spec.rb +148 -108
- data/spec/helpers_spec.rb +8 -10
- data/spec/railtie_spec.rb +80 -99
- data/spec/request_drivers/action_controller_spec.rb +122 -79
- data/spec/request_drivers/action_dispatch_spec.rb +212 -85
- data/spec/request_drivers/curb_spec.rb +36 -33
- data/spec/request_drivers/faraday_env_spec.rb +188 -0
- data/spec/request_drivers/faraday_spec.rb +87 -83
- data/spec/request_drivers/grape_request_spec.rb +280 -0
- data/spec/request_drivers/http_spec.rb +190 -0
- data/spec/request_drivers/httpi_spec.rb +59 -59
- data/spec/request_drivers/net_http_spec.rb +70 -66
- data/spec/request_drivers/rack_spec.rb +101 -97
- data/spec/request_drivers/rest_client_spec.rb +218 -144
- data/spec/spec_helper.rb +15 -12
- metadata +144 -83
- data/.travis.yml +0 -40
- data/Gemfile.lock +0 -115
- data/gemfiles/rails_23.gemfile +0 -9
- data/gemfiles/rails_23.gemfile.lock +0 -70
- data/gemfiles/rails_30.gemfile +0 -9
- data/gemfiles/rails_30.gemfile.lock +0 -92
- data/gemfiles/rails_31.gemfile +0 -9
- data/gemfiles/rails_31.gemfile.lock +0 -98
- data/gemfiles/rails_32.gemfile +0 -9
- data/gemfiles/rails_32.gemfile.lock +0 -97
- data/gemfiles/rails_4.gemfile +0 -9
- data/gemfiles/rails_4.gemfile.lock +0 -94
- data/gemfiles/rails_41.gemfile +0 -9
- data/gemfiles/rails_41.gemfile.lock +0 -98
- data/gemfiles/rails_42.gemfile +0 -9
- 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(:
|
|
6
|
+
let(:request_path) { 'https://localhost/resource.xml?foo=bar&bar=foo' }
|
|
6
7
|
|
|
7
|
-
let(:
|
|
8
|
-
|
|
9
|
-
let(:request_headers){
|
|
8
|
+
let(:request_headers) do
|
|
10
9
|
{
|
|
11
|
-
'Authorization'
|
|
12
|
-
'Content-
|
|
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
|
-
:
|
|
21
|
-
:
|
|
22
|
-
:
|
|
23
|
-
:
|
|
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
|
|
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
|
|
35
|
-
expect(driven_request.
|
|
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
|
|
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
|
|
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
|
|
52
|
-
expect(driven_request.
|
|
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
|
|
54
|
+
it 'treats no body as empty string' do
|
|
56
55
|
request = RestClient::Request.new(
|
|
57
|
-
:
|
|
58
|
-
:
|
|
59
|
-
:
|
|
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.
|
|
61
|
+
expect(driven_request.calculated_hash).to eq('47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=')
|
|
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
|
-
:
|
|
71
|
-
:
|
|
72
|
-
:
|
|
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
|
|
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
|
-
:
|
|
85
|
-
:
|
|
86
|
-
:
|
|
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
|
|
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_hash' do
|
|
104
|
+
context 'when getting' do
|
|
106
105
|
let(:request) do
|
|
107
106
|
RestClient::Request.new(
|
|
108
|
-
:
|
|
109
|
-
:
|
|
110
|
-
:
|
|
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
|
|
115
|
-
driven_request.
|
|
116
|
-
expect(request.headers[
|
|
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
|
|
119
|
+
context 'when posting' do
|
|
121
120
|
let(:request) do
|
|
122
121
|
RestClient::Request.new(
|
|
123
|
-
:
|
|
124
|
-
:
|
|
125
|
-
:
|
|
126
|
-
:
|
|
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
|
|
131
|
-
driven_request.
|
|
132
|
-
expect(request.headers[
|
|
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
|
|
136
|
-
driven_request.
|
|
137
|
-
expect(driven_request.
|
|
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
|
|
140
|
+
context 'when putting' do
|
|
142
141
|
let(:request) do
|
|
143
142
|
RestClient::Request.new(
|
|
144
|
-
:
|
|
145
|
-
:
|
|
146
|
-
:
|
|
147
|
-
:
|
|
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
|
|
152
|
-
driven_request.
|
|
153
|
-
expect(request.headers[
|
|
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
|
|
157
|
-
driven_request.
|
|
158
|
-
expect(driven_request.
|
|
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
|
|
161
|
+
context 'when deleting' do
|
|
163
162
|
let(:request) do
|
|
164
163
|
RestClient::Request.new(
|
|
165
|
-
:
|
|
166
|
-
:
|
|
167
|
-
:
|
|
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
|
|
172
|
-
driven_request.
|
|
173
|
-
expect(request.headers[
|
|
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
|
|
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 'content_hash_mismatch?' do
|
|
203
|
+
context 'when getting' do
|
|
207
204
|
let(:request) do
|
|
208
205
|
RestClient::Request.new(
|
|
209
|
-
:
|
|
210
|
-
:
|
|
211
|
-
:
|
|
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
|
|
216
|
-
expect(driven_request.
|
|
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
|
|
217
|
+
context 'when posting' do
|
|
221
218
|
let(:request) do
|
|
222
219
|
RestClient::Request.new(
|
|
223
|
-
:
|
|
224
|
-
:
|
|
225
|
-
:
|
|
226
|
-
:
|
|
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
|
|
231
|
-
let(:request_headers)
|
|
227
|
+
context 'when calculated matches sent' do
|
|
228
|
+
let(:request_headers) do
|
|
232
229
|
{
|
|
233
|
-
'Authorization'
|
|
234
|
-
'Content-
|
|
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
|
|
241
|
-
expect(driven_request.
|
|
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'
|
|
249
|
-
'Content-
|
|
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
|
|
256
|
-
expect(driven_request.
|
|
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
|
|
258
|
+
context 'when putting' do
|
|
262
259
|
let(:request) do
|
|
263
260
|
RestClient::Request.new(
|
|
264
|
-
:
|
|
265
|
-
:
|
|
266
|
-
:
|
|
267
|
-
:
|
|
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
|
|
272
|
-
let(:request_headers)
|
|
268
|
+
context 'when calculated matches sent' do
|
|
269
|
+
let(:request_headers) do
|
|
273
270
|
{
|
|
274
|
-
'Authorization'
|
|
275
|
-
'Content-
|
|
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
|
|
282
|
-
expect(driven_request.
|
|
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'
|
|
290
|
-
'Content-
|
|
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
|
|
297
|
-
expect(driven_request.
|
|
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
|
|
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
|
-
:
|
|
306
|
-
:
|
|
307
|
-
:
|
|
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
|
-
|
|
312
|
-
|
|
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
|
|
386
|
+
describe 'edge cases' do
|
|
318
387
|
it "doesn't mess up symbol based headers" do
|
|
319
|
-
headers = { 'Content-
|
|
320
|
-
:content_type =>
|
|
321
|
-
'Date' =>
|
|
322
|
-
request = RestClient::Request.new(:
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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 }
|