danbooru::http: fix SSLError exceptions not being caught.
Bug: The frontpage failed due to a SSL error. We couldn't fetch the popular tag list from Reportbooru because Reportbooru's SSL certificate had expired and HTTP.rb raised an SSLError exception that we didn't catch. Fix: Convert the SSLError to a 5xx HTTP error to prevent SSL exceptions from leaking through HTTP.rb.
This commit is contained in:
@@ -120,11 +120,17 @@ module Danbooru
|
|||||||
|
|
||||||
def request(method, url, **options)
|
def request(method, url, **options)
|
||||||
http.send(method, url, **options)
|
http.send(method, url, **options)
|
||||||
|
rescue OpenSSL::SSL::SSLError
|
||||||
|
fake_response(590, "")
|
||||||
rescue ValidatingSocket::ProhibitedIpError
|
rescue ValidatingSocket::ProhibitedIpError
|
||||||
fake_response(597, "")
|
fake_response(591, "")
|
||||||
rescue HTTP::Redirector::TooManyRedirectsError
|
rescue HTTP::Redirector::TooManyRedirectsError
|
||||||
fake_response(598, "")
|
fake_response(596, "")
|
||||||
rescue HTTP::TimeoutError
|
rescue HTTP::TimeoutError
|
||||||
|
fake_response(597, "")
|
||||||
|
rescue HTTP::ConnectionError
|
||||||
|
fake_response(598, "")
|
||||||
|
rescue HTTP::Error
|
||||||
fake_response(599, "")
|
fake_response(599, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -19,21 +19,31 @@ class DanbooruHttpTest < ActiveSupport::TestCase
|
|||||||
should "fail if redirected too many times" do
|
should "fail if redirected too many times" do
|
||||||
skip "Skipping test (https://github.com/postmanlabs/httpbin/issues/617)"
|
skip "Skipping test (https://github.com/postmanlabs/httpbin/issues/617)"
|
||||||
response = Danbooru::Http.get("https://httpbin.org/absolute-redirect/10")
|
response = Danbooru::Http.get("https://httpbin.org/absolute-redirect/10")
|
||||||
assert_equal(598, response.status)
|
assert_equal(596, response.status)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "fail if the request takes too long to connect" do
|
should "fail if the request takes too long to connect" do
|
||||||
response = Danbooru::Http.timeout(1).get("https://httpbin.org/delay/5")
|
response = Danbooru::Http.timeout(1).get("https://httpbin.org/delay/5")
|
||||||
assert_equal(599, response.status)
|
assert_equal(597, response.status)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "fail if the request takes too long to download" do
|
should "fail if the request takes too long to download" do
|
||||||
# XXX should return status 599 instead
|
# XXX should return status 597 instead
|
||||||
assert_raises(HTTP::TimeoutError) do
|
assert_raises(HTTP::TimeoutError) do
|
||||||
response = Danbooru::Http.timeout(1).get("https://httpbin.org/drip?duration=10&numbytes=10").flush
|
response = Danbooru::Http.timeout(1).get("https://httpbin.org/drip?duration=10&numbytes=10").flush
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "return a 5xx error if the domain can't be resolved" do
|
||||||
|
response = Danbooru::Http.get("http://doesnotexist.donmai.us")
|
||||||
|
assert_equal(598, response.status)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return a 5xx error if the SSL certificate is expired" do
|
||||||
|
response = Danbooru::Http.get("https://expired.badssl.com")
|
||||||
|
assert_equal(590, response.status)
|
||||||
|
end
|
||||||
|
|
||||||
should "automatically decompress gzipped responses" do
|
should "automatically decompress gzipped responses" do
|
||||||
response = Danbooru::Http.get("https://httpbin.org/gzip")
|
response = Danbooru::Http.get("https://httpbin.org/gzip")
|
||||||
assert_equal(200, response.status)
|
assert_equal(200, response.status)
|
||||||
|
|||||||
Reference in New Issue
Block a user