rack 1.0.1 → 2.2.21

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.
Files changed (147) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +829 -0
  3. data/CONTRIBUTING.md +136 -0
  4. data/{COPYING → MIT-LICENSE} +4 -2
  5. data/README.rdoc +355 -0
  6. data/Rakefile +64 -98
  7. data/SPEC.rdoc +292 -0
  8. data/bin/rackup +3 -174
  9. data/contrib/rack.png +0 -0
  10. data/contrib/rack.svg +150 -0
  11. data/contrib/rack_logo.svg +164 -111
  12. data/contrib/rdoc.css +412 -0
  13. data/example/lobster.ru +2 -0
  14. data/example/protectedlobster.rb +4 -2
  15. data/example/protectedlobster.ru +3 -1
  16. data/lib/rack/auth/abstract/handler.rb +7 -5
  17. data/lib/rack/auth/abstract/request.rb +12 -2
  18. data/lib/rack/auth/basic.rb +6 -4
  19. data/lib/rack/auth/digest/md5.rb +20 -13
  20. data/lib/rack/auth/digest/nonce.rb +6 -4
  21. data/lib/rack/auth/digest/params.rb +11 -12
  22. data/lib/rack/auth/digest/request.rb +15 -12
  23. data/lib/rack/body_proxy.rb +45 -0
  24. data/lib/rack/builder.rb +213 -19
  25. data/lib/rack/cascade.rb +50 -18
  26. data/lib/rack/chunked.rb +95 -27
  27. data/lib/rack/common_logger.rb +84 -0
  28. data/lib/rack/conditional_get.rb +83 -0
  29. data/lib/rack/config.rb +22 -0
  30. data/lib/rack/content_length.rb +19 -10
  31. data/lib/rack/content_type.rb +12 -5
  32. data/lib/rack/core_ext/regexp.rb +14 -0
  33. data/lib/rack/deflater.rb +90 -42
  34. data/lib/rack/directory.rb +118 -72
  35. data/lib/rack/etag.rb +77 -0
  36. data/lib/rack/events.rb +153 -0
  37. data/lib/rack/file.rb +4 -85
  38. data/lib/rack/files.rb +218 -0
  39. data/lib/rack/handler/cgi.rb +22 -24
  40. data/lib/rack/handler/fastcgi.rb +34 -24
  41. data/lib/rack/handler/lsws.rb +16 -15
  42. data/lib/rack/handler/scgi.rb +38 -29
  43. data/lib/rack/handler/thin.rb +23 -7
  44. data/lib/rack/handler/webrick.rb +95 -37
  45. data/lib/rack/handler.rb +49 -14
  46. data/lib/rack/head.rb +19 -13
  47. data/lib/rack/lint.rb +466 -217
  48. data/lib/rack/lobster.rb +19 -14
  49. data/lib/rack/lock.rb +24 -8
  50. data/lib/rack/logger.rb +20 -0
  51. data/lib/rack/media_type.rb +53 -0
  52. data/lib/rack/method_override.rb +52 -0
  53. data/lib/rack/mime.rb +652 -171
  54. data/lib/rack/mock.rb +203 -64
  55. data/lib/rack/multipart/generator.rb +97 -0
  56. data/lib/rack/multipart/parser.rb +440 -0
  57. data/lib/rack/multipart/uploaded_file.rb +41 -0
  58. data/lib/rack/multipart.rb +64 -0
  59. data/lib/rack/null_logger.rb +39 -0
  60. data/lib/rack/query_parser.rb +266 -0
  61. data/lib/rack/recursive.rb +18 -11
  62. data/lib/rack/reloader.rb +13 -5
  63. data/lib/rack/request.rb +607 -191
  64. data/lib/rack/response.rb +245 -110
  65. data/lib/rack/rewindable_input.rb +15 -21
  66. data/lib/rack/runtime.rb +34 -0
  67. data/lib/rack/sendfile.rb +192 -0
  68. data/lib/rack/server.rb +466 -0
  69. data/lib/rack/session/abstract/id.rb +449 -68
  70. data/lib/rack/session/cookie.rb +159 -47
  71. data/lib/rack/session/memcache.rb +4 -103
  72. data/lib/rack/session/pool.rb +39 -49
  73. data/lib/rack/show_exceptions.rb +390 -0
  74. data/lib/rack/{showstatus.rb → show_status.rb} +21 -14
  75. data/lib/rack/static.rb +164 -14
  76. data/lib/rack/tempfile_reaper.rb +22 -0
  77. data/lib/rack/urlmap.rb +60 -18
  78. data/lib/rack/utils.rb +508 -277
  79. data/lib/rack/version.rb +29 -0
  80. data/lib/rack.rb +85 -34
  81. data/rack.gemspec +43 -51
  82. metadata +119 -207
  83. data/KNOWN-ISSUES +0 -18
  84. data/RDOX +0 -428
  85. data/README +0 -364
  86. data/SPEC +0 -164
  87. data/lib/rack/adapter/camping.rb +0 -22
  88. data/lib/rack/auth/openid.rb +0 -480
  89. data/lib/rack/commonlogger.rb +0 -61
  90. data/lib/rack/conditionalget.rb +0 -47
  91. data/lib/rack/handler/evented_mongrel.rb +0 -8
  92. data/lib/rack/handler/mongrel.rb +0 -87
  93. data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
  94. data/lib/rack/methodoverride.rb +0 -27
  95. data/lib/rack/showexceptions.rb +0 -349
  96. data/test/cgi/lighttpd.conf +0 -20
  97. data/test/cgi/test +0 -9
  98. data/test/cgi/test.fcgi +0 -8
  99. data/test/cgi/test.ru +0 -7
  100. data/test/multipart/binary +0 -0
  101. data/test/multipart/empty +0 -10
  102. data/test/multipart/ie +0 -6
  103. data/test/multipart/nested +0 -10
  104. data/test/multipart/none +0 -9
  105. data/test/multipart/semicolon +0 -6
  106. data/test/multipart/text +0 -10
  107. data/test/spec_rack_auth_basic.rb +0 -73
  108. data/test/spec_rack_auth_digest.rb +0 -226
  109. data/test/spec_rack_auth_openid.rb +0 -84
  110. data/test/spec_rack_builder.rb +0 -84
  111. data/test/spec_rack_camping.rb +0 -51
  112. data/test/spec_rack_cascade.rb +0 -50
  113. data/test/spec_rack_cgi.rb +0 -89
  114. data/test/spec_rack_chunked.rb +0 -62
  115. data/test/spec_rack_commonlogger.rb +0 -32
  116. data/test/spec_rack_conditionalget.rb +0 -41
  117. data/test/spec_rack_content_length.rb +0 -43
  118. data/test/spec_rack_content_type.rb +0 -30
  119. data/test/spec_rack_deflater.rb +0 -127
  120. data/test/spec_rack_directory.rb +0 -61
  121. data/test/spec_rack_fastcgi.rb +0 -89
  122. data/test/spec_rack_file.rb +0 -75
  123. data/test/spec_rack_handler.rb +0 -43
  124. data/test/spec_rack_head.rb +0 -30
  125. data/test/spec_rack_lint.rb +0 -521
  126. data/test/spec_rack_lobster.rb +0 -45
  127. data/test/spec_rack_lock.rb +0 -38
  128. data/test/spec_rack_methodoverride.rb +0 -60
  129. data/test/spec_rack_mock.rb +0 -157
  130. data/test/spec_rack_mongrel.rb +0 -189
  131. data/test/spec_rack_recursive.rb +0 -77
  132. data/test/spec_rack_request.rb +0 -504
  133. data/test/spec_rack_response.rb +0 -218
  134. data/test/spec_rack_rewindable_input.rb +0 -118
  135. data/test/spec_rack_session_cookie.rb +0 -82
  136. data/test/spec_rack_session_memcache.rb +0 -240
  137. data/test/spec_rack_session_pool.rb +0 -172
  138. data/test/spec_rack_showexceptions.rb +0 -21
  139. data/test/spec_rack_showstatus.rb +0 -72
  140. data/test/spec_rack_static.rb +0 -37
  141. data/test/spec_rack_thin.rb +0 -91
  142. data/test/spec_rack_urlmap.rb +0 -185
  143. data/test/spec_rack_utils.rb +0 -387
  144. data/test/spec_rack_webrick.rb +0 -130
  145. data/test/testrequest.rb +0 -57
  146. data/test/unregistered_handler/rack/handler/unregistered.rb +0 -7
  147. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +0 -7
