rack 0.2.0 → 0.3.0

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.

@@ -1,6 +1,7 @@
1
1
  require 'test/spec'
2
- require 'base64'
3
- require 'rack'
2
+
3
+ require 'rack/auth/basic'
4
+ require 'rack/mock'
4
5
 
5
6
  context 'Rack::Auth::Basic' do
6
7
 
@@ -23,7 +24,7 @@ context 'Rack::Auth::Basic' do
23
24
  end
24
25
 
25
26
  def request_with_basic_auth(username, password, &block)
26
- request 'HTTP_AUTHORIZATION' => 'Basic ' + Base64.encode64("#{username}:#{password}"), &block
27
+ request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack("m*"), &block
27
28
  end
28
29
 
29
30
  def request(headers = {})
@@ -1,5 +1,7 @@
1
1
  require 'test/spec'
2
- require 'rack'
2
+
3
+ require 'rack/auth/digest/md5'
4
+ require 'rack/mock'
3
5
 
4
6
  context 'Rack::Auth::Digest::MD5' do
5
7
 
@@ -164,4 +166,4 @@ context 'Rack::Auth::Digest::MD5' do
164
166
  end
165
167
  end
166
168
 
167
- end
169
+ end
@@ -0,0 +1,50 @@
1
+ require 'test/spec'
2
+
3
+ require 'rack/builder'
4
+ require 'rack/mock'
5
+
6
+ context "Rack::Builder" do
7
+ specify "chains apps by default" do
8
+ app = Rack::Builder.new do
9
+ use Rack::ShowExceptions
10
+ run lambda { |env| raise "bzzzt" }
11
+ end.to_app
12
+
13
+ Rack::MockRequest.new(app).get("/").should.be.server_error
14
+ Rack::MockRequest.new(app).get("/").should.be.server_error
15
+ Rack::MockRequest.new(app).get("/").should.be.server_error
16
+ end
17
+
18
+ specify "has implicit #to_app" do
19
+ app = Rack::Builder.new do
20
+ use Rack::ShowExceptions
21
+ run lambda { |env| raise "bzzzt" }
22
+ end
23
+
24
+ Rack::MockRequest.new(app).get("/").should.be.server_error
25
+ Rack::MockRequest.new(app).get("/").should.be.server_error
26
+ Rack::MockRequest.new(app).get("/").should.be.server_error
27
+ end
28
+
29
+ specify "supports blocks on use" do
30
+ app = Rack::Builder.new do
31
+ use Rack::ShowExceptions
32
+ use Rack::Auth::Basic do |username, password|
33
+ 'secret' == password
34
+ end
35
+
36
+ run lambda { |env| [200, {}, 'Hi Boss'] }
37
+ end
38
+
39
+ response = Rack::MockRequest.new(app).get("/")
40
+ response.should.be.client_error
41
+ response.status.should.equal 401
42
+
43
+ # with auth...
44
+ response = Rack::MockRequest.new(app).get("/",
45
+ 'HTTP_AUTHORIZATION' => 'Basic ' + ["joe:secret"].pack("m*"))
46
+ response.status.should.equal 200
47
+ response.body.to_s.should.equal 'Hi Boss'
48
+ end
49
+
50
+ end
@@ -1,14 +1,6 @@
1
1
  require 'test/spec'
2
2
  require 'testrequest'
3
3
 
4
- pid = fork {
5
- exec "cd #{File.join(File.dirname(__FILE__), 'cgi')} && lighttpd -D -f lighttpd.conf"
6
- }
7
-
8
- at_exit {
9
- Process.kill 15, pid
10
- }
11
-
12
4
  context "Rack::Handler::CGI" do
13
5
  include TestRequest::Helpers
14
6
 
@@ -17,6 +9,14 @@ context "Rack::Handler::CGI" do
17
9
  @port = 9203
18
10
  end
19
11
 
12
+ # Keep this first.
13
+ specify "startup" do
14
+ $pid = fork {
15
+ Dir.chdir File.join(File.dirname(__FILE__), 'cgi')
16
+ exec "lighttpd -D -f lighttpd.conf"
17
+ }
18
+ end
19
+
20
20
  specify "should respond" do
