From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/test/cgi/test_cgi_cookie.rb | 110 +++++++++ jni/ruby/test/cgi/test_cgi_core.rb | 312 +++++++++++++++++++++++++ jni/ruby/test/cgi/test_cgi_header.rb | 181 +++++++++++++++ jni/ruby/test/cgi/test_cgi_modruby.rb | 146 ++++++++++++ jni/ruby/test/cgi/test_cgi_multipart.rb | 380 +++++++++++++++++++++++++++++++ jni/ruby/test/cgi/test_cgi_session.rb | 172 ++++++++++++++ jni/ruby/test/cgi/test_cgi_tag_helper.rb | 353 ++++++++++++++++++++++++++++ jni/ruby/test/cgi/test_cgi_util.rb | 104 +++++++++ jni/ruby/test/cgi/testdata/file1.html | 10 + jni/ruby/test/cgi/testdata/large.png | Bin 0 -> 156414 bytes jni/ruby/test/cgi/testdata/small.png | Bin 0 -> 82 bytes 11 files changed, 1768 insertions(+) create mode 100644 jni/ruby/test/cgi/test_cgi_cookie.rb create mode 100644 jni/ruby/test/cgi/test_cgi_core.rb create mode 100644 jni/ruby/test/cgi/test_cgi_header.rb create mode 100644 jni/ruby/test/cgi/test_cgi_modruby.rb create mode 100644 jni/ruby/test/cgi/test_cgi_multipart.rb create mode 100644 jni/ruby/test/cgi/test_cgi_session.rb create mode 100644 jni/ruby/test/cgi/test_cgi_tag_helper.rb create mode 100644 jni/ruby/test/cgi/test_cgi_util.rb create mode 100644 jni/ruby/test/cgi/testdata/file1.html create mode 100644 jni/ruby/test/cgi/testdata/large.png create mode 100644 jni/ruby/test/cgi/testdata/small.png (limited to 'jni/ruby/test/cgi') diff --git a/jni/ruby/test/cgi/test_cgi_cookie.rb b/jni/ruby/test/cgi/test_cgi_cookie.rb new file mode 100644 index 0000000..c1c6a30 --- /dev/null +++ b/jni/ruby/test/cgi/test_cgi_cookie.rb @@ -0,0 +1,110 @@ +require 'test/unit' +require 'cgi' +require 'stringio' + + +class CGICookieTest < Test::Unit::TestCase + + + def setup + ENV['REQUEST_METHOD'] = 'GET' + @str1="\xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93" + @str1.force_encoding("UTF-8") if defined?(::Encoding) + end + + def teardown + %W[REQUEST_METHOD SCRIPT_NAME].each do |name| + ENV.delete(name) + end + end + + + def test_cgi_cookie_new_simple + cookie = CGI::Cookie.new('name1', 'val1', '&<>"', @str1) + assert_equal('name1', cookie.name) + assert_equal(['val1', '&<>"', @str1], cookie.value) + assert_nil(cookie.domain) + assert_nil(cookie.expires) + assert_equal('', cookie.path) + assert_equal(false, cookie.secure) + assert_equal("name1=val1&%26%3C%3E%22&%E3%82%86%E3%82%93%E3%82%86%E3%82%93; path=", cookie.to_s) + end + + + def test_cgi_cookie_new_complex + t = Time.gm(2030, 12, 31, 23, 59, 59) + value = ['val1', '&<>"', "\xA5\xE0\xA5\xB9\xA5\xAB"] + value[2].force_encoding("EUC-JP") if defined?(::Encoding) + cookie = CGI::Cookie.new('name'=>'name1', + 'value'=>value, + 'path'=>'/cgi-bin/myapp/', + 'domain'=>'www.example.com', + 'expires'=>t, + 'secure'=>true + ) + assert_equal('name1', cookie.name) + assert_equal(value, cookie.value) + assert_equal('www.example.com', cookie.domain) + assert_equal(t, cookie.expires) + assert_equal('/cgi-bin/myapp/', cookie.path) + assert_equal(true, cookie.secure) + assert_equal('name1=val1&%26%3C%3E%22&%A5%E0%A5%B9%A5%AB; domain=www.example.com; path=/cgi-bin/myapp/; expires=Tue, 31 Dec 2030 23:59:59 GMT; secure', cookie.to_s) + end + + + def test_cgi_cookie_scriptname + cookie = CGI::Cookie.new('name1', 'value1') + assert_equal('', cookie.path) + cookie = CGI::Cookie.new('name'=>'name1', 'value'=>'value1') + assert_equal('', cookie.path) + ## when ENV['SCRIPT_NAME'] is set, cookie.path is set automatically + ENV['SCRIPT_NAME'] = '/cgi-bin/app/example.cgi' + cookie = CGI::Cookie.new('name1', 'value1') + assert_equal('/cgi-bin/app/', cookie.path) + cookie = CGI::Cookie.new('name'=>'name1', 'value'=>'value1') + assert_equal('/cgi-bin/app/', cookie.path) + end + + + def test_cgi_cookie_parse + ## ';' separator + cookie_str = 'name1=val1&val2; name2=val2&%26%3C%3E%22&%E3%82%86%E3%82%93%E3%82%86%E3%82%93;_session_id=12345' + cookies = CGI::Cookie.parse(cookie_str) + list = [ + ['name1', ['val1', 'val2']], + ['name2', ['val2', '&<>"',@str1]], + ['_session_id', ['12345']], + ] + list.each do |name, value| + cookie = cookies[name] + assert_equal(name, cookie.name) + assert_equal(value, cookie.value) + end + ## ',' separator + cookie_str = 'name1=val1&val2, name2=val2&%26%3C%3E%22&%E3%82%86%E3%82%93%E3%82%86%E3%82%93,_session_id=12345' + cookies = CGI::Cookie.parse(cookie_str) + list.each do |name, value| + cookie = cookies[name] + assert_equal(name, cookie.name) + assert_equal(value, cookie.value) + end + end + + + def test_cgi_cookie_arrayinterface + cookie = CGI::Cookie.new('name1', 'a', 'b', 'c') + assert_equal('a', cookie[0]) + assert_equal('c', cookie[2]) + assert_nil(cookie[3]) + assert_equal('a', cookie.first) + assert_equal('c', cookie.last) + assert_equal(['A', 'B', 'C'], cookie.collect{|e| e.upcase}) + end + + + + instance_methods.each do |method| + private method if method =~ /^test_(.*)/ && $1 != ENV['TEST'] + end if ENV['TEST'] + +end diff --git a/jni/ruby/test/cgi/test_cgi_core.rb b/jni/ruby/test/cgi/test_cgi_core.rb new file mode 100644 index 0000000..274d088 --- /dev/null +++ b/jni/ruby/test/cgi/test_cgi_core.rb @@ -0,0 +1,312 @@ +require 'test/unit' +require 'cgi' +require 'stringio' + + +class CGICoreTest < Test::Unit::TestCase + + + def setup + #@environ = { + # 'SERVER_PROTOCOL' => 'HTTP/1.1', + # 'REQUEST_METHOD' => 'GET', + # 'SERVER_SOFTWARE' => 'Apache 2.2.0', + #} + #ENV.update(@environ) + end + + + def teardown + @environ.each do |key, val| ENV.delete(key) end + $stdout = STDOUT + end + + def test_cgi_parse_illegal_query + @environ = { + 'REQUEST_METHOD' => 'GET', + 'QUERY_STRING' => 'a=111&&b=222&c&d=', + 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + cgi = CGI.new + assert_equal(["a","b","c","d"],cgi.keys.sort) + assert_equal("",cgi["d"]) + end + + def test_cgi_core_params_GET + @environ = { + 'REQUEST_METHOD' => 'GET', + 'QUERY_STRING' => 'id=123&id=456&id=&id&str=%40h+%3D%7E+%2F%5E%24%2F', + 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + cgi = CGI.new + ## cgi[] + assert_equal('123', cgi['id']) + assert_equal('@h =~ /^$/', cgi['str']) + ## cgi.params + assert_equal(['123', '456', ''], cgi.params['id']) + assert_equal(['@h =~ /^$/'], cgi.params['str']) + ## cgi.keys + assert_equal(['id', 'str'], cgi.keys.sort) + ## cgi.key?, cgi.has_key?, cgi.include? + assert_equal(true, cgi.key?('id')) + assert_equal(true, cgi.has_key?('id')) + assert_equal(true, cgi.include?('id')) + assert_equal(false, cgi.key?('foo')) + assert_equal(false, cgi.has_key?('foo')) + assert_equal(false, cgi.include?('foo')) + ## invalid parameter name + assert_equal('', cgi['*notfound*']) # [ruby-dev:30740] + assert_equal([], cgi.params['*notfound*']) + end + + + def test_cgi_core_params_POST + query_str = 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F' + @environ = { + 'REQUEST_METHOD' => 'POST', + 'CONTENT_LENGTH' => query_str.length.to_s, + 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + $stdin = StringIO.new + $stdin << query_str + $stdin.rewind + cgi = CGI.new + ## cgi[] + assert_equal('123', cgi['id']) + assert_equal('@h =~ /^$/', cgi['str']) + ## cgi.params + assert_equal(['123', '456', ''], cgi.params['id']) + assert_equal(['@h =~ /^$/'], cgi.params['str']) + ## invalid parameter name + assert_equal('', cgi['*notfound*']) + assert_equal([], cgi.params['*notfound*']) + end + + def test_cgi_core_params_encoding_check + query_str = 'str=%BE%BE%B9%BE' + @environ = { + 'REQUEST_METHOD' => 'POST', + 'CONTENT_LENGTH' => query_str.length.to_s, + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + $stdin = StringIO.new + $stdin << query_str + $stdin.rewind + if defined?(::Encoding) + hash={} + cgi = CGI.new(:accept_charset=>"UTF-8"){|key,val|hash[key]=val} + ## cgi[] + assert_equal("\xBE\xBE\xB9\xBE".force_encoding("UTF-8"), cgi['str']) + ## cgi.params + assert_equal(["\xBE\xBE\xB9\xBE".force_encoding("UTF-8")], cgi.params['str']) + ## accept-charset error + assert_equal({"str"=>"\xBE\xBE\xB9\xBE".force_encoding("UTF-8")},hash) + + $stdin.rewind + assert_raise(CGI::InvalidEncoding) do + cgi = CGI.new(:accept_charset=>"UTF-8") + end + + $stdin.rewind + cgi = CGI.new(:accept_charset=>"EUC-JP") + ## cgi[] + assert_equal("\xBE\xBE\xB9\xBE".force_encoding("EUC-JP"), cgi['str']) + ## cgi.params + assert_equal(["\xBE\xBE\xB9\xBE".force_encoding("EUC-JP")], cgi.params['str']) + else + assert(true) + end + end + + + def test_cgi_core_cookie + @environ = { + 'REQUEST_METHOD' => 'GET', + 'QUERY_STRING' => 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F', + 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + cgi = CGI.new + assert_not_equal(nil,cgi.cookies) + [ ['_session_id', ['12345'], ], + ['name1', ['val1', 'val2'], ], + ].each do |key, expected| + cookie = cgi.cookies[key] + assert_kind_of(CGI::Cookie, cookie) + assert_equal(expected, cookie.value) + assert_equal(false, cookie.secure) + assert_nil(cookie.expires) + assert_nil(cookie.domain) + assert_equal('', cookie.path) + end + end + + + def test_cgi_core_maxcontentlength + @environ = { + 'REQUEST_METHOD' => 'POST', + 'CONTENT_LENGTH' => (64 * 1024 * 1024).to_s + } + ENV.update(@environ) + ex = assert_raise(StandardError) do + CGI.new + end + assert_equal("too large post data.", ex.message) + end if CGI.const_defined?(:MAX_CONTENT_LENGTH) + + + def test_cgi_core_out + @environ = { + 'REQUEST_METHOD' => 'GET', + 'QUERY_STRING' => 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F', + 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + cgi = CGI.new + ## euc string + euc_str = "\270\253\244\355\241\242\277\315\244\254\245\264\245\337\244\316\244\350\244\246\244\300" + ## utf8 (not converted) + options = { 'charset'=>'utf8' } + $stdout = StringIO.new + cgi.out(options) { euc_str } + assert_nil(options['language']) + actual = $stdout.string + expected = "Content-Type: text/html; charset=utf8\r\n" + + "Content-Length: 22\r\n" + + "\r\n" + + euc_str + if defined?(::Encoding) + actual.force_encoding("ASCII-8BIT") + expected.force_encoding("ASCII-8BIT") + end + assert_equal(expected, actual) + ## language is keeped + options = { 'charset'=>'Shift_JIS', 'language'=>'en' } + $stdout = StringIO.new + cgi.out(options) { euc_str } + assert_equal('en', options['language']) + ## HEAD method + ENV['REQUEST_METHOD'] = 'HEAD' + options = { 'charset'=>'utf8' } + $stdout = StringIO.new + cgi.out(options) { euc_str } + actual = $stdout.string + expected = "Content-Type: text/html; charset=utf8\r\n" + + "Content-Length: 22\r\n" + + "\r\n" + assert_equal(expected, actual) + end + + + def test_cgi_core_print + @environ = { + 'REQUEST_METHOD' => 'GET', + } + ENV.update(@environ) + cgi = CGI.new + $stdout = StringIO.new + str = "foobar" + cgi.print(str) + expected = str + actual = $stdout.string + assert_equal(expected, actual) + end + + + def test_cgi_core_environs + @environ = { + 'REQUEST_METHOD' => 'GET', + } + ENV.update(@environ) + cgi = CGI.new + ## + list1 = %w[ AUTH_TYPE CONTENT_TYPE GATEWAY_INTERFACE PATH_INFO + PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST + REMOTE_IDENT REMOTE_USER REQUEST_METHOD SCRIPT_NAME + SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE + HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING + HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_HOST + HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT + ] + # list2 = %w[ CONTENT_LENGTH SERVER_PORT ] + ## string expected + list1.each do |name| + @environ[name] = "**#{name}**" + end + ENV.update(@environ) + list1.each do |name| + method = name.sub(/\AHTTP_/, '').downcase + actual = cgi.__send__ method + expected = "**#{name}**" + assert_equal(expected, actual) + end + ## integer expected + ENV['CONTENT_LENGTH'] = '123' + ENV['SERVER_PORT'] = '8080' + assert_equal(123, cgi.content_length) + assert_equal(8080, cgi.server_port) + ## raw cookie + ENV['HTTP_COOKIE'] = 'name1=val1' + ENV['HTTP_COOKIE2'] = 'name2=val2' + assert_equal('name1=val1', cgi.raw_cookie) + assert_equal('name2=val2', cgi.raw_cookie2) + end + + + def test_cgi_core_htmltype_header + @environ = { + 'REQUEST_METHOD' => 'GET', + } + ENV.update(@environ) + ## no htmltype + cgi = CGI.new + assert_raise(NoMethodError) do cgi.doctype end + assert_equal("Content-Type: text/html\r\n\r\n",cgi.header) + ## html3 + cgi = CGI.new('html3') + expected = '' + assert_equal(expected, cgi.doctype) + assert_equal("Content-Type: text/html\r\n\r\n",cgi.header) + ## html4 + cgi = CGI.new('html4') + expected = '' + assert_equal(expected, cgi.doctype) + assert_equal("Content-Type: text/html\r\n\r\n",cgi.header) + ## html4 transitional + cgi = CGI.new('html4Tr') + expected = '' + assert_equal(expected, cgi.doctype) + assert_equal("Content-Type: text/html\r\n\r\n",cgi.header) + ## html4 frameset + cgi = CGI.new('html4Fr') + expected = '' + assert_equal(expected, cgi.doctype) + assert_equal("Content-Type: text/html\r\n\r\n",cgi.header) + ## html5 + cgi = CGI.new('html5') + expected = '' + assert_equal(expected, cgi.doctype) + assert_match(/^
<\/HEADER>$/i,cgi.header) + end + + + instance_methods.each do |method| + private method if method =~ /^test_(.*)/ && $1 != ENV['TEST'] + end if ENV['TEST'] + +end diff --git a/jni/ruby/test/cgi/test_cgi_header.rb b/jni/ruby/test/cgi/test_cgi_header.rb new file mode 100644 index 0000000..9022301 --- /dev/null +++ b/jni/ruby/test/cgi/test_cgi_header.rb @@ -0,0 +1,181 @@ +require 'test/unit' +require 'cgi' +require 'time' + + +class CGIHeaderTest < Test::Unit::TestCase + + + def setup + @environ = { + 'SERVER_PROTOCOL' => 'HTTP/1.1', + 'REQUEST_METHOD' => 'GET', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + } + ENV.update(@environ) + end + + + def teardown + @environ.each do |key, val| ENV.delete(key) end + end + + + def test_cgi_http_header_simple + cgi = CGI.new + ## default content type + expected = "Content-Type: text/html\r\n\r\n" + actual = cgi.http_header + assert_equal(expected, actual) + ## content type specified as string + expected = "Content-Type: text/xhtml; charset=utf8\r\n\r\n" + actual = cgi.http_header('text/xhtml; charset=utf8') + assert_equal(expected, actual) + ## content type specified as hash + expected = "Content-Type: image/png\r\n\r\n" + actual = cgi.http_header('type'=>'image/png') + assert_equal(expected, actual) + ## charset specified + expected = "Content-Type: text/html; charset=utf8\r\n\r\n" + actual = cgi.http_header('charset'=>'utf8') + assert_equal(expected, actual) + end + + + def test_cgi_http_header_complex + cgi = CGI.new + options = { + 'type' => 'text/xhtml', + 'charset' => 'utf8', + 'status' => 'REDIRECT', + 'server' => 'webrick', + 'connection' => 'close', + 'length' => 123, + 'language' => 'ja', + 'expires' => Time.gm(2000, 1, 23, 12, 34, 56), + 'location' => 'http://www.ruby-lang.org/', + } + expected = "Status: 302 Found\r\n" + expected << "Server: webrick\r\n" + expected << "Connection: close\r\n" + expected << "Content-Type: text/xhtml; charset=utf8\r\n" + expected << "Content-Length: 123\r\n" + expected << "Content-Language: ja\r\n" + expected << "Expires: Sun, 23 Jan 2000 12:34:56 GMT\r\n" + expected << "location: http://www.ruby-lang.org/\r\n" + expected << "\r\n" + actual = cgi.http_header(options) + assert_equal(expected, actual) + end + + + def test_cgi_http_header_argerr + cgi = CGI.new + expected = ArgumentError + + assert_raise(expected) do + cgi.http_header(nil) + end + end + + + def test_cgi_http_header_cookie + cgi = CGI.new + cookie1 = CGI::Cookie.new('name1', 'abc', '123') + cookie2 = CGI::Cookie.new('name'=>'name2', 'value'=>'value2', 'secure'=>true) + ctype = "Content-Type: text/html\r\n" + sep = "\r\n" + c1 = "Set-Cookie: name1=abc&123; path=\r\n" + c2 = "Set-Cookie: name2=value2; path=; secure\r\n" + ## CGI::Cookie object + actual = cgi.http_header('cookie'=>cookie1) + expected = ctype + c1 + sep + assert_equal(expected, actual) + ## String + actual = cgi.http_header('cookie'=>cookie2.to_s) + expected = ctype + c2 + sep + assert_equal(expected, actual) + ## Array + actual = cgi.http_header('cookie'=>[cookie1, cookie2]) + expected = ctype + c1 + c2 + sep + assert_equal(expected, actual) + ## Hash + actual = cgi.http_header('cookie'=>{'name1'=>cookie1, 'name2'=>cookie2}) + expected = ctype + c1 + c2 + sep + assert_equal(expected, actual) + end + + + def test_cgi_http_header_output_cookies + cgi = CGI.new + ## output cookies + cookies = [ CGI::Cookie.new('name1', 'abc', '123'), + CGI::Cookie.new('name'=>'name2', 'value'=>'value2', 'secure'=>true), + ] + cgi.instance_variable_set('@output_cookies', cookies) + expected = "Content-Type: text/html; charset=utf8\r\n" + expected << "Set-Cookie: name1=abc&123; path=\r\n" + expected << "Set-Cookie: name2=value2; path=; secure\r\n" + expected << "\r\n" + ## header when string + actual = cgi.http_header('text/html; charset=utf8') + assert_equal(expected, actual) + ## _header_for_string + actual = cgi.http_header('type'=>'text/html', 'charset'=>'utf8') + assert_equal(expected, actual) + end + + + def test_cgi_http_header_nph + time_start = Time.now.to_i + cgi = CGI.new + ## 'nph' is true + ENV['SERVER_SOFTWARE'] = 'Apache 2.2.0' + actual1 = cgi.http_header('nph'=>true) + ## when old IIS, NPH-mode is forced + ENV['SERVER_SOFTWARE'] = 'IIS/4.0' + actual2 = cgi.http_header + actual3 = cgi.http_header('status'=>'REDIRECT', 'location'=>'http://www.example.com/') + ## newer IIS doesn't require NPH-mode ## [ruby-dev:30537] + ENV['SERVER_SOFTWARE'] = 'IIS/5.0' + actual4 = cgi.http_header + actual5 = cgi.http_header('status'=>'REDIRECT', 'location'=>'http://www.example.com/') + time_end = Time.now.to_i + date = /^Date: ([A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} \d\d:\d\d:\d\d GMT)\r\n/ + [actual1, actual2, actual3].each do |actual| + assert_match(date, actual) + assert_includes(time_start..time_end, date =~ actual && Time.parse($1).to_i) + actual.sub!(date, "Date: DATE_IS_REMOVED\r\n") + end + ## assertion + expected = "HTTP/1.1 200 OK\r\n" + expected << "Date: DATE_IS_REMOVED\r\n" + expected << "Server: Apache 2.2.0\r\n" + expected << "Connection: close\r\n" + expected << "Content-Type: text/html\r\n" + expected << "\r\n" + assert_equal(expected, actual1) + expected.sub!(/^Server: .*?\r\n/, "Server: IIS/4.0\r\n") + assert_equal(expected, actual2) + expected.sub!(/^HTTP\/1.1 200 OK\r\n/, "HTTP/1.1 302 Found\r\n") + expected.sub!(/\r\n\r\n/, "\r\nlocation: http://www.example.com/\r\n\r\n") + assert_equal(expected, actual3) + expected = "Content-Type: text/html\r\n" + expected << "\r\n" + assert_equal(expected, actual4) + expected = "Status: 302 Found\r\n" + expected << "Content-Type: text/html\r\n" + expected << "location: http://www.example.com/\r\n" + expected << "\r\n" + assert_equal(expected, actual5) + ensure + ENV.delete('SERVER_SOFTWARE') + end + + + + instance_methods.each do |method| + private method if method =~ /^test_(.*)/ && $1 != ENV['TEST'] + end if ENV['TEST'] + +end diff --git a/jni/ruby/test/cgi/test_cgi_modruby.rb b/jni/ruby/test/cgi/test_cgi_modruby.rb new file mode 100644 index 0000000..b0fc442 --- /dev/null +++ b/jni/ruby/test/cgi/test_cgi_modruby.rb @@ -0,0 +1,146 @@ +require 'test/unit' +require 'cgi' + + +class CGIModrubyTest < Test::Unit::TestCase + + + def setup + @environ = { + 'SERVER_PROTOCOL' => 'HTTP/1.1', + 'REQUEST_METHOD' => 'GET', + #'QUERY_STRING' => 'a=foo&b=bar', + } + ENV.update(@environ) + CGI.class_eval { const_set(:MOD_RUBY, true) } + Apache._reset() + #@cgi = CGI.new + #@req = Apache.request + end + + + def teardown + @environ.each do |key, val| ENV.delete(key) end + CGI.class_eval { remove_const(:MOD_RUBY) } + end + + + def test_cgi_modruby_simple + req = Apache.request + cgi = CGI.new + assert(req._setup_cgi_env_invoked?) + assert(! req._send_http_header_invoked?) + actual = cgi.http_header + assert_equal('', actual) + assert_equal('text/html', req.content_type) + assert(req._send_http_header_invoked?) + end + + + def test_cgi_modruby_complex + req = Apache.request + cgi = CGI.new + options = { + 'status' => 'FORBIDDEN', + 'location' => 'http://www.example.com/', + 'type' => 'image/gif', + 'content-encoding' => 'deflate', + 'cookie' => [ CGI::Cookie.new('name1', 'abc', '123'), + CGI::Cookie.new('name'=>'name2', 'value'=>'value2', 'secure'=>true), + ], + } + assert(req._setup_cgi_env_invoked?) + assert(! req._send_http_header_invoked?) + actual = cgi.http_header(options) + assert_equal('', actual) + assert_equal('image/gif', req.content_type) + assert_equal('403 Forbidden', req.status_line) + assert_equal(403, req.status) + assert_equal('deflate', req.content_encoding) + assert_equal('http://www.example.com/', req.headers_out['location']) + assert_equal(["name1=abc&123; path=", "name2=value2; path=; secure"], + req.headers_out['Set-Cookie']) + assert(req._send_http_header_invoked?) + end + + + def test_cgi_modruby_location + req = Apache.request + cgi = CGI.new + options = { + 'status' => '200 OK', + 'location' => 'http://www.example.com/', + } + cgi.http_header(options) + assert_equal('200 OK', req.status_line) # should be '302 Found' ? + assert_equal(302, req.status) + assert_equal('http://www.example.com/', req.headers_out['location']) + end + + + def test_cgi_modruby_requestparams + req = Apache.request + req.args = 'a=foo&b=bar' + cgi = CGI.new + assert_equal('foo', cgi['a']) + assert_equal('bar', cgi['b']) + end + + + instance_methods.each do |method| + private method if method =~ /^test_(.*)/ && $1 != ENV['TEST'] + end if ENV['TEST'] + +end + + + +## dummy class for mod_ruby +class Apache #:nodoc: + + def self._reset + @request = Request.new + end + + def self.request + return @request + end + + class Request + + def initialize + hash = {} + def hash.add(name, value) + (self[name] ||= []) << value + end + @http_header = nil + @headers_out = hash + @status_line = nil + @status = nil + @content_type = nil + @content_encoding = nil + end + attr_accessor :headers_out, :status_line, :status, :content_type, :content_encoding + + attr_accessor :args + #def args + # return ENV['QUERY_STRING'] + #end + + def send_http_header + @http_header = '*invoked*' + end + def _send_http_header_invoked? + @http_header ? true : false + end + + def setup_cgi_env + @cgi_env = '*invoked*' + end + def _setup_cgi_env_invoked? + @cgi_env ? true : false + end + + end + +end diff --git a/jni/ruby/test/cgi/test_cgi_multipart.rb b/jni/ruby/test/cgi/test_cgi_multipart.rb new file mode 100644 index 0000000..1325798 --- /dev/null +++ b/jni/ruby/test/cgi/test_cgi_multipart.rb @@ -0,0 +1,380 @@ +require 'test/unit' +require 'cgi' +require 'tempfile' +require 'stringio' + + +## +## usage: +## boundary = 'foobar1234' # or nil +## multipart = MultiPart.new(boundary) +## multipart.append('name1', 'value1') +## multipart.append('file1', File.read('file1.html'), 'file1.html') +## str = multipart.close() +## str.each_line {|line| p line } +## ## output: +## # "--foobar1234\r\n" +## # "Content-Disposition: form-data: name=\"name1\"\r\n" +## # "\r\n" +## # "value1\r\n" +## # "--foobar1234\r\n" +## # "Content-Disposition: form-data: name=\"file1\"; filename=\"file1.html\"\r\n" +## # "Content-Type: text/html\r\n" +## # "\r\n" +## # "\n" +## # "

