$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib') require 'socket' require 'ostruct' require 'test/unit' require 'nitro/cookie' require 'nitro/adapter/cgi' class TC_AdaptersCgi < Test::Unit::TestCase # :nodoc: all include Nitro def test_parse_query_parameters qs = 'name=tml;id=12354' params = CgiUtils.parse_query_string(qs) assert_equal 2, params.size assert_equal 'tml', params['name'] qs = '' params = CgiUtils.parse_query_string(qs) assert_equal 0, params.size qs = nil params = CgiUtils.parse_query_string(qs) assert_equal 0, params.size qs = 'name=tml;arr[]=1;arr[]=2;arr[]=3' params = CgiUtils.parse_query_string(qs) assert_equal 2, params.size arr = params['arr'] assert_equal Array, arr.class assert_equal 3, arr.size end def test_parse_cookies context = OpenStruct.new context.env = {} context.env['HTTP_COOKIE'] = 'nsid=123; nauth=gmosx:passwd' CgiUtils.parse_cookies(context) assert_equal 2, context.cookies.size assert_equal '123', context.cookies['nsid'] context.env = {} context.env['HTTP_COOKIE'] = 'nsid=123; nsid=23123' cookies = CgiUtils.parse_cookies(context) assert_equal 1, context.cookies.size assert_equal "123" + "\0" + "23123", context.cookies['nsid'] end def test_response_headers ctx = OpenStruct.new ctx.status = 200 ctx.response_cookies = { 'nsid' => Cookie.new('nsid', '1233'), 'nauth' => Cookie.new('nauth', 'gmosx') } ctx.response_headers = { 'Content-Type' => 'text/html' } res = "Status: 200 OK\r\nContent-Type: text/html\r\nSet-Cookie: nauthnauth=gmosx; Path=/\r\nSet-Cookie: nsidnsid=1233; Path=/\r\n\r\n" assert_equal res, CgiUtils.response_headers(ctx) end =begin def test_parse_multipart context = OpenStruct.new context.in = File.open(File.join(File.dirname(__FILE__), 'raw_post1.bin')) context.headers = { 'CONTENT_LENGTH' => 11963 } boundary = '---------------------------277124474474241471962886717' CgiUtils.parse_multipart(context, boundary) end =end end