From 210dd686cedc0d568b51f46a31c3510d19db080c Mon Sep 17 00:00:00 2001 From: Richard Vowles Date: Fri, 5 Mar 2021 10:32:57 +1300 Subject: [PATCH] Action Controller support for PUT requests Most of the other request proxies support PUT requests and we need this gem to also support it for Action Controller. This addresses issue #180 It includes the modified Action Controller proxy and fixes the tests. --- lib/oauth/request_proxy/action_controller_request.rb | 6 +++++- test/units/test_action_controller_request_proxy.rb | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/oauth/request_proxy/action_controller_request.rb b/lib/oauth/request_proxy/action_controller_request.rb index 425deb8c..065279ee 100644 --- a/lib/oauth/request_proxy/action_controller_request.rb +++ b/lib/oauth/request_proxy/action_controller_request.rb @@ -60,7 +60,7 @@ def parameters_for_signature params << header_params.to_query params << request.query_string unless query_string_blank? - if request.post? && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded") + if raw_post_signature? params << request.raw_post end end @@ -72,6 +72,10 @@ def parameters_for_signature reject { |kv| kv[0] == 'oauth_signature'} end + def raw_post_signature? + (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded") + end + protected def query_params diff --git a/test/units/test_action_controller_request_proxy.rb b/test/units/test_action_controller_request_proxy.rb index a264a1b1..150ce78d 100644 --- a/test/units/test_action_controller_request_proxy.rb +++ b/test/units/test_action_controller_request_proxy.rb @@ -77,7 +77,7 @@ def test_that_proxy_simple_post_request_works_with_post_params def test_that_proxy_simple_put_request_works_with_post_params request_proxy = request_proxy(:put, {}, {'key'=>'value'}) - expected_parameters = [] + expected_parameters = [["key", "value"]] assert_equal expected_parameters, request_proxy.parameters_for_signature assert_equal 'PUT', request_proxy.method end @@ -109,7 +109,7 @@ def test_that_proxy_simple_post_request_works_with_mixed_params def test_that_proxy_simple_put_request_works_with_mixed_params request_proxy = request_proxy(:put, {'key'=>'value'}, {'key2'=>'value2'}) - expected_parameters = [["key", "value"]] + expected_parameters = [["key", "value"],["key2", "value2"]] assert_equal expected_parameters, request_proxy.parameters_for_signature assert_equal 'PUT', request_proxy.method end