summaryrefslogtreecommitdiff
path: root/test/cgi/test_cgi_session.rb
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/test_cgi_session.rb
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/test_cgi_session.rb')
-rw-r--r--test/cgi/test_cgi_session.rb46
1 files changed, 21 insertions, 25 deletions
diff --git a/test/cgi/test_cgi_session.rb b/test/cgi/test_cgi_session.rb
index 8bd51776ff2..c2d7bdc60dc 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