rack-test 2.0.2 → 2.1.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/History.md +26 -0
- data/README.md +1 -1
- data/lib/rack/test/cookie_jar.rb +10 -4
- data/lib/rack/test/methods.rb +5 -6
- data/lib/rack/test/uploaded_file.rb +11 -7
- data/lib/rack/test/version.rb +1 -1
- data/lib/rack/test.rb +22 -54
- metadata +6 -8
- data/lib/rack/mock_session.rb +0 -2
- data/lib/rack/test/mock_digest_request.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98bb9656717c512790c5f65b20a8f0cfc7c2f14e4d9d98d5069e6e5910b256e5
|
4
|
+
data.tar.gz: 6305cac1636eef820a082a1431cef2bc24b445b1f902b65c550f976ba84f08e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 420e60a08ec2fa5fd92a358d28c0b17e0a943eb30962756360185091753bdd4eb55b7b58005aa84bb1907cfb7e8129166d1aed6282596f45b8b0f42dd1003306
|
7
|
+
data.tar.gz: b7446d71bf41a0f69b9812e867f7b472488ee0534d6206435b77e8266617486687044a814dd6c085003b823e0e349c83b1ca47ea296f1f23346957d66cbed0bc
|
data/History.md
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
## 2.1.0 / 2023-03-14
|
2
|
+
|
3
|
+
* Breaking changes:
|
4
|
+
* Digest authentication support, deprecated in 2.0.0, has been
|
5
|
+
removed (Jeremy Evans #307)
|
6
|
+
* requiring rack/mock_session, deprecated in 2.0.0, has been removed
|
7
|
+
(Jeremy Evans #307)
|
8
|
+
|
9
|
+
* Minor enhancements:
|
10
|
+
* The `original_filename` for `Rack::Test::UploadedFile` can now be
|
11
|
+
set even if the content of the file comes from a file path
|
12
|
+
(Stuart Chinery #314)
|
13
|
+
* Add `Rack::Test::Session#restore_state`, for executing a block
|
14
|
+
and restoring current state (last request, last response, and
|
15
|
+
cookies) after the block (Jeremy Evans #316)
|
16
|
+
* Make `Rack::Test::Methods` support `default_host` method similar to
|
17
|
+
`app`, which will set the default host used for requests to the app
|
18
|
+
(Jeremy Evans #317 #318)
|
19
|
+
* Allow responses to set cookie paths not matching the current
|
20
|
+
request URI. Such cookies will only be sent for paths matching
|
21
|
+
the cookie path (Chris Waters #322)
|
22
|
+
* Ignore leading dot for cookie domains, per RFC 6265 (Stephen Crosby
|
23
|
+
#329)
|
24
|
+
* Avoid creating empty multipart body if params is empty in
|
25
|
+
`Rack::Test::Session#env_for` (Ryunosuke Sato #331)
|
26
|
+
|
1
27
|
## 2.0.2 / 2022-06-28
|
2
28
|
|
3
29
|
* Bug fixes:
|
data/README.md
CHANGED
data/lib/rack/test/cookie_jar.rb
CHANGED
@@ -30,8 +30,9 @@ module Rack
|
|
30
30
|
@name, @value = parse_query(@raw, ';').to_a.first
|
31
31
|
@options = parse_query(options, ';')
|
32
32
|
|
33
|
-
if @options['domain']
|
33
|
+
if domain = @options['domain']
|
34
34
|
@exact_domain_match = false
|
35
|
+
domain[0] = '' if domain[0] == '.'
|
35
36
|
else
|
36
37
|
# If the domain attribute is not present in the cookie,
|
37
38
|
# the domain must match exactly.
|
@@ -94,13 +95,12 @@ module Rack
|
|
94
95
|
|
95
96
|
real_domain = domain =~ /^\./ ? domain[1..-1] : domain
|
96
97
|
!!((!secure? || (secure? && uri.scheme == 'https')) &&
|
97
|
-
uri.host =~ Regexp.new("#{'^' if @exact_domain_match}#{Regexp.escape(real_domain)}$", Regexp::IGNORECASE)
|
98
|
-
uri.path =~ Regexp.new("^#{Regexp.escape(path)}"))
|
98
|
+
uri.host =~ Regexp.new("#{'^' if @exact_domain_match}#{Regexp.escape(real_domain)}$", Regexp::IGNORECASE))
|
99
99
|
end
|
100
100
|
|
101
101
|
# Cookies that do not match the URI will not be sent in requests to the URI.
|
102
102
|
def matches?(uri)
|
103
|
-
!expired? && valid?(uri)
|
103
|
+
!expired? && valid?(uri) && uri.path.start_with?(path)
|
104
104
|
end
|
105
105
|
|
106
106
|
# Order cookies by name, path, and domain.
|
@@ -138,6 +138,12 @@ module Rack
|
|
138
138
|
@cookies = cookies.sort!
|
139
139
|
end
|
140
140
|
|
141
|
+
# Ensure the copy uses a distinct cookies array.
|
142
|
+
def initialize_copy(other)
|
143
|
+
super
|
144
|
+
@cookies = @cookies.dup
|
145
|
+
end
|
146
|
+
|
141
147
|
# Return the value for first cookie with the given name, or nil
|
142
148
|
# if no such cookie exists.
|
143
149
|
def [](name)
|
data/lib/rack/test/methods.rb
CHANGED
@@ -42,7 +42,11 @@ module Rack
|
|
42
42
|
# Backwards compatibility for capybara
|
43
43
|
build_rack_mock_session
|
44
44
|
else
|
45
|
-
|
45
|
+
if respond_to?(:default_host)
|
46
|
+
Session.new(app, default_host)
|
47
|
+
else
|
48
|
+
Session.new(app)
|
49
|
+
end
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
@@ -61,11 +65,6 @@ module Rack
|
|
61
65
|
@_rack_test_current_session = session
|
62
66
|
end
|
63
67
|
|
64
|
-
def digest_authorize(username, password) # :nodoc:
|
65
|
-
warn 'digest authentication support will be removed in rack-test 2.1', uplevel: 1
|
66
|
-
current_session._digest_authorize(username, password)
|
67
|
-
end
|
68
|
-
|
69
68
|
def_delegators(:current_session,
|
70
69
|
:request,
|
71
70
|
:get,
|
@@ -27,16 +27,18 @@ module Rack
|
|
27
27
|
# content :: is a path to a file, or an {IO} or {StringIO} object representing the content.
|
28
28
|
# content_type :: MIME type of the file
|
29
29
|
# binary :: Whether the file should be set to binmode (content treated as binary).
|
30
|
-
# original_filename :: The filename to use for the file if
|
30
|
+
# original_filename :: The filename to use for the file. Required if content is StringIO, optional override if not
|
31
31
|
def initialize(content, content_type = 'text/plain', binary = false, original_filename: nil)
|
32
|
+
@content_type = content_type
|
33
|
+
@original_filename = original_filename
|
34
|
+
|
32
35
|
case content
|
33
36
|
when StringIO
|
34
|
-
initialize_from_stringio(content
|
37
|
+
initialize_from_stringio(content)
|
35
38
|
else
|
36
39
|
initialize_from_file_path(content)
|
37
40
|
end
|
38
41
|
|
39
|
-
@content_type = content_type
|
40
42
|
@tempfile.binmode if binary
|
41
43
|
end
|
42
44
|
|
@@ -85,16 +87,18 @@ module Rack
|
|
85
87
|
private
|
86
88
|
|
87
89
|
# Use the StringIO as the tempfile.
|
88
|
-
def initialize_from_stringio(stringio
|
90
|
+
def initialize_from_stringio(stringio)
|
91
|
+
raise(ArgumentError, 'Missing `original_filename` for StringIO object') unless @original_filename
|
92
|
+
|
89
93
|
@tempfile = stringio
|
90
|
-
@original_filename = original_filename || raise(ArgumentError, 'Missing `original_filename` for StringIO object')
|
91
94
|
end
|
92
95
|
|
93
|
-
# Create a tempfile and copy the content from the given path into the tempfile
|
96
|
+
# Create a tempfile and copy the content from the given path into the tempfile, optionally renaming if
|
97
|
+
# original_filename has been set.
|
94
98
|
def initialize_from_file_path(path)
|
95
99
|
raise "#{path} file does not exist" unless ::File.exist?(path)
|
96
100
|
|
97
|
-
@original_filename
|
101
|
+
@original_filename ||= ::File.basename(path)
|
98
102
|
extension = ::File.extname(@original_filename)
|
99
103
|
|
100
104
|
@tempfile = Tempfile.new([::File.basename(@original_filename, extension), extension])
|
data/lib/rack/test/version.rb
CHANGED
data/lib/rack/test.rb
CHANGED
@@ -98,8 +98,6 @@ module Rack
|
|
98
98
|
# If a block is given, #last_response is also yielded to the block.
|
99
99
|
def initialize(app, default_host = DEFAULT_HOST)
|
100
100
|
@env = {}
|
101
|
-
@digest_username = nil
|
102
|
-
@digest_password = nil
|
103
101
|
@app = app
|
104
102
|
@after_request = []
|
105
103
|
@default_host = default_host
|
@@ -204,21 +202,6 @@ module Rack
|
|
204
202
|
|
205
203
|
alias authorize basic_authorize
|
206
204
|
|
207
|
-
# Set the username and password for HTTP Digest authorization, to be
|
208
|
-
# included in subsequent requests in the HTTP_AUTHORIZATION header.
|
209
|
-
# This method is deprecated and will be removed in rack-test 2.1
|
210
|
-
#
|
211
|
-
# Example:
|
212
|
-
# digest_authorize "bryan", "secret"
|
213
|
-
def digest_authorize(username, password)
|
214
|
-
warn 'digest authentication support will be removed in rack-test 2.1', uplevel: 1
|
215
|
-
_digest_authorize(username, password)
|
216
|
-
end
|
217
|
-
def _digest_authorize(username, password) # :nodoc:
|
218
|
-
@digest_username = username
|
219
|
-
@digest_password = password
|
220
|
-
end
|
221
|
-
|
222
205
|
# Rack::Test will not follow any redirects automatically. This method
|
223
206
|
# will follow the redirect returned (including setting the Referer header
|
224
207
|
# on the new request) in the last response. If the last response was not
|
@@ -251,6 +234,25 @@ module Rack
|
|
251
234
|
)
|
252
235
|
end
|
253
236
|
|
237
|
+
# Yield to the block, and restore the last request, last response, and
|
238
|
+
# cookie jar to the state they were prior to block execution upon
|
239
|
+
# exiting the block.
|
240
|
+
def restore_state
|
241
|
+
request = @last_request
|
242
|
+
response = @last_response
|
243
|
+
cookie_jar = @cookie_jar.dup
|
244
|
+
after_request = @after_request.dup
|
245
|
+
|
246
|
+
begin
|
247
|
+
yield
|
248
|
+
ensure
|
249
|
+
@last_request = request
|
250
|
+
@last_response = response
|
251
|
+
@cookie_jar = cookie_jar
|
252
|
+
@after_request = after_request
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
254
256
|
private
|
255
257
|
|
256
258
|
# :nocov:
|
@@ -310,7 +312,7 @@ module Rack
|
|
310
312
|
multipart = env.has_key?(:multipart) ? env.delete(:multipart) : env['CONTENT_TYPE'].start_with?('multipart/')
|
311
313
|
|
312
314
|
if params.is_a?(Hash)
|
313
|
-
if data = build_multipart(params, false, multipart)
|
315
|
+
if !params.empty? && data = build_multipart(params, false, multipart)
|
314
316
|
env[:input] = data
|
315
317
|
env['CONTENT_LENGTH'] ||= data.length.to_s
|
316
318
|
env['CONTENT_TYPE'] = "#{multipart_content_type(env)}; boundary=#{MULTIPART_BOUNDARY}"
|
@@ -363,43 +365,9 @@ module Rack
|
|
363
365
|
@after_request.each(&:call)
|
364
366
|
@last_response.finish
|
365
367
|
|
366
|
-
if
|
367
|
-
auth_env = env.merge('HTTP_AUTHORIZATION' => digest_auth_header,
|
368
|
-
'rack-test.digest_auth_retry' => true)
|
369
|
-
auth_env.delete('rack.request')
|
370
|
-
process_request(uri, auth_env)
|
371
|
-
else
|
372
|
-
yield last_response if block_given?
|
373
|
-
|
374
|
-
last_response
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
def digest_auth_header
|
379
|
-
require_relative 'test/mock_digest_request'
|
380
|
-
|
381
|
-
challenge = last_response['WWW-Authenticate'].split(' ', 2).last
|
382
|
-
params = Rack::Auth::Digest::Params.parse(challenge)
|
383
|
-
|
384
|
-
params.merge!('username' => @digest_username,
|
385
|
-
'nc' => '00000001',
|
386
|
-
'cnonce' => 'nonsensenonce',
|
387
|
-
'uri' => last_request.fullpath,
|
388
|
-
'method' => last_request.env['REQUEST_METHOD'])
|
389
|
-
|
390
|
-
params['response'] = MockDigestRequest_.new(params).response(@digest_password)
|
368
|
+
yield @last_response if block_given?
|
391
369
|
|
392
|
-
|
393
|
-
end
|
394
|
-
|
395
|
-
def retry_with_digest_auth?(env)
|
396
|
-
last_response.status == 401 &&
|
397
|
-
digest_auth_configured? &&
|
398
|
-
!env['rack-test.digest_auth_retry']
|
399
|
-
end
|
400
|
-
|
401
|
-
def digest_auth_configured?
|
402
|
-
@digest_username
|
370
|
+
@last_response
|
403
371
|
end
|
404
372
|
end
|
405
373
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
- Bryan Helmkamp
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -81,11 +81,9 @@ files:
|
|
81
81
|
- History.md
|
82
82
|
- MIT-LICENSE.txt
|
83
83
|
- README.md
|
84
|
-
- lib/rack/mock_session.rb
|
85
84
|
- lib/rack/test.rb
|
86
85
|
- lib/rack/test/cookie_jar.rb
|
87
86
|
- lib/rack/test/methods.rb
|
88
|
-
- lib/rack/test/mock_digest_request.rb
|
89
87
|
- lib/rack/test/uploaded_file.rb
|
90
88
|
- lib/rack/test/utils.rb
|
91
89
|
- lib/rack/test/version.rb
|
@@ -97,7 +95,7 @@ metadata:
|
|
97
95
|
bug_tracker_uri: https://github.com/rack/rack-test/issues
|
98
96
|
mailing_list_uri: https://github.com/rack/rack-test/discussions
|
99
97
|
changelog_uri: https://github.com/rack/rack-test/blob/main/History.md
|
100
|
-
post_install_message:
|
98
|
+
post_install_message:
|
101
99
|
rdoc_options: []
|
102
100
|
require_paths:
|
103
101
|
- lib
|
@@ -112,8 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
110
|
- !ruby/object:Gem::Version
|
113
111
|
version: '0'
|
114
112
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
116
|
-
signing_key:
|
113
|
+
rubygems_version: 3.4.6
|
114
|
+
signing_key:
|
117
115
|
specification_version: 4
|
118
116
|
summary: Simple testing API built on Rack
|
119
117
|
test_files: []
|
data/lib/rack/mock_session.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# :nocov:
|
4
|
-
require 'rack/auth/digest' unless defined?(Rack::Auth::Digest)
|
5
|
-
# :nocov:
|
6
|
-
|
7
|
-
module Rack
|
8
|
-
module Test
|
9
|
-
class MockDigestRequest_ # :nodoc:
|
10
|
-
def initialize(params)
|
11
|
-
@params = params
|
12
|
-
end
|
13
|
-
|
14
|
-
def method_missing(sym)
|
15
|
-
if @params.key? k = sym.to_s
|
16
|
-
return @params[k]
|
17
|
-
end
|
18
|
-
|
19
|
-
super
|
20
|
-
end
|
21
|
-
|
22
|
-
def method
|
23
|
-
@params['method']
|
24
|
-
end
|
25
|
-
|
26
|
-
def response(password)
|
27
|
-
Rack::Auth::Digest::MD5.new(nil).send :digest, self, password
|
28
|
-
end
|
29
|
-
end
|
30
|
-
MockDigestRequest = MockDigestRequest_
|
31
|
-
# :nocov:
|
32
|
-
deprecate_constant :MockDigestRequest if respond_to?(:deprecate_constant, true)
|
33
|
-
# :nocov:
|
34
|
-
end
|
35
|
-
end
|