[前][次][番号順一覧][スレッド一覧]

ruby-changes:37869

From: nobu <ko1@a...>
Date: Thu, 12 Mar 2015 23:58:14 +0900 (JST)
Subject: [ruby-changes:37869] nobu:r49950 (trunk): fix env leaks

nobu	2015-03-12 23:57:33 +0900 (Thu, 12 Mar 2015)

  New Revision: 49950

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49950

  Log:
    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.

  Added files:
    trunk/test/cgi/update_env.rb
  Modified files:
    trunk/lib/rubygems/test_case.rb
    trunk/test/cgi/test_cgi_cookie.rb
    trunk/test/cgi/test_cgi_core.rb
    trunk/test/cgi/test_cgi_header.rb
    trunk/test/cgi/test_cgi_modruby.rb
    trunk/test/cgi/test_cgi_multipart.rb
    trunk/test/cgi/test_cgi_session.rb
    trunk/test/cgi/test_cgi_tag_helper.rb
    trunk/test/cgi/test_cgi_util.rb
    trunk/test/rake/test_rake_application_options.rb
    trunk/test/rake/test_rake_file_utils.rb
    trunk/test/rubygems/test_gem_request.rb
Index: lib/rubygems/test_case.rb
===================================================================
--- lib/rubygems/test_case.rb	(revision 49949)
+++ lib/rubygems/test_case.rb	(revision 49950)
@@ -221,6 +221,9 @@ class Gem::TestCase < MiniTest::Unit::Te https://github.com/ruby/ruby/blob/trunk/lib/rubygems/test_case.rb#L221
     @orig_gem_home   = ENV['GEM_HOME']
     @orig_gem_path   = ENV['GEM_PATH']
     @orig_gem_vendor = ENV['GEM_VENDOR']
+    @orig_gem_spec_cache = ENV['GEM_SPEC_CACHE']
+    @orig_rubygems_gemdeps = ENV['RUBYGEMS_GEMDEPS']
+    @orig_rubygems_host = ENV['RUBYGEMS_HOST']
 
     ENV['GEM_VENDOR'] = nil
 
@@ -353,6 +356,9 @@ class Gem::TestCase < MiniTest::Unit::Te https://github.com/ruby/ruby/blob/trunk/lib/rubygems/test_case.rb#L356
     ENV['GEM_HOME']   = @orig_gem_home
     ENV['GEM_PATH']   = @orig_gem_path
     ENV['GEM_VENDOR'] = @orig_gem_vendor
+    ENV['GEM_SPEC_CACHE'] = @orig_gem_spec_cache
+    ENV['RUBYGEMS_GEMDEPS'] = @orig_rubygems_gemdeps
+    ENV['RUBYGEMS_HOST'] = @orig_rubygems_host
 
     Gem.ruby = @orig_ruby if @orig_ruby
 
Index: test/rake/test_rake_application_options.rb
===================================================================
--- test/rake/test_rake_application_options.rb	(revision 49949)
+++ test/rake/test_rake_application_options.rb	(revision 49950)
@@ -7,6 +7,7 @@ class TestRakeApplicationOptions < Rake: https://github.com/ruby/ruby/blob/trunk/test/rake/test_rake_application_options.rb#L7
   def setup
     super
 
+    @testkey = ENV['TESTKEY']
     clear_argv
     Rake::FileUtilsExt.verbose_flag = false
     Rake::FileUtilsExt.nowrite_flag = false
@@ -14,6 +15,7 @@ class TestRakeApplicationOptions < Rake: https://github.com/ruby/ruby/blob/trunk/test/rake/test_rake_application_options.rb#L15
   end
 
   def teardown
+    ENV['TESTKEY'] = @testkey
     clear_argv
     Rake::FileUtilsExt.verbose_flag = false
     Rake::FileUtilsExt.nowrite_flag = false
Index: test/rake/test_rake_file_utils.rb
===================================================================
--- test/rake/test_rake_file_utils.rb	(revision 49949)
+++ test/rake/test_rake_file_utils.rb	(revision 49950)
@@ -3,10 +3,15 @@ require 'fileutils' https://github.com/ruby/ruby/blob/trunk/test/rake/test_rake_file_utils.rb#L3
 require 'stringio'
 
 class TestRakeFileUtils < Rake::TestCase
