mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:09:00 +08:00
FIX: Swallow SSL errors when generating oneboxes
This commit is contained in:
parent
14cc67c9b2
commit
afe7785141
|
@ -192,13 +192,13 @@ class FinalDestination
|
||||||
|
|
||||||
if @limit < 0
|
if @limit < 0
|
||||||
@status = :too_many_redirects
|
@status = :too_many_redirects
|
||||||
log(:warn, "FinalDestination could not resolve URL (too many redirects): #{@uri}") if @verbose
|
log(:warn, "FinalDestination could not resolve URL (too many redirects): #{@uri}")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
unless validate_uri
|
unless validate_uri
|
||||||
@status = :invalid_address
|
@status = :invalid_address
|
||||||
log(:warn, "FinalDestination could not resolve URL (invalid URI): #{@uri}") if @verbose
|
log(:warn, "FinalDestination could not resolve URL (invalid URI): #{@uri}")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -344,10 +344,10 @@ class FinalDestination
|
||||||
@status = :failure
|
@status = :failure
|
||||||
@status_code = response.status
|
@status_code = response.status
|
||||||
|
|
||||||
log(:warn, "FinalDestination could not resolve URL (status #{response.status}): #{@uri}") if @verbose
|
log(:warn, "FinalDestination could not resolve URL (status #{response.status}): #{@uri}")
|
||||||
nil
|
nil
|
||||||
rescue Excon::Errors::Timeout
|
rescue Excon::Errors::Timeout
|
||||||
log(:warn, "FinalDestination could not resolve URL (timeout): #{@uri}") if @verbose
|
log(:warn, "FinalDestination could not resolve URL (timeout): #{@uri}")
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -427,6 +427,7 @@ class FinalDestination
|
||||||
end
|
end
|
||||||
|
|
||||||
def log(log_level, message)
|
def log(log_level, message)
|
||||||
|
return unless @verbose
|
||||||
return if @status_code == 404
|
return if @status_code == 404
|
||||||
|
|
||||||
Rails.logger.public_send(
|
Rails.logger.public_send(
|
||||||
|
@ -519,7 +520,10 @@ class FinalDestination
|
||||||
|
|
||||||
result
|
result
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
log(:warn, "FinalDestination could not resolve URL (timeout): #{@uri}") if @verbose
|
log(:warn, "FinalDestination could not resolve URL (timeout): #{@uri}")
|
||||||
|
nil
|
||||||
|
rescue OpenSSL::SSL::SSLError => exception
|
||||||
|
log(:warn, "An error with SSL occurred: #{@uri} #{exception.message}")
|
||||||
nil
|
nil
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
unsafe_close ? [:ok, headers_subset] : raise
|
unsafe_close ? [:ok, headers_subset] : raise
|
||||||
|
|
|
@ -470,6 +470,23 @@ RSpec.describe FinalDestination do
|
||||||
expect(get).to be_blank
|
expect(get).to be_blank
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when there is an SSL error" do
|
||||||
|
subject(:get) { fd.get {} }
|
||||||
|
|
||||||
|
before do
|
||||||
|
fd.stubs(:safe_session).raises(OpenSSL::SSL::SSLError)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "logs the exception" do
|
||||||
|
Rails.logger.expects(:warn).with(regexp_matches(/an error with ssl occurred/i))
|
||||||
|
get
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nothing" do
|
||||||
|
expect(get).to be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.validate_uri' do
|
describe '.validate_uri' do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user