Sha256: c8ed6a8066936b58baa655f7d02b9591de1f55c8a714ccd001c917df6c1ebb86

Contents?: true

Size: 1.46 KB

Versions: 22

Compression:

Stored size: 1.46 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__)) unless defined? DOCROOT
  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

22 entries across 21 versions & 10 rubygems

Version Path
kjvarga-rack-1.0.0 test/spec_rack_directory.rb
qoobaa-rack-1.0.0.1 test/spec_rack_directory.rb
qoobaa-rack-1.0.2 test/spec_rack_directory.rb
rack-1.1.6 test/spec_rack_directory.rb
rack-1.1.5 test/spec_rack_directory.rb
rack-1.1.4 test/spec_rack_directory.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rack-1.1.3/test/spec_rack_directory.rb
rack-1.1.3 test/spec_rack_directory.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/rack-1.1.2/test/spec_rack_directory.rb
rack-1.1.2 test/spec_rack_directory.rb
rack-1.1.1 test/spec_rack_directory.rb
rack-1.1.1.pre test/spec_rack_directory.rb
eac-rack-1.1.1 test/spec_rack_directory.rb
akamai_bookmarklet-0.1.2 vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_directory.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_directory.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/rack-1.1.0/test/spec_rack_directory.rb
akamai_bookmarklet-0.1.1 vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_directory.rb
akamai_bookmarklet-0.1.0 vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_directory.rb
rack-1.1.0 test/spec_rack_directory.rb
rango-0.0.6 vendor/rack/test/spec_rack_directory.rb