Test the combination of HTTP method, URL and normalized parameters into the signature base string.

This commit is contained in:
laserlemon 2010-10-11 16:26:34 -04:00
parent 98e23c185b
commit 6e1f58cb75

View file

@ -53,7 +53,7 @@ class SimpleOAuthTest < Test::Unit::TestCase
def test_encode
# Non-word characters should be URL encoded...
[' ', '!', '@', '$', '%', '^', '&'].each do |character|
[' ', '!', '@', '#', '$', '%', '^', '&'].each do |character|
encoded = SimpleOAuth::Header.encode(character)
assert_not_equal character, encoded
assert_equal URI.encode(character, /.*/), encoded
@ -114,4 +114,22 @@ class SimpleOAuthTest < Test::Unit::TestCase
# first.
assert_equal signature_params.sort_by(&:to_s), pairs.map{|k,v| [URI.decode(k), URI.decode(v)] }
end
def test_signature_base
header = SimpleOAuth::Header.new(:get, 'https://api.twitter.com/statuses/friendships.json', {})
header.stubs(:method).returns('METHOD')
header.stubs(:url).returns('URL')
header.stubs(:normalized_params).returns('NORMALIZED_PARAMS')
# Should combine HTTP method, URL and normalized parameters string using
# ampersands.
assert_equal 'METHOD&URL&NORMALIZED_PARAMS', header.send(:signature_base)
header.stubs(:method).returns('ME#HOD')
header.stubs(:url).returns('U#L')
header.stubs(:normalized_params).returns('NORMAL#ZED_PARAMS')
# Each of the three combined values should be URL encoded.
assert_equal 'ME%23HOD&U%23L&NORMAL%23ZED_PARAMS', header.send(:signature_base)
end
end