Fixes #3573 - Accept 2xx as response for requests in UserAgent

This commit is contained in:
André Glüpker 2021-05-27 12:10:30 +02:00 committed by Thorsten Eckel
parent c3247e98ff
commit 18f14d1720
2 changed files with 16 additions and 1 deletions

View file

@ -472,7 +472,7 @@ returns
url = response['location'] url = response['location']
return get(url, params, options, count - 1) return get(url, params, options, count - 1)
when Net::HTTPOK, Net::HTTPCreated when Net::HTTPSuccess
data = nil data = nil
if options[:json] && !options[:jsonParseDisable] && response.body if options[:json] && !options[:jsonParseDisable] && response.body
data = JSON.parse(response.body) data = JSON.parse(response.body)

View file

@ -32,6 +32,21 @@ class UserAgentTest < ActiveSupport::TestCase
assert_match(%r{"remote_ip":"#{ENV['ZAMMAD_PROXY_REMOTE_IP_CHECK']}"}, result.body) assert_match(%r{"remote_ip":"#{ENV['ZAMMAD_PROXY_REMOTE_IP_CHECK']}"}, result.body)
end end
# get / 202
result = UserAgent.get(
"#{host}/test/get_accepted/1?submitted=123",
)
assert(result)
assert_equal(true, result.success?)
assert_equal('202', result.code)
assert_equal(String, result.body.class)
assert(result.body.include?('"get"'))
assert(result.body.include?('"123"'))
assert(result.body.include?('"content_type_requested":null'))
if ENV['ZAMMAD_PROXY_TEST'] == 'true' && ENV['ZAMMAD_PROXY_REMOTE_IP_CHECK']
assert_match(%r{"remote_ip":"#{ENV['ZAMMAD_PROXY_REMOTE_IP_CHECK']}"}, result.body)
end
# get / 404 # get / 404
result = UserAgent.get( result = UserAgent.get(
"#{host}/test/not_existing", "#{host}/test/not_existing",