21
21
  lambda {
22
22
  GET("/test")
@@ -79,4 +79,10 @@ context "Rack::Handler::CGI" do
79
79
  status.should.equal 403
80
80
  response["rack.url_scheme"].should.equal "http"
81
81
  end
82
+
83
+ # Keep this last.
84
+ specify "shutdown" do
85
+ Process.kill 15, $pid
86
+ Process.wait($pid).should.equal $pid
87
+ end
82
88
  end
@@ -1,14 +1,6 @@
1
1
  require 'test/spec'
2
2
  require 'testrequest'
3
3
 
4
- pid = fork {
5
- exec "cd #{File.join(File.dirname(__FILE__), 'cgi')} && lighttpd -D -f lighttpd.conf"
6
- }
7
-
8
- at_exit {
9
- Process.kill 15, pid
10
- }
11
-
12
4
  context "Rack::Handler::FastCGI" do
13
5
  include TestRequest::Helpers
14
6
 
@@ -17,6 +9,14 @@ context "Rack::Handler::FastCGI" do
17
9
  @port = 9203
18
10
  end
19
11
 
12
+ # Keep this first.
13
+ specify "startup" do
14
+ $pid = fork {
15
+ Dir.chdir File.join(File.dirname(__FILE__), 'cgi')
16
+ exec "lighttpd -D -f lighttpd.conf"
17
+ }
18
+ end
19
+
20
20
  specify "should respond" do
21
21
  lambda {
22
22
  GET("/test.fcgi")
@@ -79,4 +79,10 @@ context "Rack::Handler::FastCGI" do
79
79
  status.should.equal 403
80
80
  response["rack.url_scheme"].should.equal "http"
81
81
  end
82
+
83
+ # Keep this last.
84
+ specify "shutdown" do
85
+ Process.kill 15, $pid
86
+ Process.wait($pid).should.equal $pid
87
+ end
82
88
  end
@@ -15,6 +15,14 @@ context "Rack::File" do
15
15
  res.should.be.ok
16
16
  res.should =~ /ruby/
17
17
  end
18
+
19
+ specify "serves files with URL encoded filenames" do
20
+ res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
21
+ get("/cgi/%74%65%73%74") # "/cgi/test"
22
+
23
+ res.should.be.ok
24
+ res.should =~ /ruby/
25
+ end
18
26
 
19
27
  specify "does not allow directory traversal" do
20
28
  res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
@@ -206,14 +206,14 @@ context "Rack::Lint" do
206
206
 
207
207
  lambda {
208
208
  Rack::Lint.new(lambda { |env|
209
- [201, {"Content-Type" => "text/plain"}, ""]
209
+ [204, {"Content-Type" => "text/plain"}, ""]
210
210
  }).call(env({}))
211
211
  }.should.raise(Rack::Lint::LintError).
212
212
  message.should.match(/Content-Type header found/)
213
213
 
214
214
  lambda {
215
215
  Rack::Lint.new(lambda { |env|
216
- [201, {"Content-type" => "text/plain"}, ""]
216
+ [204, {"Content-type" => "text/plain"}, ""]
217
217
  }).call(env({}))
218
218
  }.should.raise(Rack::Lint::LintError).
219
219
  message.should.match(/Content-Type header found/)
@@ -244,7 +244,7 @@ context "Rack::Lint" do
244
244
  [201, {"Content-type" => "text/plain"}, ""]
245
245
  }).call(env({}))
246
246
  }.should.raise(Rack::Lint::LintError).
247
- message.should.match(/read called with too many arguments/)
247
+ message.should.match(/read called with non-integer argument/)
248
248
 
249
249
  weirdio = Object.new
250
250
  class << weirdio
@@ -129,6 +129,12 @@ context "Rack::Request" do
129
129
  req.cookies.should.equal({})
130
130
  end
131
131
 
132
+ specify "parses cookies according to RFC 2109" do
133
+ req = Rack::Request.new \
134
+ Rack::MockRequest.env_for('', 'HTTP_COOKIE' => 'foo=bar;foo=car')
135
+ req.cookies.should.equal 'foo' => 'bar'
136
+ end
137
+
132
138
  specify "provides setters" do
133
139
  req = Rack::Request.new(e=Rack::MockRequest.env_for(""))
134
140
  req.script_name.should.equal ""
@@ -276,4 +282,30 @@ EOF
276
282
 
277
283
  lambda { req.POST }.should.raise(EOFError)
278
284
  end
285
+
286
+ specify "does conform to the Rack spec" do
287
+ app = lambda { |env|
288
+ content = Rack::Request.new(env).POST["file"].inspect
289
+ [200, {"Content-Type" => "text/html"}, content]
290
+ }
291
+
292
+ input = <<EOF
293
+ --AaB03x\r
294
+ content-disposition: form-data; name="reply"\r
295
+ \r
296
+ yes\r
297
+ --AaB03x\r
298
+ content-disposition: form-data; name="fileupload"; filename="dj.jpg"\r
299
+ Content-Type: image/jpeg\r
300
+ Content-Transfer-Encoding: base64\r
301
+ \r
302
+ /9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg\r
303
+ --AaB03x--\r
304
+ EOF
305
+ res = Rack::MockRequest.new(Rack::Lint.new(app)).get "/",
306
+ "CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
307
+ "CONTENT_LENGTH" => input.size.to_s, "rack.input" => StringIO.new(input)
308
+
309
+ res.should.be.ok
310
+ end
279
311
  end
