2009-12-19 03:16:58 +01:00
|
|
|
require 'rack/directory'
|
|
|
|
require 'rack/mock'
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
describe Rack::Directory do
|
2009-12-26 21:00:18 +01:00
|
|
|
DOCROOT = File.expand_path(File.dirname(__FILE__)) unless defined? DOCROOT
|
2009-12-19 03:16:58 +01:00
|
|
|
FILE_CATCH = proc{|env| [200, {'Content-Type'=>'text/plain', "Content-Length" => "7"}, ['passed!']] }
|
|
|
|
app = Rack::Directory.new DOCROOT, FILE_CATCH
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "serve directory indices" do
|
2009-12-19 03:16:58 +01:00
|
|
|
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
|
|
|
get("/cgi/")
|
|
|
|
|
|
|
|
res.should.be.ok
|
|
|
|
res.should =~ /<html><head>/
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "pass to app if file found" do
|
2009-12-19 03:16:58 +01:00
|
|
|
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
|
|
|
get("/cgi/test")
|
|
|
|
|
|
|
|
res.should.be.ok
|
|
|
|
res.should =~ /passed!/
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "serve uri with URL encoded filenames" do
|
2009-12-19 03:16:58 +01:00
|
|
|
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
|
|
|
get("/%63%67%69/") # "/cgi/test"
|
|
|
|
|
|
|
|
res.should.be.ok
|
|
|
|
res.should =~ /<html><head>/
|
|
|
|
|
|
|
|
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
|
|
|
get("/cgi/%74%65%73%74") # "/cgi/test"
|
|
|
|
|
|
|
|
res.should.be.ok
|
|
|
|
res.should =~ /passed!/
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "not allow directory traversal" do
|
2009-12-19 03:16:58 +01:00
|
|
|
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
|
|
|
get("/cgi/../test")
|
|
|
|
|
|
|
|
res.should.be.forbidden
|
|
|
|
|
|
|
|
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
|
|
|
get("/cgi/%2E%2E/test")
|
|
|
|
|
|
|
|
res.should.be.forbidden
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "404 if it can't find the file" do
|
2009-12-19 03:16:58 +01:00
|
|
|
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
|
|
|
get("/cgi/blubb")
|
|
|
|
|
|
|
|
res.should.be.not_found
|
|
|
|
end
|
|
|
|
end
|