Hello

\n" +## # "\n" +## # "\r\n" +## # "--foobar1234--\r\n" +## +class MultiPart + + def initialize(boundary=nil) + @boundary = boundary || create_boundary() + @buf = '' + @buf.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding) + end + attr_reader :boundary + + def append(name, value, filename=nil, content_type=nil) + content_type = detect_content_type(filename) if filename && content_type.nil? + s = filename ? "; filename=\"#{filename}\"" : '' + buf = @buf + buf << "--#{boundary}\r\n" + buf << "Content-Disposition: form-data: name=\"#{name}\"#{s}\r\n" + buf << "Content-Type: #{content_type}\r\n" if content_type + buf << "\r\n" + value = value.dup.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding) + buf << value + buf << "\r\n" + return self + end + + def close + buf = @buf + @buf = '' + return buf << "--#{boundary}--\r\n" + end + + def create_boundary() #:nodoc: + return "--boundary#{rand().to_s[2..-1]}" + end + + def detect_content_type(filename) #:nodoc: + filename =~ /\.(\w+)\z/ + return MIME_TYPES[$1] || 'application/octet-stream' + end + + MIME_TYPES = { + 'gif' => 'image/gif', + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'png' => 'image/png', + 'bmp' => 'image/bmp', + 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', + 'htm' => 'text/html', + 'html' => 'text/html', + 'xml' => 'text/xml', + 'txt' => 'text/plain', + 'text' => 'text/plain', + 'css' => 'text/css', + 'mpg' => 'video/mpeg', + 'mpeg' => 'video/mpeg', + 'mov' => 'video/quicktime', + 'avi' => 'video/x-msvideo', + 'mp3' => 'audio/mpeg', + 'mid' => 'audio/midi', + 'wav' => 'audio/x-wav', + 'zip' => 'application/zip', + #'tar.gz' => 'application/gtar', + 'gz' => 'application/gzip', + 'bz2' => 'application/bzip2', + 'rtf' => 'application/rtf', + 'pdf' => 'application/pdf', + 'ps' => 'application/postscript', + 'js' => 'application/x-javascript', + 'xls' => 'application/vnd.ms-excel', + 'doc' => 'application/msword', + 'ppt' => 'application/vnd.ms-powerpoint', + } + +end + + + +class CGIMultipartTest < Test::Unit::TestCase + + def setup + ENV['REQUEST_METHOD'] = 'POST' + @tempfiles = [] + end + + def teardown + %w[ REQUEST_METHOD CONTENT_TYPE CONTENT_LENGTH REQUEST_METHOD ].each do |name| + ENV.delete(name) + end + $stdin.close() if $stdin.is_a?(Tempfile) + $stdin = STDIN + @tempfiles.each {|t| + t.close! + } + end + + def _prepare(data) + ## create multipart input + multipart = MultiPart.new(defined?(@boundary) ? @boundary : nil) + data.each do |hash| + multipart.append(hash[:name], hash[:value], hash[:filename]) + end + input = multipart.close() + input = yield(input) if block_given? + #$stderr.puts "*** debug: input=\n#{input.collect{|line| line.inspect}.join("\n")}" + @boundary ||= multipart.boundary + ## set environment + ENV['CONTENT_TYPE'] = "multipart/form-data; boundary=#{@boundary}" + ENV['CONTENT_LENGTH'] = input.length.to_s + ENV['REQUEST_METHOD'] = 'POST' + ## set $stdin + tmpfile = Tempfile.new('test_cgi_multipart') + @tempfiles << tmpfile + tmpfile.binmode + tmpfile << input + tmpfile.rewind() + $stdin = tmpfile + end + + def _test_multipart(cgi_options={}) + caller(0).find {|s| s =~ /in `test_(.*?)'/ } + #testname = $1 + #$stderr.puts "*** debug: testname=#{testname.inspect}" + _prepare(@data) + options = {:accept_charset=>"UTF-8"} + options.merge! cgi_options + cgi = CGI.new(options) + expected_names = @data.collect{|hash| hash[:name] }.sort + assert_equal(expected_names, cgi.params.keys.sort) + threshold = 1024*10 + @data.each do |hash| + name = hash[:name] + expected = hash[:value] + if hash[:filename] #if file + expected_class = @expected_class || (hash[:value].length < threshold ? StringIO : Tempfile) + assert(cgi.files.keys.member?(hash[:name])) + else + expected_class = String + assert_equal(expected, cgi[name]) + assert_equal(false,cgi.files.keys.member?(hash[:name])) + end + assert_kind_of(expected_class, cgi[name]) + assert_equal(expected, cgi[name].read()) + assert_equal(hash[:filename] || '', cgi[name].original_filename) #if hash[:filename] + assert_equal(hash[:content_type] || '', cgi[name].content_type) #if hash[:content_type] + end + ensure + if cgi + cgi.params.each {|name, vals| + vals.each {|val| + if val.kind_of?(Tempfile) && val.path + val.close! + end + } + } + end + end + + + def _read(basename) + filename = File.join(File.dirname(__FILE__), 'testdata', basename) + s = File.open(filename, 'rb') {|f| f.read() } + + return s + end + + + def test_cgi_multipart_stringio + @boundary = '----WebKitFormBoundaryAAfvAII+YL9102cX' + @data = [ + {:name=>'hidden1', :value=>'foobar'}, + {:name=>'text1', :value=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"}, + {:name=>'file1', :value=>_read('file1.html'), + :filename=>'file1.html', :content_type=>'text/html'}, + {:name=>'image1', :value=>_read('small.png'), + :filename=>'small.png', :content_type=>'image/png'}, # small image + ] + @data[1][:value].force_encoding(::Encoding::UTF_8) if defined?(::Encoding) + @expected_class = StringIO + _test_multipart() + end + + + def test_cgi_multipart_tempfile + @boundary = '----WebKitFormBoundaryAAfvAII+YL9102cX' + @data = [ + {:name=>'hidden1', :value=>'foobar'}, + {:name=>'text1', :value=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"}, + {:name=>'file1', :value=>_read('file1.html'), + :filename=>'file1.html', :content_type=>'text/html'}, + {:name=>'image1', :value=>_read('large.png'), + :filename=>'large.png', :content_type=>'image/png'}, # large image + ] + @data[1][:value].force_encoding(::Encoding::UTF_8) if defined?(::Encoding) + @expected_class = Tempfile + _test_multipart() + end + + + def _set_const(klass, name, value) + old = nil + klass.class_eval do + old = const_get(name) + remove_const(name) + const_set(name, value) + end + return old + end + + + def test_cgi_multipart_maxmultipartlength + @data = [ + {:name=>'image1', :value=>_read('large.png'), + :filename=>'large.png', :content_type=>'image/png'}, # large image + ] + begin + ex = assert_raise(StandardError) do + _test_multipart(:max_multipart_length=>2 * 1024) # set via simple scalar + end + assert_equal("too large multipart data.", ex.message) + ensure + end + end + + + def test_cgi_multipart_maxmultipartlength_lambda + @data = [ + {:name=>'image1', :value=>_read('large.png'), + :filename=>'large.png', :content_type=>'image/png'}, # large image + ] + begin + ex = assert_raise(StandardError) do + _test_multipart(:max_multipart_length=>lambda{2*1024}) # set via lambda + end + assert_equal("too large multipart data.", ex.message) + ensure + end + end + + + def test_cgi_multipart_maxmultipartcount + @data = [ + {:name=>'file1', :value=>_read('file1.html'), + :filename=>'file1.html', :content_type=>'text/html'}, + ] + item = @data.first + 500.times { @data << item } + #original = _set_const(CGI, :MAX_MULTIPART_COUNT, 128) + begin + ex = assert_raise(StandardError) do + _test_multipart() + end + assert_equal("too many parameters.", ex.message) + ensure + #_set_const(CGI, :MAX_MULTIPART_COUNT, original) + end + end if CGI.const_defined?(:MAX_MULTIPART_COUNT) + + + def test_cgi_multipart_badbody ## [ruby-dev:28470] + @data = [ + {:name=>'file1', :value=>_read('file1.html'), + :filename=>'file1.html', :content_type=>'text/html'}, + ] + _prepare(@data) do |input| + input2 = input.sub(/--(\r\n)?\z/, "\r\n") + assert input2 != input + #p input2 + input2 + end + ex = assert_raise(EOFError) do + CGI.new(:accept_charset=>"UTF-8") + end + assert_equal("bad content body", ex.message) + # + _prepare(@data) do |input| + input2 = input.sub(/--(\r\n)?\z/, "") + assert input2 != input + #p input2 + input2 + end + ex = assert_raise(EOFError) do + CGI.new(:accept_charset=>"UTF-8") + end + assert_equal("bad content body", ex.message) + end + + + def test_cgi_multipart_quoteboundary ## [JVN#84798830] + @boundary = '(.|\n)*' + @data = [ + {:name=>'hidden1', :value=>'foobar'}, + {:name=>'text1', :value=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"}, + {:name=>'file1', :value=>_read('file1.html'), + :filename=>'file1.html', :content_type=>'text/html'}, + {:name=>'image1', :value=>_read('small.png'), + :filename=>'small.png', :content_type=>'image/png'}, # small image + ] + @data[1][:value].force_encoding("UTF-8") + _prepare(@data) + cgi = CGI.new(:accept_charset=>"UTF-8") + assert_equal('file1.html', cgi['file1'].original_filename) + end + + def test_cgi_multipart_boundary_10240 # [Bug #3866] + @boundary = 'AaB03x' + @data = [ + {:name=>'file', :value=>"b"*10134, + :filename=>'file.txt', :content_type=>'text/plain'}, + {:name=>'foo', :value=>"bar"}, + ] + _prepare(@data) + cgi = CGI.new(:accept_charset=>"UTF-8") + assert_equal(cgi['foo'], 'bar') + assert_equal(cgi['file'].read, 'b'*10134) + cgi['file'].close! if cgi['file'].kind_of? Tempfile + end + + def test_cgi_multipart_without_tempfile + assert_in_out_err([], <<-'EOM') + require 'cgi' + require 'stringio' + ENV['REQUEST_METHOD'] = 'POST' + ENV['CONTENT_TYPE'] = 'multipart/form-data; boundary=foobar1234' + body = <<-BODY +--foobar1234 +Content-Disposition: form-data: name=\"name1\" + +value1 +--foobar1234 +Content-Disposition: form-data: name=\"file1\"; filename=\"file1.html\" +Content-Type: text/html + + +

