rack 1.6.13 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/COPYING +1 -1
- data/HISTORY.md +138 -8
- data/README.rdoc +18 -28
- data/Rakefile +6 -14
- data/SPEC +3 -3
- data/contrib/rack_logo.svg +164 -111
- data/example/protectedlobster.rb +1 -1
- data/example/protectedlobster.ru +1 -1
- data/lib/rack/auth/abstract/request.rb +5 -1
- data/lib/rack/auth/digest/params.rb +2 -3
- data/lib/rack/auth/digest/request.rb +1 -1
- data/lib/rack/body_proxy.rb +14 -9
- data/lib/rack/builder.rb +3 -3
- data/lib/rack/chunked.rb +5 -5
- data/lib/rack/{commonlogger.rb → common_logger.rb} +3 -3
- data/lib/rack/content_length.rb +2 -2
- data/lib/rack/deflater.rb +4 -39
- data/lib/rack/directory.rb +66 -54
- data/lib/rack/etag.rb +5 -4
- data/lib/rack/events.rb +154 -0
- data/lib/rack/file.rb +64 -40
- data/lib/rack/handler/cgi.rb +15 -16
- data/lib/rack/handler/fastcgi.rb +13 -14
- data/lib/rack/handler/lsws.rb +11 -11
- data/lib/rack/handler/scgi.rb +15 -15
- data/lib/rack/handler/thin.rb +3 -0
- data/lib/rack/handler/webrick.rb +24 -26
- data/lib/rack/handler.rb +3 -25
- data/lib/rack/head.rb +15 -17
- data/lib/rack/lint.rb +40 -40
- data/lib/rack/lobster.rb +1 -1
- data/lib/rack/lock.rb +15 -10
- data/lib/rack/logger.rb +2 -2
- data/lib/rack/media_type.rb +38 -0
- data/lib/rack/{methodoverride.rb → method_override.rb} +6 -6
- data/lib/rack/mime.rb +18 -5
- data/lib/rack/mock.rb +36 -54
- data/lib/rack/multipart/generator.rb +5 -5
- data/lib/rack/multipart/parser.rb +270 -157
- data/lib/rack/multipart/uploaded_file.rb +1 -2
- data/lib/rack/multipart.rb +35 -6
- data/lib/rack/{nulllogger.rb → null_logger.rb} +1 -1
- data/lib/rack/query_parser.rb +192 -0
- data/lib/rack/recursive.rb +8 -8
- data/lib/rack/request.rb +394 -305
- data/lib/rack/response.rb +130 -57
- data/lib/rack/rewindable_input.rb +1 -12
- data/lib/rack/runtime.rb +10 -18
- data/lib/rack/sendfile.rb +5 -7
- data/lib/rack/server.rb +30 -23
- data/lib/rack/session/abstract/id.rb +110 -75
- data/lib/rack/session/cookie.rb +24 -17
- data/lib/rack/session/memcache.rb +9 -9
- data/lib/rack/session/pool.rb +8 -8
- data/lib/rack/show_exceptions.rb +386 -0
- data/lib/rack/{showstatus.rb → show_status.rb} +3 -3
- data/lib/rack/static.rb +30 -5
- data/lib/rack/tempfile_reaper.rb +2 -2
- data/lib/rack/urlmap.rb +15 -14
- data/lib/rack/utils.rb +138 -211
- data/lib/rack.rb +70 -21
- data/rack.gemspec +10 -9
- data/test/builder/an_underscore_app.rb +5 -0
- data/test/builder/options.ru +1 -1
- data/test/cgi/test.fcgi +1 -0
- data/test/cgi/test.gz +0 -0
- data/test/helper.rb +34 -0
- data/test/multipart/filename_with_encoded_words +7 -0
- data/test/multipart/filename_with_single_quote +7 -0
- data/test/multipart/quoted +15 -0
- data/test/multipart/rack-logo.png +0 -0
- data/test/multipart/unity3d_wwwform +11 -0
- data/test/registering_handler/rack/handler/registering_myself.rb +1 -1
- data/test/spec_auth_basic.rb +27 -19
- data/test/spec_auth_digest.rb +47 -46
- data/test/spec_body_proxy.rb +27 -27
- data/test/spec_builder.rb +51 -41
- data/test/spec_cascade.rb +24 -22
- data/test/spec_cgi.rb +49 -67
- data/test/spec_chunked.rb +37 -35
- data/test/{spec_commonlogger.rb → spec_common_logger.rb} +23 -21
- data/test/{spec_conditionalget.rb → spec_conditional_get.rb} +29 -28
- data/test/spec_config.rb +3 -2
- data/test/spec_content_length.rb +18 -17
- data/test/spec_content_type.rb +13 -12
- data/test/spec_deflater.rb +85 -49
- data/test/spec_directory.rb +87 -27
- data/test/spec_etag.rb +32 -31
- data/test/spec_events.rb +133 -0
- data/test/spec_fastcgi.rb +50 -72
- data/test/spec_file.rb +120 -77
- data/test/spec_handler.rb +19 -34
- data/test/spec_head.rb +15 -14
- data/test/spec_lint.rb +164 -199
- data/test/spec_lobster.rb +24 -23
- data/test/spec_lock.rb +79 -39
- data/test/spec_logger.rb +4 -3
- data/test/spec_media_type.rb +42 -0
- data/test/{spec_methodoverride.rb → spec_method_override.rb} +34 -35
- data/test/spec_mime.rb +19 -19
- data/test/spec_mock.rb +206 -144
- data/test/spec_multipart.rb +322 -200
- data/test/{spec_nulllogger.rb → spec_null_logger.rb} +5 -4
- data/test/spec_recursive.rb +17 -14
- data/test/spec_request.rb +780 -605
- data/test/spec_response.rb +233 -112
- data/test/spec_rewindable_input.rb +50 -40
- data/test/spec_runtime.rb +11 -10
- data/test/spec_sendfile.rb +30 -35
- data/test/spec_server.rb +78 -52
- data/test/spec_session_abstract_id.rb +11 -33
- data/test/spec_session_abstract_session_hash.rb +45 -0
- data/test/spec_session_cookie.rb +99 -67
- data/test/spec_session_memcache.rb +67 -68
- data/test/spec_session_pool.rb +52 -51
- data/test/{spec_showexceptions.rb → spec_show_exceptions.rb} +23 -28
- data/test/{spec_showstatus.rb → spec_show_status.rb} +36 -35
- data/test/spec_static.rb +71 -32
- data/test/spec_tempfile_reaper.rb +11 -10
- data/test/spec_thin.rb +55 -50
- data/test/spec_urlmap.rb +79 -78
- data/test/spec_utils.rb +441 -346
- data/test/spec_version.rb +2 -8
- data/test/spec_webrick.rb +93 -71
- data/test/static/foo.html +1 -0
- data/test/testrequest.rb +1 -1
- data/test/unregistered_handler/rack/handler/unregistered.rb +1 -1
- data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +1 -1
- metadata +57 -36
- data/KNOWN-ISSUES +0 -44
- data/lib/rack/backports/uri/common_18.rb +0 -56
- data/lib/rack/backports/uri/common_192.rb +0 -52
- data/lib/rack/backports/uri/common_193.rb +0 -29
- data/lib/rack/handler/evented_mongrel.rb +0 -8
- data/lib/rack/handler/mongrel.rb +0 -106
- data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
- data/lib/rack/showexceptions.rb +0 -387
- data/lib/rack/utils/okjson.rb +0 -600
- data/test/spec_mongrel.rb +0 -182
- /data/lib/rack/{conditionalget.rb → conditional_get.rb} +0 -0
data/rack.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rack"
|
3
|
-
s.version
|
3
|
+
s.version = File.read('lib/rack.rb')[/RELEASE += +([\"\'])([\d][\w\.]+)\1/, 2]
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "a modular Ruby webserver interface"
|
6
6
|
s.license = "MIT"
|
@@ -12,22 +12,23 @@ the simplest way possible, it unifies and distills the API for web
|
|
12
12
|
servers, web frameworks, and software in between (the so-called
|
13
13
|
middleware) into a single method call.
|
14
14
|
|
15
|
-
Also see
|
15
|
+
Also see https://rack.github.io/.
|
16
16
|
EOF
|
17
17
|
|
18
18
|
s.files = Dir['{bin/*,contrib/*,example/*,lib/**/*,test/**/*}'] +
|
19
|
-
%w(COPYING
|
19
|
+
%w(COPYING rack.gemspec Rakefile README.rdoc SPEC)
|
20
20
|
s.bindir = 'bin'
|
21
21
|
s.executables << 'rackup'
|
22
22
|
s.require_path = 'lib'
|
23
|
-
s.extra_rdoc_files = ['README.rdoc', '
|
23
|
+
s.extra_rdoc_files = ['README.rdoc', 'HISTORY.md']
|
24
24
|
s.test_files = Dir['test/spec_*.rb']
|
25
25
|
|
26
|
-
s.author = '
|
27
|
-
s.email = '
|
28
|
-
s.homepage = '
|
29
|
-
s.
|
26
|
+
s.author = 'Leah Neukirchen'
|
27
|
+
s.email = 'leah@vuxu.org'
|
28
|
+
s.homepage = 'https://rack.github.io/'
|
29
|
+
s.required_ruby_version = '>= 2.2.2'
|
30
30
|
|
31
|
-
s.add_development_dependency '
|
31
|
+
s.add_development_dependency 'minitest', "~> 5.0"
|
32
|
+
s.add_development_dependency 'minitest-sprint'
|
32
33
|
s.add_development_dependency 'rake'
|
33
34
|
end
|
data/test/builder/options.ru
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
#\ -d
|
1
|
+
#\ -d -p 2929 --env test
|
2
2
|
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
|
data/test/cgi/test.fcgi
CHANGED
data/test/cgi/test.gz
ADDED
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class TestCase < Minitest::Test
|
5
|
+
# Check for Lighttpd and launch it for tests if available.
|
6
|
+
`which lighttpd`
|
7
|
+
|
8
|
+
if $?.success?
|
9
|
+
begin
|
10
|
+
# Keep this first.
|
11
|
+
LIGHTTPD_PID = fork {
|
12
|
+
ENV['RACK_ENV'] = 'deployment'
|
13
|
+
ENV['RUBYLIB'] = [
|
14
|
+
::File.expand_path('../../lib', __FILE__),
|
15
|
+
ENV['RUBYLIB'],
|
16
|
+
].compact.join(':')
|
17
|
+
|
18
|
+
Dir.chdir(::File.expand_path("../cgi", __FILE__)) do
|
19
|
+
exec "lighttpd -D -f lighttpd.conf"
|
20
|
+
end
|
21
|
+
}
|
22
|
+
rescue NotImplementedError
|
23
|
+
warn "Your Ruby doesn't support Kernel#fork. Skipping Rack::Handler::CGI and ::FastCGI tests."
|
24
|
+
else
|
25
|
+
Minitest.after_run do
|
26
|
+
Process.kill 15, LIGHTTPD_PID
|
27
|
+
Process.wait LIGHTTPD_PID
|
28
|
+
end
|
29
|
+
end
|
30
|
+
else
|
31
|
+
warn "Lighttpd isn't installed. Skipping Rack::Handler::CGI and FastCGI tests. Install lighttpd to run them."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
--AaB:03x
|
2
|
+
Content-Disposition: form-data; name="submit-name"
|
3
|
+
|
4
|
+
Larry
|
5
|
+
--AaB:03x
|
6
|
+
Content-Disposition: form-data; name="submit-name-with-content"
|
7
|
+
Content-Type: text/plain
|
8
|
+
|
9
|
+
Berry
|
10
|
+
--AaB:03x
|
11
|
+
Content-Disposition: form-data; name="files"; filename="file1.txt"
|
12
|
+
Content-Type: text/plain
|
13
|
+
|
14
|
+
contents
|
15
|
+
--AaB:03x--
|
Binary file
|
@@ -0,0 +1,11 @@
|
|
1
|
+
--AaB03x
|
2
|
+
Content-Type: text/plain; charset="utf-8"
|
3
|
+
Content-disposition: form-data; name="user_sid"
|
4
|
+
|
5
|
+
bbf14f82-d2aa-4c07-9fb8-ca6714a7ea97
|
6
|
+
--AaB03x
|
7
|
+
Content-Type: image/png; charset=UTF-8
|
8
|
+
Content-disposition: form-data; name="file";
|
9
|
+
filename="b67879ed-bfed-4491-a8cc-f99cca769f94.png"
|
10
|
+
|
11
|
+
--AaB03x
|
data/test/spec_auth_basic.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'minitest/autorun'
|
1
2
|
require 'rack/auth/basic'
|
2
3
|
require 'rack/lint'
|
3
4
|
require 'rack/mock'
|
@@ -32,50 +33,57 @@ describe Rack::Auth::Basic do
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def assert_basic_auth_challenge(response)
|
35
|
-
response.
|
36
|
-
response.status.
|
37
|
-
response.
|
38
|
-
response.headers['WWW-Authenticate'].
|
39
|
-
response.body.
|
36
|
+
response.must_be :client_error?
|
37
|
+
response.status.must_equal 401
|
38
|
+
response.must_include 'WWW-Authenticate'
|
39
|
+
response.headers['WWW-Authenticate'].must_match(/Basic realm="#{Regexp.escape(realm)}"/)
|
40
|
+
response.body.must_be :empty?
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
+
it 'challenge correctly when no credentials are specified' do
|
43
44
|
request do |response|
|
44
45
|
assert_basic_auth_challenge response
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
|
49
|
+
it 'rechallenge if incorrect credentials are specified' do
|
49
50
|
request_with_basic_auth 'joe', 'password' do |response|
|
50
51
|
assert_basic_auth_challenge response
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
54
|
-
|
55
|
+
it 'return application output if correct credentials are specified' do
|
55
56
|
request_with_basic_auth 'Boss', 'password' do |response|
|
56
|
-
response.status.
|
57
|
-
response.body.to_s.
|
57
|
+
response.status.must_equal 200
|
58
|
+
response.body.to_s.must_equal 'Hi Boss'
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
|
-
|
62
|
+
it 'return 400 Bad Request if different auth scheme used' do
|
62
63
|
request 'HTTP_AUTHORIZATION' => 'Digest params' do |response|
|
63
|
-
response.
|
64
|
-
response.status.
|
65
|
-
response.
|
64
|
+
response.must_be :client_error?
|
65
|
+
response.status.must_equal 400
|
66
|
+
response.wont_include 'WWW-Authenticate'
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
+
it 'return 400 Bad Request for a malformed authorization header' do
|
70
71
|
request 'HTTP_AUTHORIZATION' => '' do |response|
|
71
|
-
response.
|
72
|
-
response.status.
|
73
|
-
response.
|
72
|
+
response.must_be :client_error?
|
73
|
+
response.status.must_equal 400
|
74
|
+
response.wont_include 'WWW-Authenticate'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'return 401 Bad Request for a nil authorization header' do
|
79
|
+
request 'HTTP_AUTHORIZATION' => nil do |response|
|
80
|
+
response.must_be :client_error?
|
81
|
+
response.status.must_equal 401
|
74
82
|
end
|
75
83
|
end
|
76
84
|
|
77
85
|
it 'takes realm as optional constructor arg' do
|
78
86
|
app = Rack::Auth::Basic.new(unprotected_app, realm) { true }
|
79
|
-
realm.
|
87
|
+
realm.must_equal app.realm
|
80
88
|
end
|
81
89
|
end
|
data/test/spec_auth_digest.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'minitest/autorun'
|
1
2
|
require 'rack/auth/digest/md5'
|
2
3
|
require 'rack/lint'
|
3
4
|
require 'rack/mock'
|
@@ -100,160 +101,160 @@ describe Rack::Auth::Digest::MD5 do
|
|
100
101
|
end
|
101
102
|
|
102
103
|
def assert_digest_auth_challenge(response)
|
103
|
-
response.
|
104
|
-
response.status.
|
105
|
-
response.
|
106
|
-
response.headers['WWW-Authenticate'].
|
107
|
-
response.body.
|
104
|
+
response.must_be :client_error?
|
105
|
+
response.status.must_equal 401
|
106
|
+
response.must_include 'WWW-Authenticate'
|
107
|
+
response.headers['WWW-Authenticate'].must_match(/^Digest /)
|
108
|
+
response.body.must_be :empty?
|
108
109
|
end
|
109
110
|
|
110
111
|
def assert_bad_request(response)
|
111
|
-
response.
|
112
|
-
response.status.
|
113
|
-
response.
|
112
|
+
response.must_be :client_error?
|
113
|
+
response.status.must_equal 400
|
114
|
+
response.wont_include 'WWW-Authenticate'
|
114
115
|
end
|
115
116
|
|
116
|
-
|
117
|
+
it 'challenge when no credentials are specified' do
|
117
118
|
request 'GET', '/' do |response|
|
118
119
|
assert_digest_auth_challenge response
|
119
120
|
end
|
120
121
|
end
|
121
122
|
|
122
|
-
|
123
|
+
it 'return application output if correct credentials given' do
|
123
124
|
request_with_digest_auth 'GET', '/', 'Alice', 'correct-password' do |response|
|
124
|
-
response.status.
|
125
|
-
response.body.to_s.
|
125
|
+
response.status.must_equal 200
|
126
|
+
response.body.to_s.must_equal 'Hi Alice'
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
129
|
-
|
130
|
+
it 'return application output if correct credentials given (hashed passwords)' do
|
130
131
|
@request = Rack::MockRequest.new(protected_app_with_hashed_passwords)
|
131
132
|
|
132
133
|
request_with_digest_auth 'GET', '/', 'Alice', 'correct-password' do |response|
|
133
|
-
response.status.
|
134
|
-
response.body.to_s.
|
134
|
+
response.status.must_equal 200
|
135
|
+
response.body.to_s.must_equal 'Hi Alice'
|
135
136
|
end
|
136
137
|
end
|
137
138
|
|
138
|
-
|
139
|
+
it 'rechallenge if incorrect username given' do
|
139
140
|
request_with_digest_auth 'GET', '/', 'Bob', 'correct-password' do |response|
|
140
141
|
assert_digest_auth_challenge response
|
141
142
|
end
|
142
143
|
end
|
143
144
|
|
144
|
-
|
145
|
+
it 'rechallenge if incorrect password given' do
|
145
146
|
request_with_digest_auth 'GET', '/', 'Alice', 'wrong-password' do |response|
|
146
147
|
assert_digest_auth_challenge response
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
150
|
-
|
151
|
+
it 'rechallenge if incorrect user and blank password given' do
|
151
152
|
request_with_digest_auth 'GET', '/', 'Bob', '' do |response|
|
152
153
|
assert_digest_auth_challenge response
|
153
154
|
end
|
154
155
|
end
|
155
156
|
|
156
|
-
|
157
|
+
it 'not rechallenge if nonce is not stale' do
|
157
158
|
begin
|
158
159
|
Rack::Auth::Digest::Nonce.time_limit = 10
|
159
160
|
|
160
161
|
request_with_digest_auth 'GET', '/', 'Alice', 'correct-password', :wait => 1 do |response|
|
161
|
-
response.status.
|
162
|
-
response.body.to_s.
|
163
|
-
response.headers['WWW-Authenticate'].
|
162
|
+
response.status.must_equal 200
|
163
|
+
response.body.to_s.must_equal 'Hi Alice'
|
164
|
+
response.headers['WWW-Authenticate'].wont_match(/\bstale=true\b/)
|
164
165
|
end
|
165
166
|
ensure
|
166
167
|
Rack::Auth::Digest::Nonce.time_limit = nil
|
167
168
|
end
|
168
169
|
end
|
169
170
|
|
170
|
-
|
171
|
+
it 'rechallenge with stale parameter if nonce is stale' do
|
171
172
|
begin
|
172
173
|
Rack::Auth::Digest::Nonce.time_limit = 1
|
173
174
|
|
174
175
|
request_with_digest_auth 'GET', '/', 'Alice', 'correct-password', :wait => 2 do |response|
|
175
176
|
assert_digest_auth_challenge response
|
176
|
-
response.headers['WWW-Authenticate'].
|
177
|
+
response.headers['WWW-Authenticate'].must_match(/\bstale=true\b/)
|
177
178
|
end
|
178
179
|
ensure
|
179
180
|
Rack::Auth::Digest::Nonce.time_limit = nil
|
180
181
|
end
|
181
182
|
end
|
182
183
|
|
183
|
-
|
184
|
+
it 'return 400 Bad Request if incorrect qop given' do
|
184
185
|
request_with_digest_auth 'GET', '/', 'Alice', 'correct-password', 'qop' => 'auth-int' do |response|
|
185
186
|
assert_bad_request response
|
186
187
|
end
|
187
188
|
end
|
188
189
|
|
189
|
-
|
190
|
+
it 'return 400 Bad Request if incorrect uri given' do
|
190
191
|
request_with_digest_auth 'GET', '/', 'Alice', 'correct-password', 'uri' => '/foo' do |response|
|
191
192
|
assert_bad_request response
|
192
193
|
end
|
193
194
|
end
|
194
195
|
|
195
|
-
|
196
|
+
it 'return 400 Bad Request if different auth scheme used' do
|
196
197
|
request 'GET', '/', 'HTTP_AUTHORIZATION' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==' do |response|
|
197
198
|
assert_bad_request response
|
198
199
|
end
|
199
200
|
end
|
200
201
|
|
201
|
-
|
202
|
+
it 'not require credentials for unprotected path' do
|
202
203
|
@request = Rack::MockRequest.new(partially_protected_app)
|
203
204
|
request 'GET', '/' do |response|
|
204
|
-
response.
|
205
|
+
response.must_be :ok?
|
205
206
|
end
|
206
207
|
end
|
207
208
|
|
208
|
-
|
209
|
+
it 'challenge when no credentials are specified for protected path' do
|
209
210
|
@request = Rack::MockRequest.new(partially_protected_app)
|
210
211
|
request 'GET', '/protected' do |response|
|
211
212
|
assert_digest_auth_challenge response
|
212
213
|
end
|
213
214
|
end
|
214
215
|
|
215
|
-
|
216
|
+
it 'return application output if correct credentials given for protected path' do
|
216
217
|
@request = Rack::MockRequest.new(partially_protected_app)
|
217
218
|
request_with_digest_auth 'GET', '/protected', 'Alice', 'correct-password' do |response|
|
218
|
-
response.status.
|
219
|
-
response.body.to_s.
|
219
|
+
response.status.must_equal 200
|
220
|
+
response.body.to_s.must_equal 'Hi Alice'
|
220
221
|
end
|
221
222
|
end
|
222
223
|
|
223
|
-
|
224
|
+
it 'return application output when used with a query string and path as uri' do
|
224
225
|
@request = Rack::MockRequest.new(partially_protected_app)
|
225
226
|
request_with_digest_auth 'GET', '/protected?friend=Mike', 'Alice', 'correct-password' do |response|
|
226
|
-
response.status.
|
227
|
-
response.body.to_s.
|
227
|
+
response.status.must_equal 200
|
228
|
+
response.body.to_s.must_equal 'Hi Alice and Mike'
|
228
229
|
end
|
229
230
|
end
|
230
231
|
|
231
|
-
|
232
|
+
it 'return application output when used with a query string and fullpath as uri' do
|
232
233
|
@request = Rack::MockRequest.new(partially_protected_app)
|
233
234
|
qs_uri = '/protected?friend=Mike'
|
234
235
|
request_with_digest_auth 'GET', qs_uri, 'Alice', 'correct-password', 'uri' => qs_uri do |response|
|
235
|
-
response.status.
|
236
|
-
response.body.to_s.
|
236
|
+
response.status.must_equal 200
|
237
|
+
response.body.to_s.must_equal 'Hi Alice and Mike'
|
237
238
|
end
|
238
239
|
end
|
239
240
|
|
240
|
-
|
241
|
+
it 'return application output if correct credentials given for POST' do
|
241
242
|
request_with_digest_auth 'POST', '/', 'Alice', 'correct-password' do |response|
|
242
|
-
response.status.
|
243
|
-
response.body.to_s.
|
243
|
+
response.status.must_equal 200
|
244
|
+
response.body.to_s.must_equal 'Hi Alice'
|
244
245
|
end
|
245
246
|
end
|
246
247
|
|
247
|
-
|
248
|
+
it 'return application output if correct credentials given for PUT (using method override of POST)' do
|
248
249
|
@request = Rack::MockRequest.new(protected_app_with_method_override)
|
249
250
|
request_with_digest_auth 'POST', '/', 'Alice', 'correct-password', :input => "_method=put" do |response|
|
250
|
-
response.status.
|
251
|
-
response.body.to_s.
|
251
|
+
response.status.must_equal 200
|
252
|
+
response.body.to_s.must_equal 'Hi Alice'
|
252
253
|
end
|
253
254
|
end
|
254
255
|
|
255
256
|
it 'takes realm as optional constructor arg' do
|
256
257
|
app = Rack::Auth::Digest::MD5.new(unprotected_app, realm) { true }
|
257
|
-
realm.
|
258
|
+
realm.must_equal app.realm
|
258
259
|
end
|
259
260
|
end
|
data/test/spec_body_proxy.rb
CHANGED
@@ -1,85 +1,85 @@
|
|
1
|
+
require 'minitest/autorun'
|
1
2
|
require 'rack/body_proxy'
|
2
3
|
require 'stringio'
|
3
|
-
require 'ostruct'
|
4
4
|
|
5
5
|
describe Rack::BodyProxy do
|
6
|
-
|
6
|
+
it 'call each on the wrapped body' do
|
7
7
|
called = false
|
8
8
|
proxy = Rack::BodyProxy.new(['foo']) { }
|
9
9
|
proxy.each do |str|
|
10
10
|
called = true
|
11
|
-
str.
|
11
|
+
str.must_equal 'foo'
|
12
12
|
end
|
13
|
-
called.
|
13
|
+
called.must_equal true
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
it 'call close on the wrapped body' do
|
17
17
|
body = StringIO.new
|
18
18
|
proxy = Rack::BodyProxy.new(body) { }
|
19
19
|
proxy.close
|
20
|
-
body.
|
20
|
+
body.must_be :closed?
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
it 'only call close on the wrapped body if it responds to close' do
|
24
24
|
body = []
|
25
25
|
proxy = Rack::BodyProxy.new(body) { }
|
26
|
-
|
26
|
+
proxy.close.must_be_nil
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
it 'call the passed block on close' do
|
30
30
|
called = false
|
31
31
|
proxy = Rack::BodyProxy.new([]) { called = true }
|
32
|
-
called.
|
32
|
+
called.must_equal false
|
33
33
|
proxy.close
|
34
|
-
called.
|
34
|
+
called.must_equal true
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
it 'call the passed block on close even if there is an exception' do
|
38
38
|
object = Object.new
|
39
39
|
def object.close() raise "No!" end
|
40
40
|
called = false
|
41
41
|
|
42
42
|
begin
|
43
43
|
proxy = Rack::BodyProxy.new(object) { called = true }
|
44
|
-
called.
|
44
|
+
called.must_equal false
|
45
45
|
proxy.close
|
46
46
|
rescue RuntimeError => e
|
47
47
|
end
|
48
48
|
|
49
49
|
raise "Expected exception to have been raised" unless e
|
50
|
-
called.
|
50
|
+
called.must_equal true
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
it 'allow multiple arguments in respond_to?' do
|
54
54
|
body = []
|
55
55
|
proxy = Rack::BodyProxy.new(body) { }
|
56
|
-
|
56
|
+
proxy.respond_to?(:foo, false).must_equal false
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
|
-
body =
|
61
|
-
body.respond_to?(:to_ary).
|
59
|
+
it 'not respond to :to_ary' do
|
60
|
+
body = Object.new.tap { |o| def o.to_ary() end }
|
61
|
+
body.respond_to?(:to_ary).must_equal true
|
62
62
|
|
63
63
|
proxy = Rack::BodyProxy.new(body) { }
|
64
|
-
proxy.respond_to?(:to_ary).
|
65
|
-
proxy.respond_to?("to_ary").
|
64
|
+
proxy.respond_to?(:to_ary).must_equal false
|
65
|
+
proxy.respond_to?("to_ary").must_equal false
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
it 'not close more than one time' do
|
69
69
|
count = 0
|
70
70
|
proxy = Rack::BodyProxy.new([]) { count += 1; raise "Block invoked more than 1 time!" if count > 1 }
|
71
71
|
2.times { proxy.close }
|
72
|
-
count.
|
72
|
+
count.must_equal 1
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
it 'be closed when the callback is triggered' do
|
76
76
|
closed = false
|
77
77
|
proxy = Rack::BodyProxy.new([]) { closed = proxy.closed? }
|
78
78
|
proxy.close
|
79
|
-
closed.
|
79
|
+
closed.must_equal true
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
Rack::BodyProxy.method_defined?(:each).
|
82
|
+
it 'provide an #each method' do
|
83
|
+
Rack::BodyProxy.method_defined?(:each).must_equal true
|
84
84
|
end
|
85
85
|
end
|