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