Skip to content

Commit

Permalink
Action Controller support for PUT requests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rvowles committed Mar 29, 2021
1 parent 8aa97d0 commit 210dd68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/oauth/request_proxy/action_controller_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/units/test_action_controller_request_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 210dd68

Please sign in to comment.