@@ -54,13 +54,21 @@ context "Rack::Response" do
54
54
  response["Set-Cookie"].should.equal ["foo=bar", "foo2=bar2", "foo3=bar3"]
55
55
  end
56
56
 
57
+ specify "formats the Cookie expiration date accordingly to RFC 2109" do
58
+ response = Rack::Response.new
59
+
60
+ response.set_cookie "foo", {:value => "bar", :expires => Time.now+10}
61
+ response["Set-Cookie"].should.match(
62
+ /expires=..., \d\d-...-\d\d\d\d \d\d:\d\d:\d\d .../)
63
+ end
64
+
57
65
  specify "can delete cookies" do
58
66
  response = Rack::Response.new
59
67
  response.set_cookie "foo", "bar"
60
68
  response.set_cookie "foo2", "bar2"
61
69
  response.delete_cookie "foo"
62
70
  response["Set-Cookie"].should.equal ["foo2=bar2",
63
- "foo=; expires=Thu, 01 Jan 1970 00:00:00 GMT"]
71
+ "foo=; expires=Thu, 01-Jan-1970 00:00:00 GMT"]
64
72
  end
65
73
 
66
74
  specify "has a useful constructor" do
@@ -96,7 +104,7 @@ context "Rack::Response" do
96
104
  end
97
105
 
98
106
  specify "doesn't return invalid responses" do
99
- r = Rack::Response.new(["foo", "bar"], 201)
107
+ r = Rack::Response.new(["foo", "bar"], 204)
100
108
  status, header, body = r.finish
101
109
  str = ""; body.each { |part| str << part }
102
110
  str.should.be.empty
@@ -0,0 +1,37 @@
1
+ require 'test/spec'
2
+
3
+ require 'rack/session/pool'
4
+ require 'rack/mock'
5
+ require 'rack/response'
6
+
7
+ context "Rack::Session::Pool" do
8
+ incrementor = lambda { |env|
9
+ env["rack.session"]["counter"] ||= 0
10
+ env["rack.session"]["counter"] += 1
11
+ Rack::Response.new(env["rack.session"].inspect).to_a
12
+ }
13
+
14
+ specify "creates a new cookie" do
15
+ pool = Rack::Session::Pool.new(incrementor)
16
+ res = Rack::MockRequest.new(pool).get("/")
17
+ res["Set-Cookie"].should.match("rack.session=")
18
+ res.body.should.equal '{"counter"=>1}'
19
+ end
20
+
21
+ specify "loads from a cookie" do
22
+ pool = Rack::Session::Pool.new(incrementor)
23
+ res = Rack::MockRequest.new(pool).get("/")
24
+ cookie = res["Set-Cookie"]
25
+ res = Rack::MockRequest.new(pool).get("/", "HTTP_COOKIE" => cookie)
26
+ res.body.should.equal '{"counter"=>2}'
27
+ res = Rack::MockRequest.new(pool).get("/", "HTTP_COOKIE" => cookie)
28
+ res.body.should.equal '{"counter"=>3}'
29
+ end
30
+
31
+ specify "survives broken cookies" do
32
+ pool = Rack::Session::Pool.new(incrementor)
33
+ res = Rack::MockRequest.new(pool).
34
+ get("/", "HTTP_COOKIE" => "rack.session=blarghfasel")
35
+ res.body.should.equal '{"counter"=>1}'
36
+ end
37
+ end
@@ -11,17 +11,17 @@ context "Rack::URLMap" do
11
11
  "X-Position" => "/foo",
12
12
  "X-PathInfo" => env["PATH_INFO"],
13
13
  }, [""]]},
14
-
14
+
15
15
  "/bar" => lambda { |env|
16
16
  [200,
17
17
  { "Content-Type" => "text/plain",
18
18
  "X-Position" => "/bar",
19
19
  "X-PathInfo" => env["PATH_INFO"],
20
20
  }, [""]]}
21
-
21
+
22
22
  )
23
23
 
24
-
24
+
25
25
  Rack::MockRequest.new(map).get("/").should.be.not_found
26
26
 
27
27
  res = Rack::MockRequest.new(map).get("/foo")
@@ -96,18 +96,24 @@ context "Rack::URLMap" do
96
96
 
97
97
  specify "should be nestable" do
