mirror of
https://github.com/samsonjs/simple_oauth.git
synced 2026-04-27 14:57:45 +00:00
Test the combination of HTTP method, URL and normalized parameters into the signature base string.
This commit is contained in:
parent
98e23c185b
commit
6e1f58cb75
1 changed files with 19 additions and 1 deletions
|
|
@ -53,7 +53,7 @@ class SimpleOAuthTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_encode
|
def test_encode
|
||||||
# Non-word characters should be URL encoded...
|
# Non-word characters should be URL encoded...
|
||||||
[' ', '!', '@', '$', '%', '^', '&'].each do |character|
|
[' ', '!', '@', '#', '$', '%', '^', '&'].each do |character|
|
||||||
encoded = SimpleOAuth::Header.encode(character)
|
encoded = SimpleOAuth::Header.encode(character)
|
||||||
assert_not_equal character, encoded
|
assert_not_equal character, encoded
|
||||||
assert_equal URI.encode(character, /.*/), encoded
|
assert_equal URI.encode(character, /.*/), encoded
|
||||||
|
|
@ -114,4 +114,22 @@ class SimpleOAuthTest < Test::Unit::TestCase
|
||||||
# first.
|
# first.
|
||||||
assert_equal signature_params.sort_by(&:to_s), pairs.map{|k,v| [URI.decode(k), URI.decode(v)] }
|
assert_equal signature_params.sort_by(&:to_s), pairs.map{|k,v| [URI.decode(k), URI.decode(v)] }
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue