kjvarga-rack 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/COPYING +18 -0
  2. data/KNOWN-ISSUES.rdoc +18 -0
  3. data/Manifest +117 -0
  4. data/README.rdoc +357 -0
  5. data/Rakefile +164 -0
  6. data/bin/rackup +176 -0
  7. data/contrib/rack_logo.svg +111 -0
  8. data/lib/rack.rb +90 -0
  9. data/lib/rack/adapter/camping.rb +22 -0
  10. data/lib/rack/auth/abstract/handler.rb +37 -0
  11. data/lib/rack/auth/abstract/request.rb +37 -0
  12. data/lib/rack/auth/basic.rb +58 -0
  13. data/lib/rack/auth/digest/md5.rb +124 -0
  14. data/lib/rack/auth/digest/nonce.rb +51 -0
  15. data/lib/rack/auth/digest/params.rb +55 -0
  16. data/lib/rack/auth/digest/request.rb +40 -0
  17. data/lib/rack/auth/openid.rb +487 -0
  18. data/lib/rack/builder.rb +63 -0
  19. data/lib/rack/cascade.rb +41 -0
  20. data/lib/rack/chunked.rb +49 -0
  21. data/lib/rack/commonlogger.rb +52 -0
  22. data/lib/rack/conditionalget.rb +47 -0
  23. data/lib/rack/content_length.rb +29 -0
  24. data/lib/rack/content_type.rb +23 -0
  25. data/lib/rack/deflater.rb +96 -0
  26. data/lib/rack/directory.rb +153 -0
  27. data/lib/rack/file.rb +88 -0
  28. data/lib/rack/handler.rb +69 -0
  29. data/lib/rack/handler/cgi.rb +61 -0
  30. data/lib/rack/handler/evented_mongrel.rb +8 -0
  31. data/lib/rack/handler/fastcgi.rb +88 -0
  32. data/lib/rack/handler/lsws.rb +60 -0
  33. data/lib/rack/handler/mongrel.rb +87 -0
  34. data/lib/rack/handler/scgi.rb +62 -0
  35. data/lib/rack/handler/swiftiplied_mongrel.rb +8 -0
  36. data/lib/rack/handler/thin.rb +18 -0
  37. data/lib/rack/handler/webrick.rb +71 -0
  38. data/lib/rack/head.rb +19 -0
  39. data/lib/rack/lint.rb +546 -0
  40. data/lib/rack/lobster.rb +65 -0
  41. data/lib/rack/lock.rb +16 -0
  42. data/lib/rack/methodoverride.rb +27 -0
  43. data/lib/rack/mime.rb +205 -0
  44. data/lib/rack/mock.rb +187 -0
  45. data/lib/rack/recursive.rb +57 -0
  46. data/lib/rack/reloader.rb +109 -0
  47. data/lib/rack/request.rb +248 -0
  48. data/lib/rack/response.rb +183 -0
  49. data/lib/rack/rewindable_input.rb +100 -0
  50. data/lib/rack/session/abstract/id.rb +142 -0
  51. data/lib/rack/session/cookie.rb +91 -0
  52. data/lib/rack/session/memcache.rb +109 -0
  53. data/lib/rack/session/pool.rb +100 -0
  54. data/lib/rack/showexceptions.rb +349 -0
  55. data/lib/rack/showstatus.rb +106 -0
  56. data/lib/rack/static.rb +38 -0
  57. data/lib/rack/urlmap.rb +55 -0
  58. data/lib/rack/utils.rb +528 -0
  59. data/rack.gemspec +140 -0
  60. data/test/cgi/lighttpd.conf +20 -0
  61. data/test/cgi/test +9 -0
  62. data/test/cgi/test.fcgi +8 -0
  63. data/test/cgi/test.ru +7 -0
  64. data/test/multipart/binary +0 -0
  65. data/test/multipart/empty +10 -0
  66. data/test/multipart/file1.txt +1 -0
  67. data/test/multipart/ie +6 -0
  68. data/test/multipart/nested +10 -0
  69. data/test/multipart/none +9 -0
  70. data/test/multipart/text +10 -0
  71. data/test/spec_rack_auth_basic.rb +73 -0
  72. data/test/spec_rack_auth_digest.rb +226 -0
  73. data/test/spec_rack_auth_openid.rb +84 -0
  74. data/test/spec_rack_builder.rb +84 -0
  75. data/test/spec_rack_camping.rb +51 -0
  76. data/test/spec_rack_cascade.rb +48 -0
  77. data/test/spec_rack_cgi.rb +89 -0
  78. data/test/spec_rack_chunked.rb +62 -0
  79. data/test/spec_rack_commonlogger.rb +61 -0
  80. data/test/spec_rack_conditionalget.rb +41 -0
  81. data/test/spec_rack_content_length.rb +43 -0
  82. data/test/spec_rack_content_type.rb +30 -0
  83. data/test/spec_rack_deflater.rb +127 -0
  84. data/test/spec_rack_directory.rb +61 -0
  85. data/test/spec_rack_fastcgi.rb +89 -0
  86. data/test/spec_rack_file.rb +75 -0
  87. data/test/spec_rack_handler.rb +43 -0
  88. data/test/spec_rack_head.rb +30 -0
  89. data/test/spec_rack_lint.rb +521 -0
  90. data/test/spec_rack_lobster.rb +45 -0
  91. data/test/spec_rack_lock.rb +38 -0
  92. data/test/spec_rack_methodoverride.rb +60 -0
  93. data/test/spec_rack_mock.rb +243 -0
  94. data/test/spec_rack_mongrel.rb +189 -0
  95. data/test/spec_rack_recursive.rb +77 -0
  96. data/test/spec_rack_request.rb +504 -0
  97. data/test/spec_rack_response.rb +218 -0
  98. data/test/spec_rack_rewindable_input.rb +118 -0
  99. data/test/spec_rack_session_cookie.rb +82 -0
  100. data/test/spec_rack_session_memcache.rb +250 -0
  101. data/test/spec_rack_session_pool.rb +172 -0
  102. data/test/spec_rack_showexceptions.rb +21 -0
  103. data/test/spec_rack_showstatus.rb +72 -0
  104. data/test/spec_rack_static.rb +37 -0
  105. data/test/spec_rack_thin.rb +91 -0
  106. data/test/spec_rack_urlmap.rb +185 -0
  107. data/test/spec_rack_utils.rb +467 -0
  108. data/test/spec_rack_webrick.rb +130 -0
  109. data/test/testrequest.rb +57 -0
  110. data/test/unregistered_handler/rack/handler/unregistered.rb +7 -0
  111. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +7 -0
  112. metadata +175 -0
