mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
f2077294f1
* lib/rubygems/validator.rb: ditto * test/cgi/test_cgi_modruby.rb: ditto * test/cgi/test_cgi_multipart.rb: ditto * test/cgi/test_cgi_session.rb: ditto: ditto * test/cgi/testdata/file1.html: ditto * test/cgi/testdata/small.png: ditto * test/cgi/testdata/large.png: ditto * test/cgi/test_cgi_core.rb: ditto * test/cgi/test_cgi_header.rb: ditto * test/cgi/test_cgi_cookie.rb: ditto * test/cgi/test_cgi_tag_helper.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
98 lines
3 KiB
Ruby
98 lines
3 KiB
Ruby
require 'test/unit'
|
|
require 'cgi'
|
|
require 'cgi/session'
|
|
require 'cgi/session/pstore'
|
|
require 'stringio'
|
|
|
|
class CGISessionTest < Test::Unit::TestCase
|
|
|
|
|
|
def setup
|
|
FileUtils.rm(Dir::glob(File.dirname(__FILE__)+"/session_dir/*"))
|
|
end
|
|
|
|
|
|
def teardown
|
|
@environ.each do |key, val| ENV.delete(key) end
|
|
$stdout = STDOUT
|
|
# FileUtils.rm(Dir::glob(File.dirname(__FILE__)+"/session_dir/*"))
|
|
end
|
|
|
|
def test_cgi_session_filestore
|
|
@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"=>File.dirname(__FILE__)+"/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{""}
|
|
|
|
@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"=>File.dirname(__FILE__)+"/session_dir")
|
|
$stdout = StringIO.new
|
|
assert_equal(value1,session["key1"])
|
|
assert_equal(value2,session["key2"])
|
|
session.close
|
|
|
|
end
|
|
def test_cgi_session_pstore
|
|
@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"=>File.dirname(__FILE__)+"/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{""}
|
|
|
|
@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"=>File.dirname(__FILE__)+"/session_dir","database_manager"=>CGI::Session::PStore)
|
|
$stdout = StringIO.new
|
|
assert_equal(value1,session["key1"])
|
|
assert_equal(value2,session["key2"])
|
|
session.close
|
|
|
|
|
|
end
|
|
end
|