Sha256: df26aa5a2c7b17ae6c09536c2245b4e8e7a48d90310dfd54444c173fc6a58e5f

Contents?: true

Size: 1.18 KB

Versions: 27

Compression:

Stored size: 1.18 KB

Contents

require 'test/spec'

require 'rack/file'
require 'rack/lint'

require 'rack/mock'

context "Rack::File" do
  DOCROOT = File.expand_path(File.dirname(__FILE__))

  specify "serves files" do
    res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
      get("/cgi/test")

    res.should.be.ok
    res.should =~ /ruby/
  end

  specify "sets Last-Modified header" do
    res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
      get("/cgi/test")

    path = File.join(DOCROOT, "/cgi/test")

    res.should.be.ok
    res["Last-Modified"].should.equal File.mtime(path).httpdate
  end

  specify "serves files with URL encoded filenames" do
    res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
      get("/cgi/%74%65%73%74") # "/cgi/test"

    res.should.be.ok
    res.should =~ /ruby/
  end

  specify "does not allow directory traversal" do
    res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
      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(Rack::File.new(DOCROOT))).
      get("/cgi/blubb")

    res.should.be.not_found
  end
end

Version data entries

27 entries across 27 versions & 5 rubygems

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