webmock 1.24.0 → 1.24.1
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.
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1034,6 +1034,7 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1034
1034
|
* Alexey Zapparov
|
1035
1035
|
* Pablo Brasero
|
1036
1036
|
* Cedric Pimenta
|
1037
|
+
* Michiel Karnebeek
|
1037
1038
|
|
1038
1039
|
For a full list of contributors you can visit the
|
1039
1040
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
@@ -172,9 +172,6 @@ if defined?(::HTTPClient)
|
|
172
172
|
uri.port = req.header.request_uri.port
|
173
173
|
uri = uri.omit(:userinfo)
|
174
174
|
|
175
|
-
auth = www_auth.basic_auth
|
176
|
-
auth.challenge(req.header.request_uri, nil)
|
177
|
-
|
178
175
|
@request_filter.each do |filter|
|
179
176
|
filter.filter_request(req)
|
180
177
|
end
|
@@ -186,11 +183,9 @@ if defined?(::HTTPClient)
|
|
186
183
|
end
|
187
184
|
headers = headers_from_session(uri).merge(headers)
|
188
185
|
|
189
|
-
if
|
190
|
-
|
191
|
-
userinfo =
|
192
|
-
headers.reject! {|k,v| k =~ /[Aa]uthorization/ && v =~ /^Basic / } #we added it to url userinfo
|
193
|
-
uri.userinfo = userinfo
|
186
|
+
if auth_cred = auth_cred_from_www_auth(req) || auth_cred_from_headers(headers)
|
187
|
+
remove_authorization_header headers
|
188
|
+
uri.userinfo = userinfo_from_auth_cred auth_cred
|
194
189
|
end
|
195
190
|
|
196
191
|
signature = WebMock::RequestSignature.new(
|
@@ -208,6 +203,38 @@ if defined?(::HTTPClient)
|
|
208
203
|
signature
|
209
204
|
end
|
210
205
|
|
206
|
+
def userinfo_from_auth_cred auth_cred
|
207
|
+
userinfo = WebMock::Util::Headers.decode_userinfo_from_header(auth_cred)
|
208
|
+
WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)
|
209
|
+
end
|
210
|
+
|
211
|
+
def remove_authorization_header headers
|
212
|
+
headers.reject! do |k, v|
|
213
|
+
next unless k =~ /[Aa]uthorization/
|
214
|
+
if v.is_a? Array
|
215
|
+
v.reject! { |v| v =~ /^Basic / }
|
216
|
+
v.length == 0
|
217
|
+
elsif v.is_a? String
|
218
|
+
v =~ /^Basic /
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def auth_cred_from_www_auth(req)
|
224
|
+
auth = www_auth.basic_auth
|
225
|
+
auth.challenge(req.header.request_uri, nil)
|
226
|
+
auth.get(req) if auth.scheme == 'Basic'
|
227
|
+
end
|
228
|
+
|
229
|
+
def auth_cred_from_headers(headers)
|
230
|
+
headers.each do |k,v|
|
231
|
+
next unless k =~ /[Aa]uthorization/
|
232
|
+
return v if v.is_a?(String) && v =~ /^Basic /
|
233
|
+
v.each { |v| return v if v =~ /^Basic / } if v.is_a? Array
|
234
|
+
end
|
235
|
+
nil
|
236
|
+
end
|
237
|
+
|
211
238
|
def webmock_responses
|
212
239
|
@webmock_responses ||= Hash.new do |hash, request_signature|
|
213
240
|
hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature)
|
data/lib/webmock/version.rb
CHANGED
@@ -186,4 +186,12 @@ describe "HTTPClient" do
|
|
186
186
|
expect(@response.body).to eq body
|
187
187
|
end
|
188
188
|
end
|
189
|
+
|
190
|
+
context 'credentials' do
|
191
|
+
it 'are detected when manually specifying Authorization header' do
|
192
|
+
stub_request(:get, 'username:password@www.example.com').to_return(:status => 200)
|
193
|
+
headers = {'Authorization' => 'Basic dXNlcm5hbWU6cGFzc3dvcmQ='}
|
194
|
+
expect(http_request(:get, 'http://www.example.com/', {:headers => headers}).status).to eql('200')
|
195
|
+
end
|
196
|
+
end
|
189
197
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 117
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 24
|
9
|
-
-
|
10
|
-
version: 1.24.
|
9
|
+
- 1
|
10
|
+
version: 1.24.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bartosz Blimke
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2016-02-
|
18
|
+
date: 2016-02-23 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|