Sha256: ecc06e71d6dd3c769aeebcae3702274a7552fcfa8dc9ac9514f4e55165381275

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

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

require 'ostruct'
require 'test/unit'

require 'nitro/cookie'
require 'nitro/adaptors/cgi'

class TC_AdaptorsCgi < Test::Unit::TestCase # :nodoc: all
	include N
	
	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 = "HTTP/1.1 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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.9.3 test/nitro/adaptors/tc_cgi.rb
nitro-0.9.5 test/nitro/adaptors/tc_cgi.rb