Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action Controller support for PUT requests #181

Merged
merged 1 commit into from Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/oauth/request_proxy/action_controller_request.rb
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
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"]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I see what you mean, the original test looks wrong and this fixes it. LGTM.

assert_equal expected_parameters, request_proxy.parameters_for_signature
assert_equal 'PUT', request_proxy.method
end
Expand Down