From 98e23c185bb9c5f25eed25cd298e87c4d04cd908 Mon Sep 17 00:00:00 2001 From: laserlemon Date: Mon, 11 Oct 2010 16:18:45 -0400 Subject: [PATCH] Test the normalized request parameter string. --- test/simple_oauth_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/simple_oauth_test.rb b/test/simple_oauth_test.rb index 22238a8..10c5228 100644 --- a/test/simple_oauth_test.rb +++ b/test/simple_oauth_test.rb @@ -95,4 +95,23 @@ class SimpleOAuthTest < Test::Unit::TestCase assert_equal [:attribute, 'param', 'url_param', 'url_param'], signature_params.map(&:first) assert_equal ['ATTRIBUTE', 'PARAM', '1', '2'], signature_params.map(&:last) end + + def test_normalized_params + header = SimpleOAuth::Header.new(:get, 'https://api.twitter.com/statuses/friendships.json', {}) + header.stubs(:signature_params).returns([['A', '4'], ['B', '3'], ['B', '2'], ['C', '1'], ['D[]', '0 ']]) + + # The +normalized_params+ string should join key=value pairs with + # ampersands. + signature_params = header.send(:signature_params) + normalized_params = header.send(:normalized_params) + parts = normalized_params.split('&') + pairs = parts.map{|p| p.split('=') } + assert_kind_of String, normalized_params + assert_equal signature_params.size, parts.size + assert pairs.all?{|p| p.size == 2 } + + # The signature parameters should be sorted and the keys/values URL encoded + # first. + assert_equal signature_params.sort_by(&:to_s), pairs.map{|k,v| [URI.decode(k), URI.decode(v)] } + end end