Hello

+ + +--foobar1234-- +BODY + body.gsub!(/\n/, "\r\n") + ENV['CONTENT_LENGTH'] = body.size.to_s + $stdin = StringIO.new(body) + CGI.new + EOM + end + + ### + + self.instance_methods.each do |method| + private method if method =~ /^test_(.*)/ && $1 != ENV['TEST'] + end if ENV['TEST'] + +end diff --git a/jni/ruby/test/cgi/test_cgi_session.rb b/jni/ruby/test/cgi/test_cgi_session.rb new file mode 100644 index 0000000..8bd5177 --- /dev/null +++ b/jni/ruby/test/cgi/test_cgi_session.rb @@ -0,0 +1,172 @@ +require 'test/unit' +require 'cgi' +require 'cgi/session' +require 'cgi/session/pstore' +require 'stringio' +require 'tmpdir' + +class CGISessionTest < Test::Unit::TestCase + def setup + @session_dir = Dir.mktmpdir(%w'session dir') + end + + def teardown + @environ.each do |key, val| ENV.delete(key) end + $stdout = STDOUT + FileUtils.rm_rf(@session_dir) + end + + def test_cgi_session_filestore + @environ = { + 'REQUEST_METHOD' => 'GET', + # 'QUERY_STRING' => 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F', + # 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + value1="value1" + value2="\x8F\xBC\x8D]" + value2.force_encoding("SJIS") if defined?(::Encoding) + ENV.update(@environ) + cgi = CGI.new + session = CGI::Session.new(cgi,"tmpdir"=>@session_dir) + session["key1"]=value1 + session["key2"]=value2 + assert_equal(value1,session["key1"]) + assert_equal(value2,session["key2"]) + session.close + $stdout = StringIO.new + cgi.out{""} + + @environ = { + 'REQUEST_METHOD' => 'GET', + # 'HTTP_COOKIE' => "_session_id=#{session_id}", + 'QUERY_STRING' => "_session_id=#{session.session_id}", + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + cgi = CGI.new + session = CGI::Session.new(cgi,"tmpdir"=>@session_dir) + $stdout = StringIO.new + assert_equal(value1,session["key1"]) + assert_equal(value2,session["key2"]) + session.close + + end + def test_cgi_session_pstore + @environ = { + 'REQUEST_METHOD' => 'GET', + # 'QUERY_STRING' => 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F', + # 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + value1="value1" + value2="\x8F\xBC\x8D]" + value2.force_encoding("SJIS") if defined?(::Encoding) + ENV.update(@environ) + cgi = CGI.new + session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"database_manager"=>CGI::Session::PStore) + session["key1"]=value1 + session["key2"]=value2 + assert_equal(value1,session["key1"]) + assert_equal(value2,session["key2"]) + session.close + $stdout = StringIO.new + cgi.out{""} + + @environ = { + 'REQUEST_METHOD' => 'GET', + # 'HTTP_COOKIE' => "_session_id=#{session_id}", + 'QUERY_STRING' => "_session_id=#{session.session_id}", + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + cgi = CGI.new + session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"database_manager"=>CGI::Session::PStore) + $stdout = StringIO.new + assert_equal(value1,session["key1"]) + assert_equal(value2,session["key2"]) + session.close + end + def test_cgi_session_specify_session_id + @environ = { + 'REQUEST_METHOD' => 'GET', + # 'QUERY_STRING' => 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F', + # 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + value1="value1" + value2="\x8F\xBC\x8D]" + value2.force_encoding("SJIS") if defined?(::Encoding) + ENV.update(@environ) + cgi = CGI.new + session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_id"=>"foo") + session["key1"]=value1 + session["key2"]=value2 + assert_equal(value1,session["key1"]) + assert_equal(value2,session["key2"]) + assert_equal("foo",session.session_id) + #session_id=session.session_id + session.close + $stdout = StringIO.new + cgi.out{""} + + @environ = { + 'REQUEST_METHOD' => 'GET', + # 'HTTP_COOKIE' => "_session_id=#{session_id}", + 'QUERY_STRING' => "_session_id=#{session.session_id}", + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + cgi = CGI.new + session = CGI::Session.new(cgi,"tmpdir"=>@session_dir) + $stdout = StringIO.new + assert_equal(value1,session["key1"]) + assert_equal(value2,session["key2"]) + assert_equal("foo",session.session_id) + session.close + end + def test_cgi_session_specify_session_key + @environ = { + 'REQUEST_METHOD' => 'GET', + # 'QUERY_STRING' => 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F', + # 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;', + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + value1="value1" + value2="\x8F\xBC\x8D]" + value2.force_encoding("SJIS") if defined?(::Encoding) + ENV.update(@environ) + cgi = CGI.new + session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar") + session["key1"]=value1 + session["key2"]=value2 + assert_equal(value1,session["key1"]) + assert_equal(value2,session["key2"]) + session_id=session.session_id + session.close + $stdout = StringIO.new + cgi.out{""} + + @environ = { + 'REQUEST_METHOD' => 'GET', + 'HTTP_COOKIE' => "bar=#{session_id}", + # 'QUERY_STRING' => "bar=#{session.session_id}", + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + cgi = CGI.new + session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar") + $stdout = StringIO.new + assert_equal(value1,session["key1"]) + assert_equal(value2,session["key2"]) + session.close + end +end diff --git a/jni/ruby/test/cgi/test_cgi_tag_helper.rb b/jni/ruby/test/cgi/test_cgi_tag_helper.rb new file mode 100644 index 0000000..eb3c20a --- /dev/null +++ b/jni/ruby/test/cgi/test_cgi_tag_helper.rb @@ -0,0 +1,353 @@ +require 'test/unit' +require 'cgi' +require 'stringio' + + +class CGITagHelperTest < Test::Unit::TestCase + + + def setup + #@environ = { + # 'SERVER_PROTOCOL' => 'HTTP/1.1', + # 'REQUEST_METHOD' => 'GET', + # 'SERVER_SOFTWARE' => 'Apache 2.2.0', + #} + #ENV.update(@environ) + end + + + def teardown + @environ.each do |key, val| ENV.delete(key) end + $stdout = STDOUT + end + + + def test_cgi_tag_helper_html3 + @environ = { + 'REQUEST_METHOD' => 'GET', + } + ENV.update(@environ) + ## html3 + cgi = CGI.new('html3') + assert_equal('',cgi.a) + assert_equal('',cgi.a('bar')) + assert_equal('foo',cgi.a{'foo'}) + assert_equal('foo',cgi.a('bar'){'foo'}) + assert_equal('',cgi.tt) + assert_equal('',cgi.tt('bar')) + assert_equal('foo',cgi.tt{'foo'}) + assert_equal('foo',cgi.tt('bar'){'foo'}) + assert_equal('',cgi.i) + assert_equal('',cgi.i('bar')) + assert_equal('foo',cgi.i{'foo'}) + assert_equal('foo',cgi.i('bar'){'foo'}) + assert_equal('',cgi.b) + assert_equal('',cgi.b('bar')) + assert_equal('foo',cgi.b{'foo'}) + assert_equal('foo',cgi.b('bar'){'foo'}) + assert_equal('',cgi.u) + assert_equal('',cgi.u('bar')) + assert_equal('foo',cgi.u{'foo'}) + assert_equal('foo',cgi.u('bar'){'foo'}) + assert_equal('',cgi.strike) + assert_equal('',cgi.strike('bar')) + assert_equal('foo',cgi.strike{'foo'}) + assert_equal('foo',cgi.strike('bar'){'foo'}) + assert_equal('',cgi.big) + assert_equal('',cgi.big('bar')) + assert_equal('foo',cgi.big{'foo'}) + assert_equal('foo',cgi.big('bar'){'foo'}) + assert_equal('',cgi.small) + assert_equal('',cgi.small('bar')) + assert_equal('foo',cgi.small{'foo'}) + assert_equal('foo',cgi.small('bar'){'foo'}) + assert_equal('',cgi.sub) + assert_equal('',cgi.sub('bar')) + assert_equal('foo',cgi.sub{'foo'}) + assert_equal('foo',cgi.sub('bar'){'foo'}) + assert_equal('',cgi.sup) + assert_equal('',cgi.sup('bar')) + assert_equal('foo',cgi.sup{'foo'}) + assert_equal('foo',cgi.sup('bar'){'foo'}) + assert_equal('',cgi.em) + assert_equal('',cgi.em('bar')) + assert_equal('foo',cgi.em{'foo'}) + assert_equal('foo',cgi.em('bar'){'foo'}) + assert_equal('',cgi.strong) + assert_equal('',cgi.strong('bar')) + assert_equal('foo',cgi.strong{'foo'}) + assert_equal('foo',cgi.strong('bar'){'foo'}) + assert_equal('',cgi.dfn) + assert_equal('',cgi.dfn('bar')) + assert_equal('foo',cgi.dfn{'foo'}) + assert_equal('foo',cgi.dfn('bar'){'foo'}) + assert_equal('',cgi.code) + assert_equal('',cgi.code('bar')) + assert_equal('foo',cgi.code{'foo'}) + assert_equal('foo',cgi.code('bar'){'foo'}) + assert_equal('',cgi.samp) + assert_equal('',cgi.samp('bar')) + assert_equal('foo',cgi.samp{'foo'}) + assert_equal('foo',cgi.samp('bar'){'foo'}) + assert_equal('',cgi.kbd) + assert_equal('',cgi.kbd('bar')) + assert_equal('foo',cgi.kbd{'foo'}) + assert_equal('foo',cgi.kbd('bar'){'foo'}) + assert_equal('',cgi.var) + assert_equal('',cgi.var('bar')) + assert_equal('foo',cgi.var{'foo'}) + assert_equal('foo',cgi.var('bar'){'foo'}) + assert_equal('',cgi.cite) + assert_equal('',cgi.cite('bar')) + assert_equal('foo',cgi.cite{'foo'}) + assert_equal('foo',cgi.cite('bar'){'foo'}) + assert_equal('',cgi.font) + assert_equal('',cgi.font('bar')) + assert_equal('foo',cgi.font{'foo'}) + assert_equal('foo',cgi.font('bar'){'foo'}) + assert_equal('
',cgi.address) + assert_equal('
',cgi.address('bar')) + assert_equal('
foo
',cgi.address{'foo'}) + assert_equal('
foo
',cgi.address('bar'){'foo'}) + assert_equal('
',cgi.div) + assert_equal('
',cgi.div('bar')) + assert_equal('
foo
',cgi.div{'foo'}) + assert_equal('
foo
',cgi.div('bar'){'foo'}) + assert_equal('
',cgi.center) + assert_equal('
',cgi.center('bar')) + assert_equal('
foo
',cgi.center{'foo'}) + assert_equal('
foo
',cgi.center('bar'){'foo'}) + assert_equal('',cgi.map) + assert_equal('',cgi.map('bar')) + assert_equal('foo',cgi.map{'foo'}) + assert_equal('foo',cgi.map('bar'){'foo'}) + assert_equal('',cgi.applet) + assert_equal('',cgi.applet('bar')) + assert_equal('foo',cgi.applet{'foo'}) + assert_equal('foo',cgi.applet('bar'){'foo'}) + assert_equal('
',cgi.pre)
+    assert_equal('
',cgi.pre('bar'))
+    assert_equal('
foo
',cgi.pre{'foo'}) + assert_equal('
foo
',cgi.pre('bar'){'foo'}) + assert_equal('',cgi.xmp) + assert_equal('',cgi.xmp('bar')) + assert_equal('foo',cgi.xmp{'foo'}) + assert_equal('foo',cgi.xmp('bar'){'foo'}) + assert_equal('',cgi.listing) + assert_equal('',cgi.listing('bar')) + assert_equal('foo',cgi.listing{'foo'}) + assert_equal('foo',cgi.listing('bar'){'foo'}) + assert_equal('
',cgi.dl) + assert_equal('
',cgi.dl('bar')) + assert_equal('
foo
',cgi.dl{'foo'}) + assert_equal('
foo
',cgi.dl('bar'){'foo'}) + assert_equal('
    ',cgi.ol) + assert_equal('
      ',cgi.ol('bar')) + assert_equal('
        foo
      ',cgi.ol{'foo'}) + assert_equal('
        foo
      ',cgi.ol('bar'){'foo'}) + assert_equal('',cgi.ul) + assert_equal('',cgi.ul('bar')) + assert_equal('',cgi.ul{'foo'}) + assert_equal('',cgi.ul('bar'){'foo'}) + assert_equal('',cgi.dir) + assert_equal('',cgi.dir('bar')) + assert_equal('foo',cgi.dir{'foo'}) + assert_equal('foo',cgi.dir('bar'){'foo'}) + assert_equal('',cgi.menu) + assert_equal('',cgi.menu('bar')) + assert_equal('foo',cgi.menu{'foo'}) + assert_equal('foo',cgi.menu('bar'){'foo'}) + assert_equal('',cgi.select) + assert_equal('',cgi.select('bar')) + assert_equal('',cgi.select{'foo'}) + assert_equal('',cgi.select('bar'){'foo'}) + assert_equal('
      ',cgi.table) + assert_equal('
      ',cgi.table('bar')) + assert_equal('foo
      ',cgi.table{'foo'}) + assert_equal('foo
      ',cgi.table('bar'){'foo'}) + assert_equal('',cgi.title) + assert_equal('',cgi.title('bar')) + assert_equal('foo',cgi.title{'foo'}) + assert_equal('foo',cgi.title('bar'){'foo'}) + assert_equal('',cgi.style) + assert_equal('',cgi.style('bar')) + assert_equal('',cgi.style{'foo'}) + assert_equal('',cgi.style('bar'){'foo'}) + assert_equal('',cgi.script) + assert_equal('',cgi.script('bar')) + assert_equal('',cgi.script{'foo'}) + assert_equal('',cgi.script('bar'){'foo'}) + assert_equal('

      ',cgi.h1) + assert_equal('

      ',cgi.h1('bar')) + assert_equal('

      foo

      ',cgi.h1{'foo'}) + assert_equal('

      foo

      ',cgi.h1('bar'){'foo'}) + assert_equal('

      ',cgi.h2) + assert_equal('

      ',cgi.h2('bar')) + assert_equal('

      foo

      ',cgi.h2{'foo'}) + assert_equal('

      foo

      ',cgi.h2('bar'){'foo'}) + assert_equal('

      ',cgi.h3) + assert_equal('

      ',cgi.h3('bar')) + assert_equal('

      foo

      ',cgi.h3{'foo'}) + assert_equal('

      foo

      ',cgi.h3('bar'){'foo'}) + assert_equal('

      ',cgi.h4) + assert_equal('

      ',cgi.h4('bar')) + assert_equal('

      foo

      ',cgi.h4{'foo'}) + assert_equal('

      foo

      ',cgi.h4('bar'){'foo'}) + assert_equal('
      ',cgi.h5) + assert_equal('
      ',cgi.h5('bar')) + assert_equal('
      foo
      ',cgi.h5{'foo'}) + assert_equal('
      foo
      ',cgi.h5('bar'){'foo'}) + assert_equal('
      ',cgi.h6) + assert_equal('
      ',cgi.h6('bar')) + assert_equal('
      foo
      ',cgi.h6{'foo'}) + assert_equal('
      foo
      ',cgi.h6('bar'){'foo'}) + assert_match(/^