@@ -1,27 +0,0 @@
1
- module Rack
2
- class MethodOverride
3
- HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)
4
-
5
- METHOD_OVERRIDE_PARAM_KEY = "_method".freeze
6
- HTTP_METHOD_OVERRIDE_HEADER = "HTTP_X_HTTP_METHOD_OVERRIDE".freeze
7
-
8
- def initialize(app)
9
- @app = app
10
- end
11
-
12
- def call(env)
13
- if env["REQUEST_METHOD"] == "POST"
14
- req = Request.new(env)
15
- method = req.POST[METHOD_OVERRIDE_PARAM_KEY] ||
16
- env[HTTP_METHOD_OVERRIDE_HEADER]
17
- method = method.to_s.upcase
18
- if HTTP_METHODS.include?(method)
19
- env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
20
- env["REQUEST_METHOD"] = method
21
- end
22
- end
23
-
24
- @app.call(env)
25
- end
26
- end
27
- end
@@ -1,349 +0,0 @@
1
- require 'ostruct'
2
- require 'erb'
3
- require 'rack/request'
4
- require 'rack/utils'
5
-
6
- module Rack
7
- # Rack::ShowExceptions catches all exceptions raised from the app it
8
- # wraps. It shows a useful backtrace with the sourcefile and
9
- # clickable context, the whole Rack environment and the request
10
- # data.
11
- #
12
- # Be careful when you use this on public-facing sites as it could
13
- # reveal information helpful to attackers.
14
-
15
- class ShowExceptions
16
- CONTEXT = 7
17
-
18
- def initialize(app)
19
- @app = app
20
- @template = ERB.new(TEMPLATE)
21
- end
22
-
23
- def call(env)
24
- @app.call(env)
25
- rescue StandardError, LoadError, SyntaxError => e
26
- backtrace = pretty(env, e)
27
- [500,
28
- {"Content-Type" => "text/html",
29
- "Content-Length" => backtrace.join.size.to_s},
30
- backtrace]
31
- end
32
-
33
- def pretty(env, exception)
34
- req = Rack::Request.new(env)
35
- path = (req.script_name + req.path_info).squeeze("/")
36
-
37
- frames = exception.backtrace.map { |line|
38
- frame = OpenStruct.new
39
- if line =~ /(.*?):(\d+)(:in `(.*)')?/
40
- frame.filename = $1
41
- frame.lineno = $2.to_i
42
- frame.function = $4
43
-
44
- begin
45
- lineno = frame.lineno-1
46
- lines = ::File.readlines(frame.filename)
47
- frame.pre_context_lineno = [lineno-CONTEXT, 0].max
48
- frame.pre_context = lines[frame.pre_context_lineno...lineno]
49
- frame.context_line = lines[lineno].chomp
50
- frame.post_context_lineno = [lineno+CONTEXT, lines.size].min
51
- frame.post_context = lines[lineno+1..frame.post_context_lineno]
52
- rescue
53
- end
54
-
55
- frame
56
- else
57
- nil
58
- end
59
- }.compact
60
-
61
- env["rack.errors"].puts "#{exception.class}: #{exception.message}"
62
- env["rack.errors"].puts exception.backtrace.map { |l| "\t" + l }
63
- env["rack.errors"].flush
64
-
65
- [@template.result(binding)]
66
- end
67
-
68
- def h(obj) # :nodoc:
69
- case obj
70
- when String
71
- Utils.escape_html(obj)
72
- else
73
- Utils.escape_html(obj.inspect)
74
- end
75
- end
76
-
77
- # :stopdoc:
78
-
79
- # adapted from Django <djangoproject.com>
80
- # Copyright (c) 2005, the Lawrence Journal-World
81
- # Used under the modified BSD license:
82
- # http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
83
- TEMPLATE = <<'HTML'
84
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
85
- <html lang="en">
86
- <head>
87
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
88
- <meta name="robots" content="NONE,NOARCHIVE" />
89
- <title><%=h exception.class %> at <%=h path %></title>
90
- <style type="text/css">
91
- html * { padding:0; margin:0; }
92
- body * { padding:10px 20px; }
93
- body * * { padding:0; }
94
- body { font:small sans-serif; }
95
- body>div { border-bottom:1px solid #ddd; }
96
- h1 { font-weight:normal; }
97
- h2 { margin-bottom:.8em; }
98
- h2 span { font-size:80%; color:#666; font-weight:normal; }
99
- h3 { margin:1em 0 .5em 0; }
100
- h4 { margin:0 0 .5em 0; font-weight: normal; }
101
- table {
102
- border:1px solid #ccc; border-collapse: collapse; background:white; }
103
- tbody td, tbody th { vertical-align:top; padding:2px 3px; }
104
- thead th {
105
- padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
106
- font-weight:normal; font-size:11px; border:1px solid #ddd; }
107
- tbody th { text-align:right; color:#666; padding-right:.5em; }
108
- table.vars { margin:5px 0 2px 40px; }
109
- table.vars td, table.req td { font-family:monospace; }
110
- table td.code { width:100%;}
111
- table td.code div { overflow:hidden; }
112
- table.source th { color:#666; }
113
- table.source td {
114
- font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
115
- ul.traceback { list-style-type:none; }
116
- ul.traceback li.frame { margin-bottom:1em; }
117
- div.context { margin: 10px 0; }
118
- div.context ol {
119
- padding-left:30px; margin:0 10px; list-style-position: inside; }
120
- div.context ol li {
121
- font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
122
- div.context ol.context-line li { color:black; background-color:#ccc; }
123
- div.context ol.context-line li span { float: right; }
124
- div.commands { margin-left: 40px; }
125
- div.commands a { color:black; text-decoration:none; }
126
- #summary { background: #ffc; }
127
- #summary h2 { font-weight: normal; color: #666; }
128
- #summary ul#quicklinks { list-style-type: none; margin-bottom: 2em; }
129
- #summary ul#quicklinks li { float: left; padding: 0 1em; }
130
- #summary ul#quicklinks>li+li { border-left: 1px #666 solid; }
131
- #explanation { background:#eee; }
132
- #template, #template-not-exist { background:#f6f6f6; }
133
- #template-not-exist ul { margin: 0 0 0 20px; }
134
- #traceback { background:#eee; }
135
- #requestinfo { background:#f6f6f6; padding-left:120px; }
136
- #summary table { border:none; background:transparent; }
137
- #requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
138
- #requestinfo h3 { margin-bottom:-1em; }
139
- .error { background: #ffc; }
140
- .specific { color:#cc3300; font-weight:bold; }
141
- </style>
142
- <script type="text/javascript">
143
- //<!--
144
- function getElementsByClassName(oElm, strTagName, strClassName){
145
- // Written by Jonathan Snook, http://www.snook.ca/jon;
146
- // Add-ons by Robert Nyman, http://www.robertnyman.com
147
- var arrElements = (strTagName == "*" && document.all)? document.all :
148
- oElm.getElementsByTagName(strTagName);
149
- var arrReturnElements = new Array();
150
- strClassName = strClassName.replace(/\-/g, "\\-");
151
- var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$$)");
152
- var oElement;
153
- for(var i=0; i<arrElements.length; i++){
154
- oElement = arrElements[i];
155
- if(oRegExp.test(oElement.className)){
156
- arrReturnElements.push(oElement);
157
- }
158
- }
159
- return (arrReturnElements)
160
- }
161
- function hideAll(elems) {
162
- for (var e = 0; e < elems.length; e++) {
163
- elems[e].style.display = 'none';
164
- }
165
- }
166
- window.onload = function() {
167
- hideAll(getElementsByClassName(document, 'table', 'vars'));
168
- hideAll(getElementsByClassName(document, 'ol', 'pre-context'));
169
- hideAll(getElementsByClassName(document, 'ol', 'post-context'));
170
- }
171
- function toggle() {
172
- for (var i = 0; i < arguments.length; i++) {
173
- var e = document.getElementById(arguments[i]);
174
- if (e) {
175
- e.style.display = e.style.display == 'none' ? 'block' : 'none';
176
- }
177
- }
178
- return false;
179
- }
180
- function varToggle(link, id) {
181
- toggle('v' + id);
182
- var s = link.getElementsByTagName('span')[0];
183
- var uarr = String.fromCharCode(0x25b6);
184
- var darr = String.fromCharCode(0x25bc);
185
- s.innerHTML = s.innerHTML == uarr ? darr : uarr;
186
- return false;
187
- }
188
- //-->
189
- </script>
190
- </head>
191
- <body>
192
-
193
- <div id="summary">
194
- <h1><%=h exception.class %> at <%=h path %></h1>
195
- <h2><%=h exception.message %></h2>
196
- <table><tr>
197
- <th>Ruby</th>
198
- <td><code><%=h frames.first.filename %></code>: in <code><%=h frames.first.function %></code>, line <%=h frames.first.lineno %></td>
199
- </tr><tr>
200
- <th>Web</th>
201
- <td><code><%=h req.request_method %> <%=h(req.host + path)%></code></td>
202
- </tr></table>
203
-
204
- <h3>Jump to:</h3>
205
- <ul id="quicklinks">
206
- <li><a href="#get-info">GET</a></li>
207
- <li><a href="#post-info">POST</a></li>
208
- <li><a href="#cookie-info">Cookies</a></li>
209
- <li><a href="#env-info">ENV</a></li>
210
- </ul>
211
- </div>
212
-
213
- <div id="traceback">
214
- <h2>Traceback <span>(innermost first)</span></h2>
215
- <ul class="traceback">
216
- <% frames.each { |frame| %>
217
- <li class="frame">
218
- <code><%=h frame.filename %></code>: in <code><%=h frame.function %></code>
219
-
220
- <% if frame.context_line %>
221
- <div class="context" id="c<%=h frame.object_id %>">
222
- <% if frame.pre_context %>
223
- <ol start="<%=h frame.pre_context_lineno+1 %>" class="pre-context" id="pre<%=h frame.object_id %>">
224
- <% frame.pre_context.each { |line| %>
225
- <li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h line %></li>
226
- <% } %>
227
- </ol>
228
- <% end %>
229
-
230
- <ol start="<%=h frame.lineno %>" class="context-line">
231
- <li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h frame.context_line %><span>...</span></li></ol>
232
-
233
- <% if frame.post_context %>
234
- <ol start='<%=h frame.lineno+1 %>' class="post-context" id="post<%=h frame.object_id %>">
235
- <% frame.post_context.each { |line| %>
236
- <li onclick="toggle('pre<%=h frame.object_id %>', 'post<%=h frame.object_id %>')"><%=h line %></li>
237
- <% } %>
238
- </ol>
239
- <% end %>
240
- </div>
241
- <% end %>
242
- </li>
243
- <% } %>
244
- </ul>
245
- </div>
246
-
247
- <div id="requestinfo">
248
- <h2>Request information</h2>
249
-
250
- <h3 id="get-info">GET</h3>
251
- <% unless req.GET.empty? %>
252
- <table class="req">
253
- <thead>
254
- <tr>
255
- <th>Variable</th>
256
- <th>Value</th>
257
- </tr>
258
- </thead>
259
- <tbody>
260
- <% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
261
- <tr>
262
- <td><%=h key %></td>
263
- <td class="code"><div><%=h val.inspect %></div></td>
264
- </tr>
265
- <% } %>
266
- </tbody>
267
- </table>
268
- <% else %>
269
- <p>No GET data.</p>
270
- <% end %>
271
-
272
- <h3 id="post-info">POST</h3>
273
- <% unless req.POST.empty? %>
274
- <table class="req">
275
- <thead>
276
- <tr>
277
- <th>Variable</th>
278
- <th>Value</th>
279
- </tr>
280
- </thead>
281
- <tbody>
282
- <% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
283
- <tr>
284
- <td><%=h key %></td>
285
- <td class="code"><div><%=h val.inspect %></div></td>
286
- </tr>
287
- <% } %>
288
- </tbody>
289
- </table>
290
- <% else %>
291
- <p>No POST data.</p>
292
- <% end %>
293
-
294
-
295
- <h3 id="cookie-info">COOKIES</h3>
296
- <% unless req.cookies.empty? %>
297
- <table class="req">
298
- <thead>
299
- <tr>
300
- <th>Variable</th>
301
- <th>Value</th>
302
- </tr>
303
- </thead>
304
- <tbody>
305
- <% req.cookies.each { |key, val| %>
306
- <tr>
307
- <td><%=h key %></td>
308
- <td class="code"><div><%=h val.inspect %></div></td>
309
- </tr>
310
- <% } %>
311
- </tbody>
312
- </table>
313
- <% else %>
314
- <p>No cookie data.</p>
315
- <% end %>
316
-
317
- <h3 id="env-info">Rack ENV</h3>
318
- <table class="req">
319
- <thead>
320
- <tr>
321
- <th>Variable</th>
322
- <th>Value</th>
323
- </tr>
324
- </thead>
325
- <tbody>
326
- <% env.sort_by { |k, v| k.to_s }.each { |key, val| %>
327
- <tr>
328
- <td><%=h key %></td>
329
- <td class="code"><div><%=h val %></div></td>
330
- </tr>
331
- <% } %>
332
- </tbody>
333
- </table>
334
-
335
- </div>
336
-
337
- <div id="explanation">
338
- <p>
339
- You're seeing this error because you use <code>Rack::ShowExceptions</code>.
340
- </p>
341
- </div>
342
-
343
- </body>
344
- </html>
345
- HTML
346
-
347
- # :startdoc:
348
- end
349
- end
@@ -1,20 +0,0 @@
1
- server.modules = ("mod_fastcgi", "mod_cgi")
2
- server.document-root = "."
3
- server.errorlog = "lighttpd.errors"
4
- server.port = 9203
5
-
6
- server.event-handler = "select"
7
-
8
- cgi.assign = ("/test" => "",
9
- # ".ru" => ""
10
- )
11
-
12
- fastcgi.server = ("test.fcgi" => ("localhost" =>
13
- ("min-procs" => 1,
14
- "socket" => "/tmp/rack-test-fcgi",
15
- "bin-path" => "test.fcgi")),
16
- "test.ru" => ("localhost" =>
17
- ("min-procs" => 1,
18
- "socket" => "/tmp/rack-test-ru-fcgi",
19
- "bin-path" => "test.ru")),
20
- )
data/test/cgi/test DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- ruby -*-
3
-
4
- $: << File.join(File.dirname(__FILE__), "..", "..", "lib")
5
-
6
- require 'rack'
7
- require '../testrequest'
8
-
9
- Rack::Handler::CGI.run(Rack::Lint.new(TestRequest.new))
data/test/cgi/test.fcgi DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- ruby -*-
3
-
4
- $:.unshift '../../lib'
5
- require 'rack'
6
- require '../testrequest'
7
-
8
- Rack::Handler::FastCGI.run(Rack::Lint.new(TestRequest.new))
data/test/cgi/test.ru DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ../../bin/rackup
2
- #\ -E deployment -I ../../lib
3
- # -*- ruby -*-
4
-
5
- require '../testrequest'
6
-
7
- run TestRequest.new
Binary file
data/test/multipart/empty DELETED
@@ -1,10 +0,0 @@
1
- --AaB03x
2
- Content-Disposition: form-data; name="submit-name"
3
-
4
- Larry
5
- --AaB03x
6
- Content-Disposition: form-data; name="files"; filename="file1.txt"
7
- Content-Type: text/plain
8
-
9
-
10
- --AaB03x--
data/test/multipart/ie DELETED
@@ -1,6 +0,0 @@
1
- --AaB03x
2
- Content-Disposition: form-data; name="files"; filename="C:\Documents and Settings\Administrator\Desktop\file1.txt"
3
- Content-Type: text/plain
4
-
5
- contents
6
- --AaB03x--
@@ -1,10 +0,0 @@
1
- --AaB03x
2
- Content-Disposition: form-data; name="foo[submit-name]"
3
-
4
- Larry
5
- --AaB03x
6
- Content-Disposition: form-data; name="foo[files]"; filename="file1.txt"
7
- Content-Type: text/plain
8
-
9
- contents
10
- --AaB03x--
data/test/multipart/none DELETED
@@ -1,9 +0,0 @@
1
- --AaB03x
2
- Content-Disposition: form-data; name="submit-name"
3
-
4
- Larry
5
- --AaB03x
6
- Content-Disposition: form-data; name="files"; filename=""
7
-
8
-
9
- --AaB03x--
@@ -1,6 +0,0 @@
1
- --AaB03x
2
- Content-Disposition: form-data; name="files"; filename="fi;le1.txt"
3
- Content-Type: text/plain
4
-
5
- contents
6
- --AaB03x--
data/test/multipart/text DELETED
@@ -1,10 +0,0 @@
1
- --AaB03x
2
- Content-Disposition: form-data; name="submit-name"
3
-
4
- Larry
5
- --AaB03x
6
- Content-Disposition: form-data; name="files"; filename="file1.txt"
7
- Content-Type: text/plain
8
-
9
- contents
10
- --AaB03x--
@@ -1,73 +0,0 @@
1
- require 'test/spec'
2
-
3
- require 'rack/auth/basic'
4
- require 'rack/mock'
5
-
6
- context 'Rack::Auth::Basic' do
7
-
8
- def realm
9
- 'WallysWorld'
10
- end
11
-
12
- def unprotected_app
13
- lambda { |env| [ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ] }
14
- end
15
-
16
- def protected_app
17
- app = Rack::Auth::Basic.new(unprotected_app) { |username, password| 'Boss' == username }
18
- app.realm = realm
19
- app
20
- end
21
-
22
- setup do
23
- @request = Rack::MockRequest.new(protected_app)
24
- end
25
-
26
- def request_with_basic_auth(username, password, &block)
27
- request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack("m*"), &block
28
- end
29
-
30
- def request(headers = {})
31
- yield @request.get('/', headers)
32
- end
33
-
34
- def assert_basic_auth_challenge(response)
35
- response.should.be.a.client_error
36
- response.status.should.equal 401
37
- response.should.include 'WWW-Authenticate'
38
- response.headers['WWW-Authenticate'].should =~ /Basic realm="#{Regexp.escape(realm)}"/
39
- response.body.should.be.empty
40
- end
41
-
42
- specify 'should challenge correctly when no credentials are specified' do
43
- request do |response|
44
- assert_basic_auth_challenge response
45
- end
46
- end
47
-
48
- specify 'should rechallenge if incorrect credentials are specified' do
49
- request_with_basic_auth 'joe', 'password' do |response|
50
- assert_basic_auth_challenge response
51
- end
52
- end
53
-
54
- specify 'should return application output if correct credentials are specified' do
55
- request_with_basic_auth 'Boss', 'password' do |response|
56
- response.status.should.equal 200
57
- response.body.to_s.should.equal 'Hi Boss'
58
- end
59
- end
60
-
61
- specify 'should return 400 Bad Request if different auth scheme used' do
62
- request 'HTTP_AUTHORIZATION' => 'Digest params' do |response|
63
- response.should.be.a.client_error
64
- response.status.should.equal 400
65
- response.should.not.include 'WWW-Authenticate'
66
- end
67
- end
68
-
69
- specify 'realm as optional constructor arg' do
70
- app = Rack::Auth::Basic.new(unprotected_app, realm) { true }
71
- assert_equal realm, app.realm
72
- end
73
- end