diff options
author | Eric Wong <e@80x24.org> | 2013-11-02 10:54:17 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-11-02 22:03:54 +0000 |
commit | 3192ec1b4054bcc228dfb88e57d5e1c828682a7b (patch) | |
tree | e7f7ac214f4a6e4ccdc1f1c109f49b555921a881 /test/test_extras_exec_cgi.rb | |
parent | f78020396ac822c31f7f0b1a593bd3f58362a27a (diff) | |
download | yahns-3192ec1b4054bcc228dfb88e57d5e1c828682a7b.tar.gz |
These applications are what I'll be using to run on yahns on my personal server. Including them here will be helpful for me to find bugs. I've already found some, the following commits were directly the result of playing with these extras: * stream_file: only close FDs we opened ourselves * worker-less server should not waitpid indiscriminately * http: do not drop Content-Range from response headers
Diffstat (limited to 'test/test_extras_exec_cgi.rb')
-rw-r--r-- | test/test_extras_exec_cgi.rb | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/test/test_extras_exec_cgi.rb b/test/test_extras_exec_cgi.rb new file mode 100644 index 0000000..403925b --- /dev/null +++ b/test/test_extras_exec_cgi.rb @@ -0,0 +1,81 @@ +# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +require_relative 'server_helper' + +class TestExtrasExecCGI < Testcase + ENV["N"].to_i > 1 and parallelize_me! + include ServerHelper + alias setup server_helper_setup + alias teardown server_helper_teardown + + def test_exec_cgi + err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1] + runme = "#{Dir.pwd}/test/test_extras_exec_cgi.sh" + assert File.executable?(runme), "run test in project root" + pid = mkserver(cfg) do + require './extras/exec_cgi' + cfg.instance_eval do + app(:rack, ExecCgi.new(runme)) do + listen "#{host}:#{port}" + end + stderr_path err.path + end + end + + Timeout.timeout(30) do # we can chunk + c = get_tcp_client(host, port) + c.write "GET / HTTP/1.1\r\nConnection: close\r\n" \ + "Host: example.com\r\n\r\n" + head, body = c.read.split(/\r\n\r\n/, 2) + assert_match %r{^Transfer-Encoding: chunked\b}, head + assert_equal "5\r\nHIHI\n\r\n0\r\n\r\n", body + c.close + cerr = tmpfile(%w(curl .err)) + assert_equal "HIHI\n", `curl -sSfv 2>#{cerr.path} http://#{host}:#{port}/` + assert_match %r{\bTransfer-Encoding: chunked\b}, cerr.read + cerr.close! + end + + Timeout.timeout(30) do # do not chunk on clients who can't handle chunking + c = get_tcp_client(host, port) + c.write "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n" + head, body = c.read.split(/\r\n\r\n/) + assert_equal "HIHI\n", body + refute_match %r{^Transfer-Encoding: chunked\b}, head + c.close + end + + Timeout.timeout(30) do # sure env is sane + c = get_tcp_client(host, port) + c.write "GET /env\r\n\r\n" + head, body = c.read.split(/\r\n\r\n/) + assert_nil body + assert_match %r{^REQUEST_METHOD=GET$}, head + assert_match %r{^PATH_INFO=/env$}, head + assert_match %r{^QUERY_STRING=$}, head + c.close + end + + Timeout.timeout(30) do # known length should not chunk + c = get_tcp_client(host, port) + c.write "GET /known-length HTTP/1.1\r\nConnection: close\r\n" \ + "Host: example.com\r\n\r\n" + head, body = c.read.split(/\r\n\r\n/, 2) + refute_match %r{^Transfer-Encoding: chunked\b}, head + assert_match %r{^Content-Length: 5\b}, head + assert_equal "HIHI\n", body + c.close + end + + Timeout.timeout(30) do # 404 + c = get_tcp_client(host, port) + c.write "GET /not-found HTTP/1.0\r\n\r\n" + head, body = c.read.split(/\r\n\r\n/) + assert_match %r{\AHTTP/1\.1 404 Not Found}, head + assert_nil body + c.close + end + ensure + quit_wait(pid) + end +end |