@@ -0,0 +1,41 @@
1
+ require 'test/spec'
2
+ require 'time'
3
+
4
+ require 'rack/mock'
5
+ require 'rack/conditionalget'
6
+
7
+ context "Rack::ConditionalGet" do
8
+ specify "should set a 304 status and truncate body when If-Modified-Since hits" do
9
+ timestamp = Time.now.httpdate
10
+ app = Rack::ConditionalGet.new(lambda { |env|
11
+ [200, {'Last-Modified'=>timestamp}, ['TEST']] })
12
+
13
+ response = Rack::MockRequest.new(app).
14
+ get("/", 'HTTP_IF_MODIFIED_SINCE' => timestamp)
15
+
16
+ response.status.should.equal 304
17
+ response.body.should.be.empty
18
+ end
19
+
20
+ specify "should set a 304 status and truncate body when If-None-Match hits" do
21
+ app = Rack::ConditionalGet.new(lambda { |env|
22
+ [200, {'Etag'=>'1234'}, ['TEST']] })
23
+
24
+ response = Rack::MockRequest.new(app).
25
+ get("/", 'HTTP_IF_NONE_MATCH' => '1234')
26
+
27
+ response.status.should.equal 304
28
+ response.body.should.be.empty
29
+ end
30
+
31
+ specify "should not affect non-GET/HEAD requests" do
32
+ app = Rack::ConditionalGet.new(lambda { |env|
33
+ [200, {'Etag'=>'1234'}, ['TEST']] })
34
+
35
+ response = Rack::MockRequest.new(app).
36
+ post("/", 'HTTP_IF_NONE_MATCH' => '1234')
37
+
38
+ response.status.should.equal 200
39
+ response.body.should.equal 'TEST'
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ require 'rack/mock'
2
+ require 'rack/content_length'
3
+
4
+ context "Rack::ContentLength" do
5
+ specify "sets Content-Length on String bodies if none is set" do
6
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
7
+ response = Rack::ContentLength.new(app).call({})
8
+ response[1]['Content-Length'].should.equal '13'
9
+ end
10
+
11
+ specify "sets Content-Length on Array bodies if none is set" do
12
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
13
+ response = Rack::ContentLength.new(app).call({})
14
+ response[1]['Content-Length'].should.equal '13'
15
+ end
16
+
17
+ specify "does not set Content-Length on variable length bodies" do
18
+ body = lambda { "Hello World!" }
19
+ def body.each ; yield call ; end
20
+
21
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
22
+ response = Rack::ContentLength.new(app).call({})
23
+ response[1]['Content-Length'].should.be.nil
24
+ end
25
+
26
+ specify "does not change Content-Length if it is already set" do
27
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '1'}, "Hello, World!"] }
28
+ response = Rack::ContentLength.new(app).call({})
29
+ response[1]['Content-Length'].should.equal '1'
30
+ end
31
+
32
+ specify "does not set Content-Length on 304 responses" do
33
+ app = lambda { |env| [304, {'Content-Type' => 'text/plain'}, []] }
34
+ response = Rack::ContentLength.new(app).call({})
35
+ response[1]['Content-Length'].should.equal nil
36
+ end
37
+
38
+ specify "does not set Content-Length when Transfer-Encoding is chunked" do
39
+ app = lambda { |env| [200, {'Transfer-Encoding' => 'chunked'}, []] }
40
+ response = Rack::ContentLength.new(app).call({})
41
+ response[1]['Content-Length'].should.equal nil
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ require 'rack/mock'
2
+ require 'rack/content_type'
3
+
4
+ context "Rack::ContentType" do
5
+ specify "sets Content-Type to default text/html if none is set" do
6
+ app = lambda { |env| [200, {}, "Hello, World!"] }
7
+ status, headers, body = Rack::ContentType.new(app).call({})
8
+ headers['Content-Type'].should.equal 'text/html'
9
+ end
10
+
11
+ specify "sets Content-Type to chosen default if none is set" do
12
+ app = lambda { |env| [200, {}, "Hello, World!"] }
13
+ status, headers, body =
14
+ Rack::ContentType.new(app, 'application/octet-stream').call({})
15
+ headers['Content-Type'].should.equal 'application/octet-stream'
16
+ end
17
+
18
+ specify "does not change Content-Type if it is already set" do
19
+ app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] }
20
+ status, headers, body = Rack::ContentType.new(app).call({})
21
+ headers['Content-Type'].should.equal 'foo/bar'
22
+ end
23
+
24
+ specify "case insensitive detection of Content-Type" do
25
+ app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] }
26
+ status, headers, body = Rack::ContentType.new(app).call({})
27
+ headers.to_a.select { |k,v| k.downcase == "content-type" }.
28
+ should.equal [["CONTENT-Type","foo/bar"]]
29
+ end
30
+ end
@@ -0,0 +1,127 @@
1
+ require 'test/spec'
2
+
3
+ require 'rack/mock'
4
+ require 'rack/deflater'
5
+ require 'stringio'
6
+ require 'time' # for Time#httpdate
7
+
8
+ context "Rack::Deflater" do
9
+ def build_response(status, body, accept_encoding, headers = {})
10
+ body = [body] if body.respond_to? :to_str
11
+ app = lambda { |env| [status, {}, body] }
12
+ request = Rack::MockRequest.env_for("", headers.merge("HTTP_ACCEPT_ENCODING" => accept_encoding))
13
+ response = Rack::Deflater.new(app).call(request)
14
+
15
+ return response
16
+ end
17
+
18
+ specify "should be able to deflate bodies that respond to each" do
19
+ body = Object.new
20
+ class << body; def each; yield("foo"); yield("bar"); end; end
21
+
22
+ response = build_response(200, body, "deflate")
23
+
24
+ response[0].should.equal(200)
25
+ response[1].should.equal({
26
+ "Content-Encoding" => "deflate",
27
+ "Vary" => "Accept-Encoding"
28
+ })
29
+ buf = ''
30
+ response[2].each { |part| buf << part }
31
+ buf.should.equal("K\313\317OJ,\002\000")
32
+ end
33
+
34
+ # TODO: This is really just a special case of the above...
35
+ specify "should be able to deflate String bodies" do
36
+ response = build_response(200, "Hello world!", "deflate")
37
+
38
+ response[0].should.equal(200)
39
+ response[1].should.equal({
40
+ "Content-Encoding" => "deflate",
41
+ "Vary" => "Accept-Encoding"
42
+ })
43
+ buf = ''
44
+ response[2].each { |part| buf << part }
45
+ buf.should.equal("\363H\315\311\311W(\317/\312IQ\004\000")
46
+ end
47
+
48
+ specify "should be able to gzip bodies that respond to each" do
49
+ body = Object.new
50
+ class << body; def each; yield("foo"); yield("bar"); end; end
51
+
52
+ response = build_response(200, body, "gzip")
53
+
54
+ response[0].should.equal(200)
55
+ response[1].should.equal({
56
+ "Content-Encoding" => "gzip",
57
+ "Vary" => "Accept-Encoding",
58
+ })
59
+
60
+ buf = ''
61
+ response[2].each { |part| buf << part }
62
+ io = StringIO.new(buf)
63
+ gz = Zlib::GzipReader.new(io)
64
+ gz.read.should.equal("foobar")
65
+ gz.close
66
+ end
67
+
68
+ specify "should be able to fallback to no deflation" do
69
+ response = build_response(200, "Hello world!", "superzip")
70
+
71
+ response[0].should.equal(200)
72
+ response[1].should.equal({ "Vary" => "Accept-Encoding" })
73
+ response[2].should.equal(["Hello world!"])
74
+ end
75
+
76
+ specify "should be able to skip when there is no response entity body" do
77
+ response = build_response(304, [], "gzip")
78
+
79
+ response[0].should.equal(304)
80
+ response[1].should.equal({})
81
+ response[2].should.equal([])
82
+ end
83
+
84
+ specify "should handle the lack of an acceptable encoding" do
85
+ response1 = build_response(200, "Hello world!", "identity;q=0", "PATH_INFO" => "/")
86
+ response1[0].should.equal(406)
87
+ response1[1].should.equal({"Content-Type" => "text/plain", "Content-Length" => "71"})
88
+ response1[2].should.equal(["An acceptable encoding for the requested resource / could not be found."])
89
+
90
+ response2 = build_response(200, "Hello world!", "identity;q=0", "SCRIPT_NAME" => "/foo", "PATH_INFO" => "/bar")
91
+ response2[0].should.equal(406)
92
+ response2[1].should.equal({"Content-Type" => "text/plain", "Content-Length" => "78"})
93
+ response2[2].should.equal(["An acceptable encoding for the requested resource /foo/bar could not be found."])
94
+ end
95
+
96
+ specify "should handle gzip response with Last-Modified header" do
97
+ last_modified = Time.now.httpdate
98
+
99
+ app = lambda { |env| [200, { "Last-Modified" => last_modified }, ["Hello World!"]] }
100
+ request = Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => "gzip")
101
+ response = Rack::Deflater.new(app).call(request)
102
+
103
+ response[0].should.equal(200)
104
+ response[1].should.equal({
105
+ "Content-Encoding" => "gzip",
106
+ "Vary" => "Accept-Encoding",
107
+ "Last-Modified" => last_modified
108
+ })
109
+
110
+ buf = ''
111
+ response[2].each { |part| buf << part }
112
+ io = StringIO.new(buf)
113
+ gz = Zlib::GzipReader.new(io)
114
+ gz.read.should.equal("Hello World!")
115
+ gz.close
116
+ end
117
+
118
+ specify "should do nothing when no-transform Cache-Control directive present" do
119
+ app = lambda { |env| [200, {'Cache-Control' => 'no-transform'}, ['Hello World!']] }
120
+ request = Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => "gzip")
121
+ response = Rack::Deflater.new(app).call(request)
122
+
123
+ response[0].should.equal(200)
124
+ response[1].should.not.include "Content-Encoding"
125
+ response[2].join.should.equal("Hello World!")
126
+ end
127
+ end
@@ -0,0 +1,61 @@
1
+ require 'test/spec'
2
+
3
+ require 'rack/directory'
4
+ require 'rack/lint'
5
+
6
+ require 'rack/mock'
7
+
8
+ context "Rack::Directory" do
9
+ DOCROOT = File.expand_path(File.dirname(__FILE__)) unless defined? DOCROOT
10
+ FILE_CATCH = proc{|env| [200, {'Content-Type'=>'text/plain', "Content-Length" => "7"}, ['passed!']] }
11
+ app = Rack::Directory.new DOCROOT, FILE_CATCH
12
+
13
+ specify "serves directory indices" do
14
+ res = Rack::MockRequest.new(Rack::Lint.new(app)).
15
+ get("/cgi/")
16
+
17
+ res.should.be.ok
18
+ res.should =~ /<html><head>/
19
+ end
20
+
21
+ specify "passes to app if file found" do
22
+ res = Rack::MockRequest.new(Rack::Lint.new(app)).
23
+ get("/cgi/test")
24
+
25
+ res.should.be.ok
26
+ res.should =~ /passed!/
27
+ end
28
+
29
+ specify "serves uri with URL encoded filenames" do
30
+ res = Rack::MockRequest.new(Rack::Lint.new(app)).
31
+ get("/%63%67%69/") # "/cgi/test"
32
+
33
+ res.should.be.ok
34
+ res.should =~ /<html><head>/
35
+
36
+ res = Rack::MockRequest.new(Rack::Lint.new(app)).
37
+ get("/cgi/%74%65%73%74") # "/cgi/test"
38
+
39
+ res.should.be.ok
40
+ res.should =~ /passed!/
41
+ end
42
+
43
+ specify "does not allow directory traversal" do
44
+ res = Rack::MockRequest.new(Rack::Lint.new(app)).
45
+ get("/cgi/../test")
46
+
47
+ res.should.be.forbidden
48
+
49
+ res = Rack::MockRequest.new(Rack::Lint.new(app)).
50
+ get("/cgi/%2E%2E/test")
51
+
52
+ res.should.be.forbidden
53
+ end
54
+
55
+ specify "404s if it can't find the file" do
56
+ res = Rack::MockRequest.new(Rack::Lint.new(app)).
57
+ get("/cgi/blubb")
58
+
59
+ res.should.be.not_found
60
+ end
61
+ end
@@ -0,0 +1,89 @@
1
+ require 'test/spec'
2
+ require 'testrequest'
3
+
4
+ context "Rack::Handler::FastCGI" do
5
+ include TestRequest::Helpers
6
+
7
+ setup do
8
+ @host = '0.0.0.0'
9
+ @port = 9203
10
+ end
11
+
12
+ # Keep this first.
13
+ specify "startup" do
14
+ $pid = fork {
15
+ Dir.chdir(File.join(File.dirname(__FILE__), "..", "test", "cgi"))
16
+ exec "lighttpd -D -f lighttpd.conf"
17
+ }
18
+ end
19
+
20
+ specify "should respond" do
21
+ sleep 1
22
+ lambda {
23
+ GET("/test.fcgi")
24
+ }.should.not.raise
25
+ end
26
+
27
+ specify "should be a lighttpd" do
28
+ GET("/test.fcgi")
29
+ status.should.be 200
30
+ response["SERVER_SOFTWARE"].should =~ /lighttpd/
31
+ response["HTTP_VERSION"].should.equal "HTTP/1.1"
32
+ response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
33
+ response["SERVER_PORT"].should.equal @port.to_s
34
+ response["SERVER_NAME"].should =~ @host
35
+ end
36
+
37
+ specify "should have rack headers" do
38
+ GET("/test.fcgi")
39
+ response["rack.version"].should.equal [1,0]
40
+ response["rack.multithread"].should.be false
41
+ response["rack.multiprocess"].should.be true
42
+ response["rack.run_once"].should.be false
43
+ end
44
+
45
+ specify "should have CGI headers on GET" do
46
+ GET("/test.fcgi")
47
+ response["REQUEST_METHOD"].should.equal "GET"
48
+ response["SCRIPT_NAME"].should.equal "/test.fcgi"
49
+ response["REQUEST_PATH"].should.equal "/"
50
+ response["PATH_INFO"].should.be.nil
51
+ response["QUERY_STRING"].should.equal ""
52
+ response["test.postdata"].should.equal ""
53
+
54
+ GET("/test.fcgi/foo?quux=1")
55
+ response["REQUEST_METHOD"].should.equal "GET"
56
+ response["SCRIPT_NAME"].should.equal "/test.fcgi"
57
+ response["REQUEST_PATH"].should.equal "/"
58
+ response["PATH_INFO"].should.equal "/foo"
59
+ response["QUERY_STRING"].should.equal "quux=1"
60
+ end
61
+
62
+ specify "should have CGI headers on POST" do
63
+ POST("/test.fcgi", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
64
+ status.should.equal 200
65
+ response["REQUEST_METHOD"].should.equal "POST"
66
+ response["SCRIPT_NAME"].should.equal "/test.fcgi"
67
+ response["REQUEST_PATH"].should.equal "/"
68
+ response["QUERY_STRING"].should.equal ""
69
+ response["HTTP_X_TEST_HEADER"].should.equal "42"
70
+ response["test.postdata"].should.equal "rack-form-data=23"
71
+ end
72
+
73
+ specify "should support HTTP auth" do
74
+ GET("/test.fcgi", {:user => "ruth", :passwd => "secret"})
75
+ response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
76
+ end
77
+
78
+ specify "should set status" do
79
+ GET("/test.fcgi?secret")
80
+ status.should.equal 403
81
+ response["rack.url_scheme"].should.equal "http"
82
+ end
83
+
84
+ # Keep this last.
85
+ specify "shutdown" do
86
+ Process.kill 15, $pid
87
+ Process.wait($pid).should.equal $pid
88
+ end
89
+ end
@@ -0,0 +1,75 @@
1
+ require 'test/spec'
2
+
3
+ require 'rack/file'
4
+ require 'rack/lint'
5
+
6
+ require 'rack/mock'
7
+
8
+ context "Rack::File" do
9
+ DOCROOT = File.expand_path(File.dirname(__FILE__)) unless defined? DOCROOT
10
+
11
+ specify "serves files" do
12
+ res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
13
+ get("/cgi/test")
14
+
15
+ res.should.be.ok
16
+ res.should =~ /ruby/
17
+ end
18
+
19
+ specify "sets Last-Modified header" do
20
+ res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
21
+ get("/cgi/test")
22
+
23
+ path = File.join(DOCROOT, "/cgi/test")
24
+
25
+ res.should.be.ok
26
+ res["Last-Modified"].should.equal File.mtime(path).httpdate
27
+ end
28
+
29
+ specify "serves files with URL encoded filenames" do
30
+ res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
31
+ get("/cgi/%74%65%73%74") # "/cgi/test"
32
+
33
+ res.should.be.ok
34
+ res.should =~ /ruby/
35
+ end
36
+
37
+ specify "does not allow directory traversal" do
38
+ res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
39
+ get("/cgi/../test")
40
+
41
+ res.should.be.forbidden
42
+ end
43
+
44
+ specify "does not allow directory traversal with encoded periods" do
45
+ res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
46
+ get("/%2E%2E/README")
47
+
48
+ res.should.be.forbidden
49
+ end
50
+
51
+ specify "404s if it can't find the file" do
52
+ res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
53
+ get("/cgi/blubb")
54
+
55
+ res.should.be.not_found
56
+ end
57
+
58
+ specify "detects SystemCallErrors" do
59
+ res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
60
+ get("/cgi")
61
+
62
+ res.should.be.not_found
63
+ end
64
+
65
+ specify "returns bodies that respond to #to_path" do
66
+ env = Rack::MockRequest.env_for("/cgi/test")
67
+ status, headers, body = Rack::File.new(DOCROOT).call(env)
68
+
69
+ path = File.join(DOCROOT, "/cgi/test")
70
+
71
+ status.should.equal 200
72
+ body.should.respond_to :to_path
73
+ body.to_path.should.equal path
74
+ end
75
+ end