2009-01-13 12:53:53 -05:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
2010-09-01 06:18:22 -04:00
|
|
|
require 'stringio'
|
2008-12-13 16:06:02 -05:00
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
class RequestTest < Test::Unit::TestCase
|
2008-12-13 16:06:02 -05:00
|
|
|
it 'responds to #user_agent' do
|
|
|
|
request = Sinatra::Request.new({'HTTP_USER_AGENT' => 'Test'})
|
2009-01-14 17:00:26 -05:00
|
|
|
assert request.respond_to?(:user_agent)
|
|
|
|
assert_equal 'Test', request.user_agent
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
2009-01-15 09:45:38 -05:00
|
|
|
|
|
|
|
it 'parses POST params when Content-Type is form-dataish' do
|
|
|
|
request = Sinatra::Request.new(
|
|
|
|
'REQUEST_METHOD' => 'PUT',
|
|
|
|
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
|
|
|
|
'rack.input' => StringIO.new('foo=bar')
|
|
|
|
)
|
|
|
|
assert_equal 'bar', request.params['foo']
|
|
|
|
end
|
2009-08-14 17:51:58 -04:00
|
|
|
|
|
|
|
it 'is secure when the url scheme is https' do
|
|
|
|
request = Sinatra::Request.new('rack.url_scheme' => 'https')
|
|
|
|
assert request.secure?
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not secure when the url scheme is http' do
|
|
|
|
request = Sinatra::Request.new('rack.url_scheme' => 'http')
|
|
|
|
assert !request.secure?
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'respects X-Forwarded-Proto header for proxied SSL' do
|
|
|
|
request = Sinatra::Request.new('HTTP_X_FORWARDED_PROTO' => 'https')
|
|
|
|
assert request.secure?
|
|
|
|
end
|
2010-09-01 06:12:36 -04:00
|
|
|
|
|
|
|
it 'is possible to marshal params' do
|
|
|
|
request = Sinatra::Request.new(
|
|
|
|
'REQUEST_METHOD' => 'PUT',
|
|
|
|
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
|
|
|
|
'rack.input' => StringIO.new('foo=bar')
|
|
|
|
)
|
|
|
|
params = Sinatra::Base.new.send(:indifferent_hash).replace(request.params)
|
|
|
|
dumped = Marshal.dump(request.params)
|
|
|
|
assert_equal 'bar', Marshal.load(dumped)['foo']
|
|
|
|
end
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|