summaryrefslogtreecommitdiff
path: root/test/cgi/test_cgi_session.rb
diff options
context:
space:
mode:
authorxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-18 12:20:13 +0000
committerxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-18 12:20:13 +0000
commit52d481d8de7ee3e0dfaef7322d540f95223bf41b (patch)
treeb0cb61753544ded8deb73337bd4b6833bb8c1c40 /test/cgi/test_cgi_session.rb
parent88cab63a07aff9731026f7191d9c4263f7fe11b8 (diff)
* lib/cgi/session.rb: fix bug for ignore session_id option.
report from [ruby-core:18635], [Bug #572] * lib/cgi/core.rb: use Encoding#find when encoding set. * test/cgi/test_cgi_session.rb: test for session_id specified. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/cgi/test_cgi_session.rb')
-rw-r--r--test/cgi/test_cgi_session.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/cgi/test_cgi_session.rb b/test/cgi/test_cgi_session.rb
index 621674980e0..4fcb936d4e6 100644
--- a/test/cgi/test_cgi_session.rb
+++ b/test/cgi/test_cgi_session.rb
@@ -91,7 +91,83 @@ class CGISessionTest < Test::Unit::TestCase
assert_equal(value1,session["key1"])
assert_equal(value2,session["key2"])
session.close
+ end
+ def test_cgi_session_specify_session_id
+ @environ = {
+ 'REQUEST_METHOD' => 'GET',
+ # 'QUERY_STRING' => 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F',
+ # 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;',
+ 'SERVER_SOFTWARE' => 'Apache 2.2.0',
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
+ }
+ value1="value1"
+ value2="\x8F\xBC\x8D]"
+ value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
+ ENV.update(@environ)
+ cgi = CGI.new
+ session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_id"=>"foo")
+ session["key1"]=value1
+ session["key2"]=value2
+ assert_equal(value1,session["key1"])
+ assert_equal(value2,session["key2"])
+ assert_equal("foo",session.session_id)
+ session_id=session.session_id
+ session.close
+ $stdout = StringIO.new
+ cgi.out{""}
+ @environ = {
+ 'REQUEST_METHOD' => 'GET',
+ # 'HTTP_COOKIE' => "_session_id=#{session_id}",
+ 'QUERY_STRING' => "_session_id=#{session.session_id}",
+ 'SERVER_SOFTWARE' => 'Apache 2.2.0',
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
+ }
+ ENV.update(@environ)
+ cgi = CGI.new
+ session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
+ $stdout = StringIO.new
+ assert_equal(value1,session["key1"])
+ assert_equal(value2,session["key2"])
+ assert_equal("foo",session.session_id)
+ session.close
+ end
+ def test_cgi_session_specify_session_key
+ @environ = {
+ 'REQUEST_METHOD' => 'GET',
+ # 'QUERY_STRING' => 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F',
+ # 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;',
+ 'SERVER_SOFTWARE' => 'Apache 2.2.0',
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
+ }
+ value1="value1"
+ value2="\x8F\xBC\x8D]"
+ value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
+ ENV.update(@environ)
+ cgi = CGI.new
+ session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar")
+ session["key1"]=value1
+ session["key2"]=value2
+ assert_equal(value1,session["key1"])
+ assert_equal(value2,session["key2"])
+ session_id=session.session_id
+ session.close
+ $stdout = StringIO.new
+ cgi.out{""}
+ @environ = {
+ 'REQUEST_METHOD' => 'GET',
+ 'HTTP_COOKIE' => "bar=#{session_id}",
+ # 'QUERY_STRING' => "bar=#{session.session_id}",
+ 'SERVER_SOFTWARE' => 'Apache 2.2.0',
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
+ }
+ ENV.update(@environ)
+ cgi = CGI.new
+ session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar")
+ $stdout = StringIO.new
+ assert_equal(value1,session["key1"])
+ assert_equal(value2,session["key2"])
+ session.close
end
end