Sha256: fea7a85195e2ef223d5a222e94db65e2f96cd28e27ec5776878a768d39f6c501

Contents?: true

Size: 1.44 KB

Versions: 13

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

13 entries across 13 versions & 4 rubygems

Version Path
timocratic-rack-1.0.0 test/spec_rack_directory.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
middleman-0.10.17 vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
middleman-0.10.16 vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
middleman-0.10.15 vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
rackjour-0.1.8 vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
middleman-0.10.14 vendor/gems/gems/rack-1.0.1/test/spec_rack_directory.rb
rack-1.0.1 test/spec_rack_directory.rb
rack-1.0.0 test/spec_rack_directory.rb