From 6e1f58cb75a552ee8b99fafdf220537f193d51f6 Mon Sep 17 00:00:00 2001 From: laserlemon Date: Mon, 11 Oct 2010 16:26:34 -0400 Subject: [PATCH] Test the combination of HTTP method, URL and normalized parameters into the signature base string. --- test/simple_oauth_test.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/simple_oauth_test.rb b/test/simple_oauth_test.rb index 10c5228..b83f021 100644 --- a/test/simple_oauth_test.rb +++ b/test/simple_oauth_test.rb @@ -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