Sha256: 1f2e59ad8e83fdeadaabc322fa7b75516a34feb39460724822190e860c5d8ebe

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')

require 'ostruct'
require 'test/unit'

require 'nitro/cookie'
require 'nitro/adapters/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\r\nSet-Cookie: nsidnsid=1233\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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.16.0 test/nitro/adapters/tc_cgi.rb