summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHiroshi SHIBATA <[email protected]>2025-05-08 19:21:47 +0900
committerHiroshi SHIBATA <[email protected]>2025-05-09 14:27:28 +0900
commit600c616507b258cdf9dbfbc822deb267f3202325 (patch)
treeaff8f5b0847a0301391f2dc5463049b0d7cd4e33 /test
parenta61f51f66d7dff966dd17915c854fea08763722d (diff)
Removed CGI library without CGI::Escape features
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13275
Diffstat (limited to 'test')
-rw-r--r--test/cgi/test_cgi_cookie.rb211
-rw-r--r--test/cgi/test_cgi_core.rb307
-rw-r--r--test/cgi/test_cgi_header.rb192
-rw-r--r--test/cgi/test_cgi_modruby.rb149
-rw-r--r--test/cgi/test_cgi_multipart.rb385
-rw-r--r--test/cgi/test_cgi_session.rb169
-rw-r--r--test/cgi/test_cgi_tag_helper.rb355
-rw-r--r--test/cgi/test_cgi_util.rb12
-rw-r--r--test/cgi/testdata/file1.html10
-rw-r--r--test/cgi/testdata/large.pngbin156414 -> 0 bytes
-rw-r--r--test/cgi/testdata/small.pngbin82 -> 0 bytes
11 files changed, 0 insertions, 1790 deletions
diff --git a/test/cgi/test_cgi_cookie.rb b/test/cgi/test_cgi_cookie.rb
deleted file mode 100644
index eadae45313..0000000000
--- a/test/cgi/test_cgi_cookie.rb
+++ /dev/null
@@ -1,211 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-require 'cgi'
-require 'stringio'
-require_relative 'update_env'
-
-
-class CGICookieTest < Test::Unit::TestCase
- include UpdateEnv
-
-
- def setup
- @environ = {}
- update_env(
- 'REQUEST_METHOD' => 'GET',
- 'SCRIPT_NAME' => nil,
- )
- @str1="\xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93".dup
- @str1.force_encoding("UTF-8") if defined?(::Encoding)
- end
-
- def teardown
- ENV.update(@environ)
- 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(false, cookie.httponly)
- 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".dup]
- 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,
- 'httponly'=>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(true, cookie.httponly)
- 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; HttpOnly', cookie.to_s)
- end
-
-
- def test_cgi_cookie_new_with_domain
- h = {'name'=>'name1', 'value'=>'value1'}
- cookie = CGI::Cookie.new(h.merge('domain'=>'a.example.com'))
- assert_equal('a.example.com', cookie.domain)
-
- cookie = CGI::Cookie.new(h.merge('domain'=>'.example.com'))
- assert_equal('.example.com', cookie.domain)
-
- cookie = CGI::Cookie.new(h.merge('domain'=>'1.example.com'))
- assert_equal('1.example.com', cookie.domain, 'enhanced by RFC 1123')
-
- assert_raise(ArgumentError) {
- CGI::Cookie.new(h.merge('domain'=>'-a.example.com'))
- }
-
- assert_raise(ArgumentError) {
- CGI::Cookie.new(h.merge('domain'=>'a-.example.com'))
- }
- 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
- ## don't allow ',' separator
- cookie_str = 'name1=val1&val2, name2=val2'
- cookies = CGI::Cookie.parse(cookie_str)
- list = [
- ['name1', ['val1', 'val2, name2=val2']],
- ]
- list.each do |name, value|
- cookie = cookies[name]
- assert_equal(name, cookie.name)
- assert_equal(value, cookie.value)
- end
- end
-
- def test_cgi_cookie_parse_not_decode_name
- cookie_str = "%66oo=baz;foo=bar"
- cookies = CGI::Cookie.parse(cookie_str)
- assert_equal({"%66oo" => ["baz"], "foo" => ["bar"]}, cookies)
- 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
-
-
- def test_cgi_cookie_domain_injection_into_name
- name = "a=b; domain=example.com;"
- path = "/"
- domain = "example.jp"
- assert_raise(ArgumentError) do
- CGI::Cookie.new('name' => name,
- 'value' => "value",
- 'domain' => domain,
- 'path' => path)
- end
- end
-
-
- def test_cgi_cookie_newline_injection_into_name
- name = "a=b;\r\nLocation: http://example.com#"
- path = "/"
- domain = "example.jp"
- assert_raise(ArgumentError) do
- CGI::Cookie.new('name' => name,
- 'value' => "value",
- 'domain' => domain,
- 'path' => path)
- end
- end
-
-
- def test_cgi_cookie_multibyte_injection_into_name
- name = "a=b;\u3042"
- path = "/"
- domain = "example.jp"
- assert_raise(ArgumentError) do
- CGI::Cookie.new('name' => name,
- 'value' => "value",
- 'domain' => domain,
- 'path' => path)
- end
- end
-
-
- def test_cgi_cookie_injection_into_path
- name = "name"
- path = "/; samesite=none"
- domain = "example.jp"
- assert_raise(ArgumentError) do
- CGI::Cookie.new('name' => name,
- 'value' => "value",
- 'domain' => domain,
- 'path' => path)
- end
- end
-
-
- def test_cgi_cookie_injection_into_domain
- name = "name"
- path = "/"
- domain = "example.jp; samesite=none"
- assert_raise(ArgumentError) do
- CGI::Cookie.new('name' => name,
- 'value' => "value",
- 'domain' => domain,
- 'path' => path)
- end
- end
-
-
- instance_methods.each do |method|
- private method if method =~ /^test_(.*)/ && $1 != ENV['TEST']
- end if ENV['TEST']
-
-end
diff --git a/test/cgi/test_cgi_core.rb b/test/cgi/test_cgi_core.rb
deleted file mode 100644
index f7adb7e99f..0000000000
--- a/test/cgi/test_cgi_core.rb
+++ /dev/null
@@ -1,307 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-require 'cgi'
-require 'stringio'
-require_relative 'update_env'
-
-
-class CGICoreTest < Test::Unit::TestCase
- include UpdateEnv
-
- def setup
- @environ = {}
- #@environ = {
- # 'SERVER_PROTOCOL' => 'HTTP/1.1',
- # 'REQUEST_METHOD' => 'GET',
- # 'SERVER_SOFTWARE' => 'Apache 2.2.0',
- #}
- #ENV.update(@environ)
- end
-
- def teardown
- ENV.update(@environ)
- $stdout = STDOUT
- end
-
- def test_cgi_parse_illegal_query
- update_env(
- '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',
- )
- cgi = CGI.new
- assert_equal(["a","b","c","d"],cgi.keys.sort)
- assert_equal("",cgi["d"])
- end
-
- def test_cgi_core_params_GET
- update_env(
- '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',
- )
- 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'
- update_env(
- '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',
- )
- $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*'])
- ensure
- $stdin = STDIN
- end
-
- def test_cgi_core_params_encoding_check
- query_str = 'str=%BE%BE%B9%BE'
- update_env(
- 'REQUEST_METHOD' => 'POST',
- 'CONTENT_LENGTH' => query_str.length.to_s,
- 'SERVER_SOFTWARE' => 'Apache 2.2.0',
- 'SERVER_PROTOCOL' => 'HTTP/1.1',
- )
- $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".dup.force_encoding("UTF-8"), cgi['str'])
- ## cgi.params
- assert_equal(["\xBE\xBE\xB9\xBE".dup.force_encoding("UTF-8")], cgi.params['str'])
- ## accept-charset error
- assert_equal({"str"=>"\xBE\xBE\xB9\xBE".dup.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".dup.force_encoding("EUC-JP"), cgi['str'])
- ## cgi.params
- assert_equal(["\xBE\xBE\xB9\xBE".dup.force_encoding("EUC-JP")], cgi.params['str'])
- else
- assert(true)
- end
- ensure
- $stdin = STDIN
- end
-
-
- def test_cgi_core_cookie
- update_env(
- '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',
- )
- 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
- update_env(
- 'REQUEST_METHOD' => 'POST',
- 'CONTENT_LENGTH' => (64 * 1024 * 1024).to_s
- )
- 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
- update_env(
- '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',
- )
- 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
- update_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
- update_env(
- 'REQUEST_METHOD' => 'GET',
- )
- 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
- update_env(
- 'REQUEST_METHOD' => 'GET',
- )
- 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|
- update_env(name => "**#{name}**")
- end
- list1.each do |name|
- method = name.sub(/\AHTTP_/, '').downcase
- actual = cgi.__send__ method
- expected = "**#{name}**"
- assert_equal(expected, actual)
- end
- ## integer expected
- update_env('CONTENT_LENGTH' => '123')
- update_env('SERVER_PORT' => '8080')
- assert_equal(123, cgi.content_length)
- assert_equal(8080, cgi.server_port)
- ## raw cookie
- update_env('HTTP_COOKIE' => 'name1=val1')
- update_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
- update_env(
- 'REQUEST_METHOD' => 'GET',
- )
- ## 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 = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
- assert_equal(expected, cgi.doctype)
- assert_equal("Content-Type: text/html\r\n\r\n",cgi.header)
- ## html4
- cgi = CGI.new('html4')
- expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
- assert_equal(expected, cgi.doctype)
- assert_equal("Content-Type: text/html\r\n\r\n",cgi.header)
- ## html4 transitional
- cgi = CGI.new('html4Tr')
- expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
- assert_equal(expected, cgi.doctype)
- assert_equal("Content-Type: text/html\r\n\r\n",cgi.header)
- ## html4 frameset
- cgi = CGI.new('html4Fr')
- expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
- assert_equal(expected, cgi.doctype)
- assert_equal("Content-Type: text/html\r\n\r\n",cgi.header)
- ## html5
- cgi = CGI.new('html5')
- expected = '<!DOCTYPE HTML>'
- assert_equal(expected, cgi.doctype)
- assert_match(/^<HEADER><\/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/test/cgi/test_cgi_header.rb b/test/cgi/test_cgi_header.rb
deleted file mode 100644
index ec2f4deb72..0000000000
--- a/test/cgi/test_cgi_header.rb
+++ /dev/null
@@ -1,192 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-require 'cgi'
-require 'time'
-require_relative 'update_env'
-
-
-class CGIHeaderTest < Test::Unit::TestCase
- include UpdateEnv
-
-
- def setup
- @environ = {}
- update_env(
- 'SERVER_PROTOCOL' => 'HTTP/1.1',
- 'REQUEST_METHOD' => 'GET',
- 'SERVER_SOFTWARE' => 'Apache 2.2.0',
- )
- end
-
-
- def teardown
- ENV.update(@environ)
- 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".dup
- 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".dup
- 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_include(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".dup
- 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".dup
- expected << "\r\n"
- assert_equal(expected, actual4)
- expected = "Status: 302 Found\r\n".dup
- 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
-
-
- def test_cgi_http_header_crlf_injection
- cgi = CGI.new
- assert_raise(RuntimeError) { cgi.http_header("text/xhtml\r\nBOO") }
- assert_raise(RuntimeError) { cgi.http_header("type" => "text/xhtml\r\nBOO") }
- assert_raise(RuntimeError) { cgi.http_header("status" => "200 OK\r\nBOO") }
- assert_raise(RuntimeError) { cgi.http_header("location" => "text/xhtml\r\nBOO") }
- end
-
-
- instance_methods.each do |method|
- private method if method =~ /^test_(.*)/ && $1 != ENV['TEST']
- end if ENV['TEST']
-
-end
diff --git a/test/cgi/test_cgi_modruby.rb b/test/cgi/test_cgi_modruby.rb
deleted file mode 100644
index 90132962b5..0000000000
--- a/test/cgi/test_cgi_modruby.rb
+++ /dev/null
@@ -1,149 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-require 'cgi'
-require_relative 'update_env'
-
-
-class CGIModrubyTest < Test::Unit::TestCase
- include UpdateEnv
-
-
- def setup
- @environ = {}
- update_env(
- 'SERVER_PROTOCOL' => 'HTTP/1.1',
- 'REQUEST_METHOD' => 'GET',
- #'QUERY_STRING' => 'a=foo&b=bar',
- )
- CGI.class_eval { const_set(:MOD_RUBY, true) }
- Apache._reset()
- #@cgi = CGI.new
- #@req = Apache.request
- end
-
-
- def teardown
- ENV.update(@environ)
- 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/test/cgi/test_cgi_multipart.rb b/test/cgi/test_cgi_multipart.rb
deleted file mode 100644
index 5e8ec25390..0000000000
--- a/test/cgi/test_cgi_multipart.rb
+++ /dev/null
@@ -1,385 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-require 'cgi'
-require 'tempfile'
-require 'stringio'
-require_relative 'update_env'
-
-
-##
-## 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"
-## # "<html>\n"
-## # "<body><p>Hello</p></body>\n"
-## # "</html>\n"
-## # "\r\n"
-## # "--foobar1234--\r\n"
-##
-class MultiPart
-
- def initialize(boundary=nil)
- @boundary = boundary || create_boundary()
- @buf = ''.dup
- @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"
- buf << value.b
- buf << "\r\n"
- return self
- end
-
- def close
- buf = @buf
- @buf = ''.dup
- 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
- include UpdateEnv
-
-
- def setup
- @environ = {}
- update_env(
- 'REQUEST_METHOD' => 'POST',
- 'CONTENT_TYPE' => nil,
- 'CONTENT_LENGTH' => nil,
- )
- @tempfiles = []
- end
-
- def teardown
- ENV.update(@environ)
- $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".dup},
- {: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".dup},
- {: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".dup},
- {: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.gsub(/\n/, "\r\n")
---foobar1234
-Content-Disposition: form-data: name=\"name1\"
-
-value1
---foobar1234
-Content-Disposition: form-data: name=\"file1\"; filename=\"file1.html\"
-Content-Type: text/html
-
-<html>
-<body><p>Hello</p></body>
-</html>
-
---foobar1234--
-BODY
- 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/test/cgi/test_cgi_session.rb b/test/cgi/test_cgi_session.rb
deleted file mode 100644
index 32b907d741..0000000000
--- a/test/cgi/test_cgi_session.rb
+++ /dev/null
@@ -1,169 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-require 'cgi'
-require 'cgi/session'
-require 'cgi/session/pstore'
-require 'stringio'
-require 'tmpdir'
-require_relative 'update_env'
-
-class CGISessionTest < Test::Unit::TestCase
- include UpdateEnv
-
- def setup
- @environ = {}
- @session_dir = Dir.mktmpdir(%w'session dir')
- end
-
- def teardown
- ENV.update(@environ)
- $stdout = STDOUT
- FileUtils.rm_rf(@session_dir)
- end
-
- def test_cgi_session_filestore
- update_env(
- '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]".dup
- value2.force_encoding("SJIS") if defined?(::Encoding)
- 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{""}
-
- update_env(
- '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',
- )
- 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
- update_env(
- '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]".dup
- value2.force_encoding("SJIS") if defined?(::Encoding)
- 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{""}
-
- update_env(
- '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',
- )
- 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 if defined?(::PStore)
- def test_cgi_session_specify_session_id
- update_env(
- '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]".dup
- value2.force_encoding("SJIS") if defined?(::Encoding)
- 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{""}
-
- update_env(
- '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',
- )
- 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
- update_env(
- '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]".dup
- value2.force_encoding("SJIS") if defined?(::Encoding)
- 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{""}
-
- update_env(
- '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',
- )
- 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/test/cgi/test_cgi_tag_helper.rb b/test/cgi/test_cgi_tag_helper.rb
deleted file mode 100644
index 0b99dfc1bc..0000000000
--- a/test/cgi/test_cgi_tag_helper.rb
+++ /dev/null
@@ -1,355 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-require 'cgi'
-require 'stringio'
-require_relative 'update_env'
-
-
-class CGITagHelperTest < Test::Unit::TestCase
- include UpdateEnv
-
-
- def setup
- @environ = {}
- #@environ = {
- # 'SERVER_PROTOCOL' => 'HTTP/1.1',
- # 'REQUEST_METHOD' => 'GET',
- # 'SERVER_SOFTWARE' => 'Apache 2.2.0',
- #}
- #ENV.update(@environ)
- end
-
-
- def teardown
- ENV.update(@environ)
- $stdout = STDOUT
- end
-
-
- def test_cgi_tag_helper_html3
- update_env(
- 'REQUEST_METHOD' => 'GET',
- )
- ## html3
- cgi = CGI.new('html3')
- assert_equal('<A HREF=""></A>',cgi.a)
- assert_equal('<A HREF="bar"></A>',cgi.a('bar'))
- assert_equal('<A HREF="">foo</A>',cgi.a{'foo'})
- assert_equal('<A HREF="bar">foo</A>',cgi.a('bar'){'foo'})
- assert_equal('<TT></TT>',cgi.tt)
- assert_equal('<TT></TT>',cgi.tt('bar'))
- assert_equal('<TT>foo</TT>',cgi.tt{'foo'})
- assert_equal('<TT>foo</TT>',cgi.tt('bar'){'foo'})
- assert_equal('<I></I>',cgi.i)
- assert_equal('<I></I>',cgi.i('bar'))
- assert_equal('<I>foo</I>',cgi.i{'foo'})
- assert_equal('<I>foo</I>',cgi.i('bar'){'foo'})
- assert_equal('<B></B>',cgi.b)
- assert_equal('<B></B>',cgi.b('bar'))
- assert_equal('<B>foo</B>',cgi.b{'foo'})
- assert_equal('<B>foo</B>',cgi.b('bar'){'foo'})
- assert_equal('<U></U>',cgi.u)
- assert_equal('<U></U>',cgi.u('bar'))
- assert_equal('<U>foo</U>',cgi.u{'foo'})
- assert_equal('<U>foo</U>',cgi.u('bar'){'foo'})
- assert_equal('<STRIKE></STRIKE>',cgi.strike)
- assert_equal('<STRIKE></STRIKE>',cgi.strike('bar'))
- assert_equal('<STRIKE>foo</STRIKE>',cgi.strike{'foo'})
- assert_equal('<STRIKE>foo</STRIKE>',cgi.strike('bar'){'foo'})
- assert_equal('<BIG></BIG>',cgi.big)
- assert_equal('<BIG></BIG>',cgi.big('bar'))
- assert_equal('<BIG>foo</BIG>',cgi.big{'foo'})
- assert_equal('<BIG>foo</BIG>',cgi.big('bar'){'foo'})
- assert_equal('<SMALL></SMALL>',cgi.small)
- assert_equal('<SMALL></SMALL>',cgi.small('bar'))
- assert_equal('<SMALL>foo</SMALL>',cgi.small{'foo'})
- assert_equal('<SMALL>foo</SMALL>',cgi.small('bar'){'foo'})
- assert_equal('<SUB></SUB>',cgi.sub)
- assert_equal('<SUB></SUB>',cgi.sub('bar'))
- assert_equal('<SUB>foo</SUB>',cgi.sub{'foo'})
- assert_equal('<SUB>foo</SUB>',cgi.sub('bar'){'foo'})
- assert_equal('<SUP></SUP>',cgi.sup)
- assert_equal('<SUP></SUP>',cgi.sup('bar'))
- assert_equal('<SUP>foo</SUP>',cgi.sup{'foo'})
- assert_equal('<SUP>foo</SUP>',cgi.sup('bar'){'foo'})
- assert_equal('<EM></EM>',cgi.em)
- assert_equal('<EM></EM>',cgi.em('bar'))
- assert_equal('<EM>foo</EM>',cgi.em{'foo'})
- assert_equal('<EM>foo</EM>',cgi.em('bar'){'foo'})
- assert_equal('<STRONG></STRONG>',cgi.strong)
- assert_equal('<STRONG></STRONG>',cgi.strong('bar'))
- assert_equal('<STRONG>foo</STRONG>',cgi.strong{'foo'})
- assert_equal('<STRONG>foo</STRONG>',cgi.strong('bar'){'foo'})
- assert_equal('<DFN></DFN>',cgi.dfn)
- assert_equal('<DFN></DFN>',cgi.dfn('bar'))
- assert_equal('<DFN>foo</DFN>',cgi.dfn{'foo'})
- assert_equal('<DFN>foo</DFN>',cgi.dfn('bar'){'foo'})
- assert_equal('<CODE></CODE>',cgi.code)
- assert_equal('<CODE></CODE>',cgi.code('bar'))
- assert_equal('<CODE>foo</CODE>',cgi.code{'foo'})
- assert_equal('<CODE>foo</CODE>',cgi.code('bar'){'foo'})
- assert_equal('<SAMP></SAMP>',cgi.samp)
- assert_equal('<SAMP></SAMP>',cgi.samp('bar'))
- assert_equal('<SAMP>foo</SAMP>',cgi.samp{'foo'})
- assert_equal('<SAMP>foo</SAMP>',cgi.samp('bar'){'foo'})
- assert_equal('<KBD></KBD>',cgi.kbd)
- assert_equal('<KBD></KBD>',cgi.kbd('bar'))
- assert_equal('<KBD>foo</KBD>',cgi.kbd{'foo'})
- assert_equal('<KBD>foo</KBD>',cgi.kbd('bar'){'foo'})
- assert_equal('<VAR></VAR>',cgi.var)
- assert_equal('<VAR></VAR>',cgi.var('bar'))
- assert_equal('<VAR>foo</VAR>',cgi.var{'foo'})
- assert_equal('<VAR>foo</VAR>',cgi.var('bar'){'foo'})
- assert_equal('<CITE></CITE>',cgi.cite)
- assert_equal('<CITE></CITE>',cgi.cite('bar'))
- assert_equal('<CITE>foo</CITE>',cgi.cite{'foo'})
- assert_equal('<CITE>foo</CITE>',cgi.cite('bar'){'foo'})
- assert_equal('<FONT></FONT>',cgi.font)
- assert_equal('<FONT></FONT>',cgi.font('bar'))
- assert_equal('<FONT>foo</FONT>',cgi.font{'foo'})
- assert_equal('<FONT>foo</FONT>',cgi.font('bar'){'foo'})
- assert_equal('<ADDRESS></ADDRESS>',cgi.address)
- assert_equal('<ADDRESS></ADDRESS>',cgi.address('bar'))
- assert_equal('<ADDRESS>foo</ADDRESS>',cgi.address{'foo'})
- assert_equal('<ADDRESS>foo</ADDRESS>',cgi.address('bar'){'foo'})
- assert_equal('<DIV></DIV>',cgi.div)
- assert_equal('<DIV></DIV>',cgi.div('bar'))
- assert_equal('<DIV>foo</DIV>',cgi.div{'foo'})
- assert_equal('<DIV>foo</DIV>',cgi.div('bar'){'foo'})
- assert_equal('<CENTER></CENTER>',cgi.center)
- assert_equal('<CENTER></CENTER>',cgi.center('bar'))
- assert_equal('<CENTER>foo</CENTER>',cgi.center{'foo'})
- assert_equal('<CENTER>foo</CENTER>',cgi.center('bar'){'foo'})
- assert_equal('<MAP></MAP>',cgi.map)
- assert_equal('<MAP></MAP>',cgi.map('bar'))
- assert_equal('<MAP>foo</MAP>',cgi.map{'foo'})
- assert_equal('<MAP>foo</MAP>',cgi.map('bar'){'foo'})
- assert_equal('<APPLET></APPLET>',cgi.applet)
- assert_equal('<APPLET></APPLET>',cgi.applet('bar'))
- assert_equal('<APPLET>foo</APPLET>',cgi.applet{'foo'})
- assert_equal('<APPLET>foo</APPLET>',cgi.applet('bar'){'foo'})
- assert_equal('<PRE></PRE>',cgi.pre)
- assert_equal('<PRE></PRE>',cgi.pre('bar'))
- assert_equal('<PRE>foo</PRE>',cgi.pre{'foo'})
- assert_equal('<PRE>foo</PRE>',cgi.pre('bar'){'foo'})
- assert_equal('<XMP></XMP>',cgi.xmp)
- assert_equal('<XMP></XMP>',cgi.xmp('bar'))
- assert_equal('<XMP>foo</XMP>',cgi.xmp{'foo'})
- assert_equal('<XMP>foo</XMP>',cgi.xmp('bar'){'foo'})
- assert_equal('<LISTING></LISTING>',cgi.listing)
- assert_equal('<LISTING></LISTING>',cgi.listing('bar'))
- assert_equal('<LISTING>foo</LISTING>',cgi.listing{'foo'})
- assert_equal('<LISTING>foo</LISTING>',cgi.listing('bar'){'foo'})
- assert_equal('<DL></DL>',cgi.dl)
- assert_equal('<DL></DL>',cgi.dl('bar'))
- assert_equal('<DL>foo</DL>',cgi.dl{'foo'})
- assert_equal('<DL>foo</DL>',cgi.dl('bar'){'foo'})
- assert_equal('<OL></OL>',cgi.ol)
- assert_equal('<OL></OL>',cgi.ol('bar'))
- assert_equal('<OL>foo</OL>',cgi.ol{'foo'})
- assert_equal('<OL>foo</OL>',cgi.ol('bar'){'foo'})
- assert_equal('<UL></UL>',cgi.ul)
- assert_equal('<UL></UL>',cgi.ul('bar'))
- assert_equal('<UL>foo</UL>',cgi.ul{'foo'})
- assert_equal('<UL>foo</UL>',cgi.ul('bar'){'foo'})
- assert_equal('<DIR></DIR>',cgi.dir)
- assert_equal('<DIR></DIR>',cgi.dir('bar'))
- assert_equal('<DIR>foo</DIR>',cgi.dir{'foo'})
- assert_equal('<DIR>foo</DIR>',cgi.dir('bar'){'foo'})
- assert_equal('<MENU></MENU>',cgi.menu)
- assert_equal('<MENU></MENU>',cgi.menu('bar'))
- assert_equal('<MENU>foo</MENU>',cgi.menu{'foo'})
- assert_equal('<MENU>foo</MENU>',cgi.menu('bar'){'foo'})
- assert_equal('<SELECT></SELECT>',cgi.select)
- assert_equal('<SELECT></SELECT>',cgi.select('bar'))
- assert_equal('<SELECT>foo</SELECT>',cgi.select{'foo'})
- assert_equal('<SELECT>foo</SELECT>',cgi.select('bar'){'foo'})
- assert_equal('<TABLE></TABLE>',cgi.table)
- assert_equal('<TABLE></TABLE>',cgi.table('bar'))
- assert_equal('<TABLE>foo</TABLE>',cgi.table{'foo'})
- assert_equal('<TABLE>foo</TABLE>',cgi.table('bar'){'foo'})
- assert_equal('<TITLE></TITLE>',cgi.title)
- assert_equal('<TITLE></TITLE>',cgi.title('bar'))
- assert_equal('<TITLE>foo</TITLE>',cgi.title{'foo'})
- assert_equal('<TITLE>foo</TITLE>',cgi.title('bar'){'foo'})
- assert_equal('<STYLE></STYLE>',cgi.style)
- assert_equal('<STYLE></STYLE>',cgi.style('bar'))
- assert_equal('<STYLE>foo</STYLE>',cgi.style{'foo'})
- assert_equal('<STYLE>foo</STYLE>',cgi.style('bar'){'foo'})
- assert_equal('<SCRIPT></SCRIPT>',cgi.script)
- assert_equal('<SCRIPT></SCRIPT>',cgi.script('bar'))
- assert_equal('<SCRIPT>foo</SCRIPT>',cgi.script{'foo'})
- assert_equal('<SCRIPT>foo</SCRIPT>',cgi.script('bar'){'foo'})
- assert_equal('<H1></H1>',cgi.h1)
- assert_equal('<H1></H1>',cgi.h1('bar'))
- assert_equal('<H1>foo</H1>',cgi.h1{'foo'})
- assert_equal('<H1>foo</H1>',cgi.h1('bar'){'foo'})
- assert_equal('<H2></H2>',cgi.h2)
- assert_equal('<H2></H2>',cgi.h2('bar'))
- assert_equal('<H2>foo</H2>',cgi.h2{'foo'})
- assert_equal('<H2>foo</H2>',cgi.h2('bar'){'foo'})
- assert_equal('<H3></H3>',cgi.h3)
- assert_equal('<H3></H3>',cgi.h3('bar'))
- assert_equal('<H3>foo</H3>',cgi.h3{'foo'})
- assert_equal('<H3>foo</H3>',cgi.h3('bar'){'foo'})
- assert_equal('<H4></H4>',cgi.h4)
- assert_equal('<H4></H4>',cgi.h4('bar'))
- assert_equal('<H4>foo</H4>',cgi.h4{'foo'})
- assert_equal('<H4>foo</H4>',cgi.h4('bar'){'foo'})
- assert_equal('<H5></H5>',cgi.h5)
- assert_equal('<H5></H5>',cgi.h5('bar'))
- assert_equal('<H5>foo</H5>',cgi.h5{'foo'})
- assert_equal('<H5>foo</H5>',cgi.h5('bar'){'foo'})
- assert_equal('<H6></H6>',cgi.h6)
- assert_equal('<H6></H6>',cgi.h6('bar'))
- assert_equal('<H6>foo</H6>',cgi.h6{'foo'})
- assert_equal('<H6>foo</H6>',cgi.h6('bar'){'foo'})
- assert_match(/^<TEXTAREA .*><\/TEXTAREA>$/,cgi.textarea)
- assert_match(/COLS="70"/,cgi.textarea)
- assert_match(/ROWS="10"/,cgi.textarea)
- assert_match(/NAME=""/,cgi.textarea)
- assert_match(/^<TEXTAREA .*><\/TEXTAREA>$/,cgi.textarea("bar"))
- assert_match(/COLS="70"/,cgi.textarea("bar"))
- assert_match(/ROWS="10"/,cgi.textarea("bar"))
- assert_match(/NAME="bar"/,cgi.textarea("bar"))
- assert_match(/^<TEXTAREA .*>foo<\/TEXTAREA>$/,cgi.textarea{"foo"})
- assert_match(/COLS="70"/,cgi.textarea{"foo"})
- assert_match(/ROWS="10"/,cgi.textarea{"foo"})
- assert_match(/NAME=""/,cgi.textarea{"foo"})
- assert_match(/^<TEXTAREA .*>foo<\/TEXTAREA>$/,cgi.textarea("bar"){"foo"})
- assert_match(/COLS="70"/,cgi.textarea("bar"){"foo"})
- assert_match(/ROWS="10"/,cgi.textarea("bar"){"foo"})
- assert_match(/NAME="bar"/,cgi.textarea("bar"){"foo"})
- assert_match(/^<FORM .*><\/FORM>$/,cgi.form)
- assert_match(/METHOD="post"/,cgi.form)
- assert_match(/ENCTYPE="application\/x-www-form-urlencoded"/,cgi.form)
- assert_match(/^<FORM .*><\/FORM>$/,cgi.form("bar"))
- assert_match(/METHOD="bar"/,cgi.form("bar"))
- assert_match(/ENCTYPE="application\/x-www-form-urlencoded"/,cgi.form("bar"))
- assert_match(/^<FORM .*>foo<\/FORM>$/,cgi.form{"foo"})
- assert_match(/METHOD="post"/,cgi.form{"foo"})
- assert_match(/ENCTYPE="application\/x-www-form-urlencoded"/,cgi.form{"foo"})
- assert_match(/^<FORM .*>foo<\/FORM>$/,cgi.form("bar"){"foo"})
- assert_match(/METHOD="bar"/,cgi.form("bar"){"foo"})
- assert_match(/ENCTYPE="application\/x-www-form-urlencoded"/,cgi.form("bar"){"foo"})
- assert_equal('<BLOCKQUOTE></BLOCKQUOTE>',cgi.blockquote)
- assert_equal('<BLOCKQUOTE CITE="bar"></BLOCKQUOTE>',cgi.blockquote('bar'))
- assert_equal('<BLOCKQUOTE>foo</BLOCKQUOTE>',cgi.blockquote{'foo'})
- assert_equal('<BLOCKQUOTE CITE="bar">foo</BLOCKQUOTE>',cgi.blockquote('bar'){'foo'})
- assert_equal('<CAPTION></CAPTION>',cgi.caption)
- assert_equal('<CAPTION ALIGN="bar"></CAPTION>',cgi.caption('bar'))
- assert_equal('<CAPTION>foo</CAPTION>',cgi.caption{'foo'})
- assert_equal('<CAPTION ALIGN="bar">foo</CAPTION>',cgi.caption('bar'){'foo'})
- assert_equal('<IMG SRC="" ALT="">',cgi.img)
- assert_equal('<IMG SRC="bar" ALT="">',cgi.img('bar'))
- assert_equal('<IMG SRC="" ALT="">',cgi.img{'foo'})
- assert_equal('<IMG SRC="bar" ALT="">',cgi.img('bar'){'foo'})
- assert_equal('<BASE HREF="">',cgi.base)
- assert_equal('<BASE HREF="bar">',cgi.base('bar'))
- assert_equal('<BASE HREF="">',cgi.base{'foo'})
- assert_equal('<BASE HREF="bar">',cgi.base('bar'){'foo'})
- assert_equal('<BASEFONT>',cgi.basefont)
- assert_equal('<BASEFONT>',cgi.basefont('bar'))
- assert_equal('<BASEFONT>',cgi.basefont{'foo'})
- assert_equal('<BASEFONT>',cgi.basefont('bar'){'foo'})
- assert_equal('<BR>',cgi.br)
- assert_equal('<BR>',cgi.br('bar'))
- assert_equal('<BR>',cgi.br{'foo'})
- assert_equal('<BR>',cgi.br('bar'){'foo'})
- assert_equal('<AREA>',cgi.area)
- assert_equal('<AREA>',cgi.area('bar'))
- assert_equal('<AREA>',cgi.area{'foo'})
- assert_equal('<AREA>',cgi.area('bar'){'foo'})
- assert_equal('<LINK>',cgi.link)
- assert_equal('<LINK>',cgi.link('bar'))
- assert_equal('<LINK>',cgi.link{'foo'})
- assert_equal('<LINK>',cgi.link('bar'){'foo'})
- assert_equal('<PARAM>',cgi.param)
- assert_equal('<PARAM>',cgi.param('bar'))
- assert_equal('<PARAM>',cgi.param{'foo'})
- assert_equal('<PARAM>',cgi.param('bar'){'foo'})
- assert_equal('<HR>',cgi.hr)
- assert_equal('<HR>',cgi.hr('bar'))
- assert_equal('<HR>',cgi.hr{'foo'})
- assert_equal('<HR>',cgi.hr('bar'){'foo'})
- assert_equal('<INPUT>',cgi.input)
- assert_equal('<INPUT>',cgi.input('bar'))
- assert_equal('<INPUT>',cgi.input{'foo'})
- assert_equal('<INPUT>',cgi.input('bar'){'foo'})
- assert_equal('<ISINDEX>',cgi.isindex)
- assert_equal('<ISINDEX>',cgi.isindex('bar'))
- assert_equal('<ISINDEX>',cgi.isindex{'foo'})
- assert_equal('<ISINDEX>',cgi.isindex('bar'){'foo'})
- assert_equal('<META>',cgi.meta)
- assert_equal('<META>',cgi.meta('bar'))
- assert_equal('<META>',cgi.meta{'foo'})
- assert_equal('<META>',cgi.meta('bar'){'foo'})
- assert_equal('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML>',cgi.html)
- assert_equal('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML>foo</HTML>',cgi.html{'foo'})
- assert_equal('<HEAD>',cgi.head)
- assert_equal('<HEAD>foo</HEAD>',cgi.head{'foo'})
- assert_equal('<BODY>',cgi.body)
- assert_equal('<BODY>foo</BODY>',cgi.body{'foo'})
- assert_equal('<P>',cgi.p)
- assert_equal('<P>foo</P>',cgi.p{'foo'})
- assert_equal('<PLAINTEXT>',cgi.plaintext)
- assert_equal('<PLAINTEXT>foo</PLAINTEXT>',cgi.plaintext{'foo'})
- assert_equal('<DT>',cgi.dt)
- assert_equal('<DT>foo</DT>',cgi.dt{'foo'})
- assert_equal('<DD>',cgi.dd)
- assert_equal('<DD>foo</DD>',cgi.dd{'foo'})
- assert_equal('<LI>',cgi.li)
- assert_equal('<LI>foo</LI>',cgi.li{'foo'})
- assert_equal('<OPTION>',cgi.option)
- assert_equal('<OPTION>foo</OPTION>',cgi.option{'foo'})
- assert_equal('<TR>',cgi.tr)
- assert_equal('<TR>foo</TR>',cgi.tr{'foo'})
- assert_equal('<TH>',cgi.th)
- assert_equal('<TH>foo</TH>',cgi.th{'foo'})
- assert_equal('<TD>',cgi.td)
- assert_equal('<TD>foo</TD>',cgi.td{'foo'})
- str=cgi.checkbox_group("foo",["aa","bb"],["cc","dd"])
- assert_match(/^<INPUT .*VALUE="aa".*>bb<INPUT .*VALUE="cc".*>dd$/,str)
- assert_match(/^<INPUT .*TYPE="checkbox".*>bb<INPUT .*TYPE="checkbox".*>dd$/,str)
- assert_match(/^<INPUT .*NAME="foo".*>bb<INPUT .*NAME="foo".*>dd$/,str)
- str=cgi.radio_group("foo",["aa","bb"],["cc","dd"])
- assert_match(/^<INPUT .*VALUE="aa".*>bb<INPUT .*VALUE="cc".*>dd$/,str)
- assert_match(/^<INPUT .*TYPE="radio".*>bb<INPUT .*TYPE="radio".*>dd$/,str)
- assert_match(/^<INPUT .*NAME="foo".*>bb<INPUT .*NAME="foo".*>dd$/,str)
- str=cgi.checkbox_group("foo",["aa","bb"],["cc","dd",true])
- assert_match(/^<INPUT .*VALUE="aa".*>bb<INPUT .*VALUE="cc".*>dd$/,str)
- assert_match(/^<INPUT .*TYPE="checkbox".*>bb<INPUT .*TYPE="checkbox".*>dd$/,str)
- assert_match(/^<INPUT .*NAME="foo".*>bb<INPUT .*NAME="foo".*>dd$/,str)
- assert_match(/^<INPUT .*>bb<INPUT .*CHECKED.*>dd$/,str)
- assert_match(/<INPUT .*TYPE="text".*>/,cgi.text_field(:name=>"name",:value=>"value"))
- str=cgi.radio_group("foo",["aa","bb"],["cc","dd",false])
- assert_match(/^<INPUT .*VALUE="aa".*>bb<INPUT .*VALUE="cc".*>dd$/,str)
- assert_match(/^<INPUT .*TYPE="radio".*>bb<INPUT .*TYPE="radio".*>dd$/,str)
- assert_match(/^<INPUT .*NAME="foo".*>bb<INPUT .*NAME="foo".*>dd$/,str)
- end
-
-=begin
- def test_cgi_tag_helper_html4
- ## html4
- cgi = CGI.new('html4')
- ## html4 transitional
- cgi = CGI.new('html4Tr')
- ## html4 frameset
- cgi = CGI.new('html4Fr')
- end
-=end
-
- def test_cgi_tag_helper_html5
- update_env(
- 'REQUEST_METHOD' => 'GET',
- )
- ## html5
- cgi = CGI.new('html5')
- assert_equal('<HEADER></HEADER>',cgi.header)
- assert_equal('<FOOTER></FOOTER>',cgi.footer)
- assert_equal('<ARTICLE></ARTICLE>',cgi.article)
- assert_equal('<SECTION></SECTION>',cgi.section)
- assert_equal('<!DOCTYPE HTML><HTML BLA="TEST"></HTML>',cgi.html("BLA"=>"TEST"){})
- end
-
-end
diff --git a/test/cgi/test_cgi_util.rb b/test/cgi/test_cgi_util.rb
deleted file mode 100644
index 50f85e3967..0000000000
--- a/test/cgi/test_cgi_util.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-require 'cgi/util'
-
-class CGIUtilTest < Test::Unit::TestCase
-
- def test_cgi_pretty
- assert_equal("<HTML>\n <BODY>\n </BODY>\n</HTML>\n",CGI.pretty("<HTML><BODY></BODY></HTML>"))
- assert_equal("<HTML>\n\t<BODY>\n\t</BODY>\n</HTML>\n",CGI.pretty("<HTML><BODY></BODY></HTML>","\t"))
- end
-
-end
diff --git a/test/cgi/testdata/file1.html b/test/cgi/testdata/file1.html
deleted file mode 100644
index 2ceaf6bc39..0000000000
--- a/test/cgi/testdata/file1.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
- <head>
- <title>ムスカ大佐のひとりごと</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF8">
- </head>
- <body>
- <p>バカどもにはちょうどいい目くらましだ。</p>
- </body>
-</html>
diff --git a/test/cgi/testdata/large.png b/test/cgi/testdata/large.png
deleted file mode 100644
index d716396fa3..0000000000
--- a/test/cgi/testdata/large.png
+++ /dev/null
Binary files differ
diff --git a/test/cgi/testdata/small.png b/test/cgi/testdata/small.png
deleted file mode 100644
index 753d58e3cb..0000000000
--- a/test/cgi/testdata/small.png
+++ /dev/null
Binary files differ