Skip to content

Commit

Permalink
FIX: FinalDestination::HTTP: validate address argument (discourse#25407)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ldmosquera authored Jan 24, 2024
1 parent 0c63463 commit 508e2e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/final_destination/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions spec/lib/final_destination/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,12 @@ def stub_tcp_to_raise(stub_addr, exception)
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

0 comments on commit 508e2e6

Please sign in to comment.