From 508e2e601c2701108242ffbb170dc2cadb28389d Mon Sep 17 00:00:00 2001 From: Leonardo Mosquera <ldmosquera@gmail.com> Date: Wed, 24 Jan 2024 18:50:42 -0300 Subject: [PATCH] FIX: FinalDestination::HTTP: validate address argument (#25407) This would only be empty due to a programming error elsewhere, but checking this here is a failstop so that it doesn't go further. --- lib/final_destination/http.rb | 2 ++ spec/lib/final_destination/http_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/final_destination/http.rb b/lib/final_destination/http.rb index 4973b149a33..111b1c80143 100644 --- a/lib/final_destination/http.rb +++ b/lib/final_destination/http.rb @@ -2,6 +2,8 @@ class FinalDestination::HTTP < Net::HTTP def connect + raise ArgumentError.new("address cannot be nil or empty") unless @address.present? + original_open_timeout = @open_timeout return super if @ipaddr diff --git a/spec/lib/final_destination/http_spec.rb b/spec/lib/final_destination/http_spec.rb index fe1132acc82..2f2181fefe1 100644 --- a/spec/lib/final_destination/http_spec.rb +++ b/spec/lib/final_destination/http_spec.rb @@ -110,4 +110,12 @@ describe FinalDestination::HTTP do FinalDestination::HTTP.start("example.com", 80, open_timeout: 5) {} end.to raise_error(Net::OpenTimeout) end + + it "validates address argument against nil value" do + expect do FinalDestination::HTTP.start(nil) {} end.to raise_error(ArgumentError) + end + + it "validates address argument against empty value" do + expect do FinalDestination::HTTP.start("") {} end.to raise_error(ArgumentError) + end end