summaryrefslogtreecommitdiff
path: root/test/cgi
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-12 14:57:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-12 14:57:33 +0000
commit05c29680e515c000552008f725747261ffa6008d (patch)
tree4ad6c4c057ec68f3d7b396a8fa55022f45ee274c /test/cgi
parent31eb1938832eb3a3a69c7246db151c96b589b877 (diff)
fix env leaks
* lib/rubygems/test_case.rb (setup, teardown): fix environment variable change leaks. * test/cgi/update_env.rb: ditto. * test/rake/test_rake_application_options.rb (setup, teardown): ditto. * test/rake/test_rake_file_utils.rb (setup, teardown): ditto. * test/rubygems/test_gem_request.rb (setup): add https_proxy. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/cgi')
-rw-r--r--test/cgi/test_cgi_cookie.rb12
-rw-r--r--test/cgi/test_cgi_core.rb70
-rw-r--r--test/cgi/test_cgi_header.rb10
-rw-r--r--test/cgi/test_cgi_modruby.rb10
-rw-r--r--test/cgi/test_cgi_multipart.rb14
-rw-r--r--test/cgi/test_cgi_session.rb46
-rw-r--r--test/cgi/test_cgi_tag_helper.rb15
-rw-r--r--test/cgi/test_cgi_util.rb12
-rw-r--r--test/cgi/update_env.rb8
9 files changed, 105 insertions, 92 deletions
diff --git a/test/cgi/test_cgi_cookie.rb b/test/cgi/test_cgi_cookie.rb
index c1c6a30..eaf4ff1 100644
--- a/test/cgi/test_cgi_cookie.rb
+++ b/test/cgi/test_cgi_cookie.rb
@@ -1,21 +1,25 @@
require 'test/unit'
require 'cgi'
require 'stringio'
+require_relative 'update_env'
class CGICookieTest < Test::Unit::TestCase
+ include UpdateEnv
def setup
- ENV['REQUEST_METHOD'] = 'GET'
+ @environ = {}
+ update_env(
+ 'REQUEST_METHOD' => 'GET',
+ 'SCRIPT_NAME' => nil,
+ )
@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
+ ENV.update(@environ)
end
diff --git a/test/cgi/test_cgi_core.rb b/test/cgi/test_cgi_core.rb
index 274d088..68e008d 100644
--- a/test/cgi/test_cgi_core.rb
+++ b/test/cgi/test_cgi_core.rb
@@ -1,12 +1,14 @@
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',
@@ -15,35 +17,32 @@ class CGICoreTest < Test::Unit::TestCase
#ENV.update(@environ)
end
-
def teardown
- @environ.each do |key, val| ENV.delete(key) end
+ ENV.update(@environ)
$stdout = STDOUT
end
def test_cgi_parse_illegal_query
- @environ = {
+ 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',
- }
- 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 = {
+ 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',
- }
- ENV.update(@environ)
+ )
cgi = CGI.new
## cgi[]
assert_equal('123', cgi['id'])
@@ -68,14 +67,13 @@ class CGICoreTest < Test::Unit::TestCase
def test_cgi_core_params_POST
query_str = 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F'
- @environ = {
+ 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',
- }
- ENV.update(@environ)
+ )
$stdin = StringIO.new
$stdin << query_str
$stdin.rewind
@@ -93,13 +91,12 @@ class CGICoreTest < Test::Unit::TestCase
def test_cgi_core_params_encoding_check
query_str = 'str=%BE%BE%B9%BE'
- @environ = {
+ update_env(
'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
@@ -131,14 +128,13 @@ class CGICoreTest < Test::Unit::TestCase
def test_cgi_core_cookie
- @environ = {
+ 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',
- }
- ENV.update(@environ)
+ )
cgi = CGI.new
assert_not_equal(nil,cgi.cookies)
[ ['_session_id', ['12345'], ],
@@ -156,11 +152,10 @@ class CGICoreTest < Test::Unit::TestCase
def test_cgi_core_maxcontentlength
- @environ = {
+ update_env(
'REQUEST_METHOD' => 'POST',
'CONTENT_LENGTH' => (64 * 1024 * 1024).to_s
- }
- ENV.update(@environ)
+ )
ex = assert_raise(StandardError) do
CGI.new
end
@@ -169,14 +164,13 @@ class CGICoreTest < Test::Unit::TestCase
def test_cgi_core_out
- @environ = {
+ 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',
- }
- 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"
@@ -201,7 +195,7 @@ class CGICoreTest < Test::Unit::TestCase
cgi.out(options) { euc_str }
assert_equal('en', options['language'])
## HEAD method
- ENV['REQUEST_METHOD'] = 'HEAD'
+ update_env('REQUEST_METHOD' => 'HEAD')
options = { 'charset'=>'utf8' }
$stdout = StringIO.new
cgi.out(options) { euc_str }
@@ -214,10 +208,9 @@ class CGICoreTest < Test::Unit::TestCase
def test_cgi_core_print
- @environ = {
+ update_env(
'REQUEST_METHOD' => 'GET',
- }
- ENV.update(@environ)
+ )
cgi = CGI.new
$stdout = StringIO.new
str = "foobar"
@@ -229,10 +222,9 @@ class CGICoreTest < Test::Unit::TestCase
def test_cgi_core_environs
- @environ = {
+ update_env(
'REQUEST_METHOD' => 'GET',
- }
- ENV.update(@environ)
+ )
cgi = CGI.new
##
list1 = %w[ AUTH_TYPE CONTENT_TYPE GATEWAY_INTERFACE PATH_INFO
@@ -246,9 +238,8 @@ class CGICoreTest < Test::Unit::TestCase
# list2 = %w[ CONTENT_LENGTH SERVER_PORT ]
## string expected
list1.each do |name|
- @environ[name] = "**#{name}**"
+ update_env(name => "**#{name}**")
end
- ENV.update(@environ)
list1.each do |name|
method = name.sub(/\AHTTP_/, '').downcase
actual = cgi.__send__ method
@@ -256,23 +247,22 @@ class CGICoreTest < Test::Unit::TestCase
assert_equal(expected, actual)
end
## integer expected
- ENV['CONTENT_LENGTH'] = '123'
- ENV['SERVER_PORT'] = '8080'
+ update_env('CONTENT_LENGTH' => '123')
+ update_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'
+ 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
- @environ = {
+ update_env(
'REQUEST_METHOD' => 'GET',
- }
- ENV.update(@environ)
+ )
## no htmltype
cgi = CGI.new
assert_raise(NoMethodError) do cgi.doctype end
diff --git a/test/cgi/test_cgi_header.rb b/test/cgi/test_cgi_header.rb
index 9022301..91086c4 100644
--- a/test/cgi/test_cgi_header.rb
+++ b/test/cgi/test_cgi_header.rb
@@ -1,23 +1,25 @@
require 'test/unit'
require 'cgi'
require 'time'
+require_relative 'update_env'
class CGIHeaderTest < Test::Unit::TestCase
+ include UpdateEnv
def setup
- @environ = {
+ @environ = {}
+ update_env(
'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
+ ENV.update(@environ)
end
diff --git a/test/cgi/test_cgi_modruby.rb b/test/cgi/test_cgi_modruby.rb
index b0fc442..ed1d519 100644
--- a/test/cgi/test_cgi_modruby.rb
+++ b/test/cgi/test_cgi_modruby.rb
@@ -1,17 +1,19 @@
require 'test/unit'
require 'cgi'
+require_relative 'update_env'
class CGIModrubyTest < Test::Unit::TestCase
+ include UpdateEnv
def setup
- @environ = {
+ @environ = {}
+ update_env(
'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
@@ -20,7 +22,7 @@ class CGIModrubyTest < Test::Unit::TestCase
def teardown
- @environ.each do |key, val| ENV.delete(key) end
+ ENV.update(@environ)
CGI.class_eval { remove_const(:MOD_RUBY) }
end
diff --git a/test/cgi/test_cgi_multipart.rb b/test/cgi/test_cgi_multipart.rb
index 1325798..989c054 100644
--- a/test/cgi/test_cgi_multipart.rb
+++ b/test/cgi/test_cgi_multipart.rb
@@ -2,6 +2,7 @@ require 'test/unit'
require 'cgi'
require 'tempfile'
require 'stringio'
+require_relative 'update_env'
##
@@ -104,16 +105,21 @@ end
class CGIMultipartTest < Test::Unit::TestCase
+ include UpdateEnv
+
def setup
- ENV['REQUEST_METHOD'] = 'POST'
+ @environ = {}
+ update_env(
+ 'REQUEST_METHOD' => 'POST',
+ 'CONTENT_TYPE' => nil,
+ 'CONTENT_LENGTH' => nil,
+ )
@tempfiles = []
end
def teardown
- %w[ REQUEST_METHOD CONTENT_TYPE CONTENT_LENGTH REQUEST_METHOD ].each do |name|
- ENV.delete(name)
- end
+ ENV.update(@environ)
$stdin.close() if $stdin.is_a?(Tempfile)
$stdin = STDIN
@tempfiles.each {|t|
diff --git a/test/cgi/test_cgi_session.rb b/test/cgi/test_cgi_session.rb
index 8bd5177..c2d7bdc 100644
--- a/test/cgi/test_cgi_session.rb
+++ b/test/cgi/test_cgi_session.rb
@@ -4,30 +4,33 @@ 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
- @environ.each do |key, val| ENV.delete(key) end
+ ENV.update(@environ)
$stdout = STDOUT
FileUtils.rm_rf(@session_dir)
end
def test_cgi_session_filestore
- @environ = {
+ 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]"
value2.force_encoding("SJIS") if defined?(::Encoding)
- ENV.update(@environ)
cgi = CGI.new
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
session["key1"]=value1
@@ -38,14 +41,13 @@ class CGISessionTest < Test::Unit::TestCase
$stdout = StringIO.new
cgi.out{""}
- @environ = {
+ 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',
- }
- ENV.update(@environ)
+ )
cgi = CGI.new
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
$stdout = StringIO.new
@@ -55,17 +57,16 @@ class CGISessionTest < Test::Unit::TestCase
end
def test_cgi_session_pstore
- @environ = {
+ 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]"
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
@@ -76,14 +77,13 @@ class CGISessionTest < Test::Unit::TestCase
$stdout = StringIO.new
cgi.out{""}
- @environ = {
+ 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',
- }
- ENV.update(@environ)
+ )
cgi = CGI.new
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"database_manager"=>CGI::Session::PStore)
$stdout = StringIO.new
@@ -92,17 +92,16 @@ class CGISessionTest < Test::Unit::TestCase
session.close
end
def test_cgi_session_specify_session_id
- @environ = {
+ 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]"
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
@@ -115,14 +114,13 @@ class CGISessionTest < Test::Unit::TestCase
$stdout = StringIO.new
cgi.out{""}
- @environ = {
+ 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',
- }
- ENV.update(@environ)
+ )
cgi = CGI.new
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
$stdout = StringIO.new
@@ -132,17 +130,16 @@ class CGISessionTest < Test::Unit::TestCase
session.close
end
def test_cgi_session_specify_session_key
- @environ = {
+ 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]"
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
@@ -154,14 +151,13 @@ class CGISessionTest < Test::Unit::TestCase
$stdout = StringIO.new
cgi.out{""}
- @environ = {
+ 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',
- }
- ENV.update(@environ)
+ )
cgi = CGI.new
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar")
$stdout = StringIO.new
diff --git a/test/cgi/test_cgi_tag_helper.rb b/test/cgi/test_cgi_tag_helper.rb
index eb3c20a..cc119cb 100644
--- a/test/cgi/test_cgi_tag_helper.rb
+++ b/test/cgi/test_cgi_tag_helper.rb
@@ -1,12 +1,15 @@
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',
@@ -17,16 +20,15 @@ class CGITagHelperTest < Test::Unit::TestCase
def teardown
- @environ.each do |key, val| ENV.delete(key) end
+ ENV.update(@environ)
$stdout = STDOUT
end
def test_cgi_tag_helper_html3
- @environ = {
+ update_env(
'REQUEST_METHOD' => 'GET',
- }
- ENV.update(@environ)
+ )
## html3
cgi = CGI.new('html3')
assert_equal('<A HREF=""></A>',cgi.a)
@@ -337,10 +339,9 @@ class CGITagHelperTest < Test::Unit::TestCase
=end
def test_cgi_tag_helper_html5
- @environ = {
+ update_env(
'REQUEST_METHOD' => 'GET',
- }
- ENV.update(@environ)
+ )
## html5
cgi = CGI.new('html5')
assert_equal('<HEADER></HEADER>',cgi.header)
diff --git a/test/cgi/test_cgi_util.rb b/test/cgi/test_cgi_util.rb
index 802379d..2c5182b 100644
--- a/test/cgi/test_cgi_util.rb
+++ b/test/cgi/test_cgi_util.rb
@@ -1,21 +1,25 @@
require 'test/unit'
require 'cgi'
require 'stringio'
+require_relative 'update_env'
class CGIUtilTest < Test::Unit::TestCase
include CGI::Util
+ include UpdateEnv
def setup
- ENV['REQUEST_METHOD'] = 'GET'
+ @environ = {}
+ update_env(
+ 'REQUEST_METHOD' => 'GET',
+ 'SCRIPT_NAME' => nil,
+ )
@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
+ ENV.update(@environ)
end
diff --git a/test/cgi/update_env.rb b/test/cgi/update_env.rb
new file mode 100644
index 0000000..0cd926d
--- /dev/null
+++ b/test/cgi/update_env.rb
@@ -0,0 +1,8 @@
+module UpdateEnv
+ def update_env(environ)
+ environ.each do |key, val|
+ @environ[key] = ENV[key] unless @environ.key?(key)
+ ENV[key] = val
+ end
+ end
+end