98
98
  map = Rack::URLMap.new("/foo" =>
99
- Rack::URLMap.new("/bar" => lambda { |env|
100
- [200,
101
- { "Content-Type" => "text/plain",
102
- "X-Position" => "/foo/bar",
103
- "X-PathInfo" => env["PATH_INFO"],
104
- }, [""]]}
105
- )
106
- )
99
+ Rack::URLMap.new("/bar" =>
100
+ Rack::URLMap.new("/quux" => lambda { |env|
101
+ [200,
102
+ { "Content-Type" => "text/plain",
103
+ "X-Position" => "/foo/bar/quux",
104
+ "X-PathInfo" => env["PATH_INFO"],
105
+ "X-ScriptName" => env["SCRIPT_NAME"],
106
+ }, [""]]}
107
+ )))
107
108
 
108
109
  res = Rack::MockRequest.new(map).get("/foo/bar")
110
+ res.should.be.not_found
111
+
112
+ res = Rack::MockRequest.new(map).get("/foo/bar/quux")
109
113
  res.should.be.ok
110
- res["X-Position"].should.equal "/foo/bar"
114
+ res["X-Position"].should.equal "/foo/bar/quux"
115
+ res["X-PathInfo"].should.equal "/"
116
+ res["X-ScriptName"].should.equal "/foo/bar/quux"
111
117
  end
112
118
 
113
119
  specify "should route root apps correctly" do
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0.8
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rack
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2007-05-16 00:00:00 +02:00
6
+ version: 0.3.0
7
+ date: 2008-02-26 00:00:00 +01:00
8
8
  summary: a modular Ruby webserver interface
9
9
  require_paths:
10
10
  - lib
@@ -35,6 +35,7 @@ files:
35
35
  - COPYING
36
36
  - example/lobster.ru
37
37
  - example/protectedlobster.rb
38
+ - example/protectedlobster.ru
38
39
  - KNOWN-ISSUES
39
40
  - lib/rack/adapter/camping.rb
40
41
  - lib/rack/auth/abstract/handler.rb
@@ -44,13 +45,16 @@ files:
44
45
  - lib/rack/auth/digest/nonce.rb
45
46
  - lib/rack/auth/digest/params.rb
46
47
  - lib/rack/auth/digest/request.rb
48
+ - lib/rack/auth/openid.rb
47
49
  - lib/rack/builder.rb
48
50
  - lib/rack/cascade.rb
49
51
  - lib/rack/commonlogger.rb
50
52
  - lib/rack/file.rb
51
53
  - lib/rack/handler/cgi.rb
52
54
  - lib/rack/handler/fastcgi.rb
55
+ - lib/rack/handler/lsws.rb
53
56
  - lib/rack/handler/mongrel.rb
57
+ - lib/rack/handler/scgi.rb
54
58
  - lib/rack/handler/webrick.rb
55
59
  - lib/rack/lint.rb
56
60
  - lib/rack/lobster.rb
@@ -60,6 +64,7 @@ files:
60
64
  - lib/rack/request.rb
61
65
  - lib/rack/response.rb
62
66
  - lib/rack/session/cookie.rb
67
+ - lib/rack/session/pool.rb
63
68
  - lib/rack/showexceptions.rb
64
69
  - lib/rack/showstatus.rb
65
70
  - lib/rack/static.rb
@@ -74,6 +79,7 @@ files:
74
79
  - test/cgi/test.ru
75
80
  - test/spec_rack_auth_basic.rb
76
81
  - test/spec_rack_auth_digest.rb
82
+ - test/spec_rack_builder.rb
77
83
  - test/spec_rack_camping.rb
78
84
  - test/spec_rack_cascade.rb
79
85
  - test/spec_rack_cgi.rb
@@ -88,6 +94,7 @@ files:
88
94
  - test/spec_rack_request.rb
89
95
  - test/spec_rack_response.rb
90
96
  - test/spec_rack_session_cookie.rb
97
+ - test/spec_rack_session_pool.rb
91
98
  - test/spec_rack_showexceptions.rb
92
99
  - test/spec_rack_showstatus.rb
93
100
  - test/spec_rack_static.rb
@@ -100,6 +107,7 @@ files:
100
107
  test_files:
101
108
  - test/spec_rack_auth_basic.rb
102
109
  - test/spec_rack_auth_digest.rb
110
+ - test/spec_rack_builder.rb
103
111
  - test/spec_rack_camping.rb
104
112
  - test/spec_rack_cascade.rb
105
113
  - test/spec_rack_cgi.rb
@@ -114,6 +122,7 @@ test_files:
114
122
  - test/spec_rack_request.rb
115
123
  - test/spec_rack_response.rb
116
124
  - test/spec_rack_session_cookie.rb
125
+ - test/spec_rack_session_pool.rb
117
126
  - test/spec_rack_showexceptions.rb
118
127
  - test/spec_rack_showstatus.rb
119
128
  - test/spec_rack_static.rb