Skip to content

Commit 11925d6

Browse files
committed
fix deleting array content when passing an array as payload
1 parent 45cef15 commit 11925d6

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/auth0/mixins/httpproxy.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module HTTPProxy
1818
# proxying requests from instance methods to HTTP class methods
1919
%i(get post post_file post_form put patch delete delete_with_body).each do |method|
2020
define_method(method) do |uri, body = {}, extra_headers = {}|
21-
body = body.delete_if { |_, v| v.nil? }
21+
# body = body.delete_if { |_, v| v.nil? }
22+
body = body.dup.delete_if { |_, v| v.nil? } if body.is_a?(Hash)
2223
token = get_token()
2324
authorization_header(token) unless token.nil?
2425
request_with_retry(method, uri, body, extra_headers)

spec/lib/auth0/mixins/httpproxy_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ def expected_payload(method, overrides = {})
279279
expect { @instance.send(http_method, '/test') }.not_to raise_error
280280
end
281281

282+
it "should handle array parameters for #{http_method} method" do
283+
array_data = ['param1', 'param2']
284+
if http_method == :post_form
285+
expected_params = expected_payload(http_method, { payload: array_data })
286+
else
287+
expected_params = expected_payload(http_method, { payload: array_data.to_json })
288+
end
289+
290+
expect(RestClient::Request).to receive(:execute).with(expected_params)
291+
.and_return(StubResponse.new({}, true, 200))
292+
expect { @instance.send(http_method, '/test', array_data) }.not_to raise_error
293+
end
294+
282295
it 'should not raise exception if data returned not in json format (should be fixed in v2)' do
283296
allow(RestClient::Request).to receive(:execute).with(expected_payload(http_method))
284297
.and_return(StubResponse.new('Some random text here', true, 200))

0 commit comments

Comments
 (0)