+  def setup
+    super
+    @rake_test_sh = ENV['RAKE_TEST_SH']
+  end
 
   def teardown
     FileUtils::LN_SUPPORTED[0] = true
     RakeFileUtils.verbose_flag = Rake::FileUtilsExt::DEFAULT
+    ENV['RAKE_TEST_SH'] = @rake_test_sh
 
     super
   end
Index: test/rubygems/test_gem_request.rb
===================================================================
--- test/rubygems/test_gem_request.rb	(revision 49949)
+++ test/rubygems/test_gem_request.rb	(revision 49950)
@@ -16,7 +16,7 @@ class TestGemRequest < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request.rb#L16
   end
 
   def setup
-    @proxies = %w[http_proxy HTTP_PROXY http_proxy_user HTTP_PROXY_USER http_proxy_pass HTTP_PROXY_PASS no_proxy NO_PROXY]
+    @proxies = %w[http_proxy https_proxy HTTP_PROXY http_proxy_user HTTP_PROXY_USER http_proxy_pass HTTP_PROXY_PASS no_proxy NO_PROXY]
     @old_proxies = @proxies.map {|k| ENV[k] }
     @proxies.each {|k| ENV[k] = nil }
 
Index: test/cgi/test_cgi_util.rb
===================================================================
--- test/cgi/test_cgi_util.rb	(revision 49949)
+++ test/cgi/test_cgi_util.rb	(revision 49950)
@@ -1,21 +1,25 @@ https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_util.rb#L1
 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
 
 
Index: test/cgi/test_cgi_modruby.rb
===================================================================
--- test/cgi/test_cgi_modruby.rb	(revision 49949)
+++ test/cgi/test_cgi_modruby.rb	(revision 49950)
@@ -1,17 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_modruby.rb#L1
 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::TestC https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_modruby.rb#L22
 
 
   def teardown
-    @environ.each do |key, val| ENV.delete(key) end
+    ENV.update(@environ)
     CGI.class_eval { remove_const(:MOD_RUBY) }
   end
 
Index: test/cgi/test_cgi_multipart.rb
===================================================================
--- test/cgi/test_cgi_multipart.rb	(revision 49949)
+++ test/cgi/test_cgi_multipart.rb	(revision 49950)
@@ -2,6 +2,7 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_multipart.rb#L2
 require 'cgi'
 require 'tempfile'
 require 'stringio'
+require_relative 'update_env'
 
 
 ##
@@ -104,16 +105,21 @@ end https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_multipart.rb#L105
 
 
 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|
Index: test/cgi/test_cgi_session.rb
===================================================================
--- test/cgi/test_cgi_session.rb	(revision 49949)
+++ test/cgi/test_cgi_session.rb	(revision 49950)
@@ -4,30 +4,33 @@ require 'cgi/session' https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_session.rb#L4
 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::TestC https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_session.rb#L41
     $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::TestC https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_session.rb#L57
 
   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::TestC https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_session.rb#L77
     $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::TestC https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_session.rb#L92
     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::TestC https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_session.rb#L114
     $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::TestC https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_session.rb#L130
     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::TestC https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_session.rb#L151
     $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
Index: test/cgi/test_cgi_core.rb
===================================================================
--- test/cgi/test_cgi_core.rb	(revision 49949)
+++ test/cgi/test_cgi_core.rb	(revision 49950)
@@ -1,12 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L1
 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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L17
     #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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L67
 
   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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L91
 
   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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L128
 
 
   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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L152
 
 
   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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L164
 
 
   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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L195
     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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L208
 
 
   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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L222
 
 
   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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L238
     # 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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_core.rb#L247
       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
Index: test/cgi/test_cgi_header.rb
===================================================================
--- test/cgi/test_cgi_header.rb	(revision 49949)
+++ test/cgi/test_cgi_header.rb	(revision 49950)
@@ -1,23 +1,25 @@ https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_header.rb#L1
 require 'test/unit'
 require 'cgi'
 require 'time'
+require_relative 'update_env'
 
 
 class CGIHeaderTest < Test::Unit::TestCase
+  inc (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]