Sha256: 52a8fd56453e653ea17af86dde08abebbac1a1830ec2df7306bb679720401f1d

Contents?: true

Size: 1.33 KB

Versions: 30

Compression:

Stored size: 1.33 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
  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

30 entries across 30 versions & 6 rubygems

Version Path
3mix-castronaut-0.5.0.2 vendor/rack/test/spec_rack_directory.rb
kastner-rack-0.3.171 test/spec_rack_directory.rb
kastner-rack-0.3.186 test/spec_rack_directory.rb
masover-castronaut-0.4.4.4 vendor/rack/test/spec_rack_directory.rb
masover-castronaut-0.4.4.5 vendor/rack/test/spec_rack_directory.rb
masover-castronaut-0.5.0.1 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.2.0 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.2.5 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.3.0 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.3.5 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.3.6 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.4.1 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.4.2 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.4.3 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.4.4 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.4.5 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.4.6 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.5.0 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.5.1 vendor/rack/test/spec_rack_directory.rb
relevance-castronaut-0.5.2 vendor/rack/test/spec_rack_directory.rb