yahns.git  about / heads / tags
sleepy, multi-threaded, non-blocking application server for Ruby
blob fe753d56cb31c3db47e2d7660e11d6d9fc1dff03 1702 bytes (raw)
$ git show maint:test/test_extras_autoindex.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
# Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
# frozen_string_literal: true
require_relative 'server_helper'
require 'zlib'
require 'time'

class TestExtrasAutoindex < Testcase
  ENV["N"].to_i > 1 and parallelize_me!
  include ServerHelper

  def setup
    @tmpdir = yahns_mktmpdir
    server_helper_setup
    skip 'Ruby 2.x required' unless ''.respond_to?(:b)
  end

  def teardown
    server_helper_teardown
    FileUtils.rm_rf @tmpdir
  end

  def test_autoindex
    err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
    tmpdir = @tmpdir
    pid = mkserver(cfg) do
      $LOAD_PATH.unshift "#{Dir.pwd}/extras"
      require 'try_gzip_static'
      require 'autoindex'
      cfg.instance_eval do
        app(:rack, Autoindex.new(TryGzipStatic.new(tmpdir))) do
          listen "#{host}:#{port}"
        end
        stderr_path err.path
      end
    end

    Net::HTTP.start(host, port) do |http|
      res = http.request(Net::HTTP::Get.new("/"))
      assert_equal 200, res.code.to_i
      File.open("#@tmpdir/foo", "w").close
      res = http.request(Net::HTTP::Get.new("/"))
      assert_equal 200, res.code.to_i
      assert_match %r{foo}, res.body
      Dir.mkdir "#@tmpdir/bar"

      res = http.request(Net::HTTP::Get.new("/"))
      assert_equal 200, res.code.to_i
      refute_match %r{\.\./}, res.body, "top level should not link to parent"
      assert_match %r{foo}, res.body

      res = http.request(Net::HTTP::Get.new("/bar/"))
      assert_equal 200, res.code.to_i
      assert_match %r{\.\./}, res.body, "link to parent present"
    end
  ensure
    quit_wait pid
  end
end

git clone git://yhbt.net/yahns.git
git clone https://yhbt.net/yahns.git