Sha256: 9cb674b7709ceddef282efabdcdd2e1fab2f2cf1f28c6ad7b55f3358b15c6272

Contents?: true

Size: 1.44 KB

Versions: 7

Compression:

Stored size: 1.44 KB

Contents

require 'test/spec'

require 'rack/directory'
require 'rack/lint'

require 'rack/mock'

context "Rack::Directory" do
  DOCROOT = File.expand_path(File.dirname(__FILE__))
  FILE_CATCH = proc{|env| [200, {'Content-Type'=>'text/plain', "Content-Length" => "7"}, 'passed!'] }
  app = Rack::Directory.new DOCROOT, FILE_CATCH

  specify "serves directory indices" do
    res = Rack::MockRequest.new(Rack::Lint.new(app)).
      get("/cgi/")

    res.should.be.ok
    res.should =~ /<html><head>/
  end

  specify "passes to app if file found" do
    res = Rack::MockRequest.new(Rack::Lint.new(app)).
      get("/cgi/test")

    res.should.be.ok
    res.should =~ /passed!/
  end

  specify "serves uri with URL encoded filenames" do
    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

  specify "does not allow directory traversal" do
    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

  specify "404s if it can't find the file" do
    res = Rack::MockRequest.new(Rack::Lint.new(app)).
      get("/cgi/blubb")

    res.should.be.not_found
  end
end

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
p8-castronaut-0.6.1.1 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.6.0 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.6.1 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.7.4 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.7.5 vendor/rack/test/spec_rack_directory.rb
nbudin-castronaut-0.7.5 vendor/rack/test/spec_rack_directory.rb
rack-0.9.1 test/spec_rack_directory.rb