From edbc779f4dfc9b26c36310881711ddc976a9dfc8 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Fri, 9 Oct 2026 11:58:58 -0400 Subject: [PATCH] Test the pooled-connection class check on its own, and name the class The rejection cases built plain Net::HTTP connections that were also unpinned or proxied, so they failed the guard either way. They're built as WebPush::Connections::HTTP now, so each fails only for its stated reason, and a pinned, direct, TLS plain Net::HTTP is refused for being one. The error says which class is required. Co-Authored-By: Claude Opus 5.5 --- lib/web_push/connections.rb | 2 +- test/lib/web_push/connections_test.rb | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/web_push/connections.rb b/lib/web_push/connections.rb index 24a13aa..be6191a 100644 --- a/lib/web_push/connections.rb +++ b/lib/web_push/connections.rb @@ -42,7 +42,7 @@ class WebPush::Connections def request(http, request) unless http.is_a?(HTTP) && http.ipaddr && !http.proxy? && http.use_ssl? && !http.started? - raise ArgumentError, "Only new, direct TLS connections pinned to an address are pooled" + raise ArgumentError, "Only new, direct TLS connections pinned to an address and opened as WebPush::Connections::HTTP are pooled" end address = [ http.address, http.port, http.ipaddr ] diff --git a/test/lib/web_push/connections_test.rb b/test/lib/web_push/connections_test.rb index b93ced3..9eb2b2b 100644 --- a/test/lib/web_push/connections_test.rb +++ b/test/lib/web_push/connections_test.rb @@ -97,14 +97,15 @@ class WebPush::ConnectionsTest < ActiveSupport::TestCase end end - test "only new, direct TLS connections pinned to an address are pooled" do + test "only new, direct TLS connections pinned to an address and opened as WebPush::Connections::HTTP are pooled" do with_push_service do |server| - unpinned = Net::HTTP.new(HOST, server.port, nil).tap { it.use_ssl = true } - proxied = Net::HTTP.new(HOST, server.port, "127.0.0.1", 3128).tap { it.ipaddr = IP; it.use_ssl = true } + unpinned = WebPush::Connections::HTTP.new(HOST, server.port, nil).tap { it.use_ssl = true } + proxied = WebPush::Connections::HTTP.new(HOST, server.port, "127.0.0.1", 3128).tap { it.ipaddr = IP; it.use_ssl = true } plain = pinned_connection(server).tap { it.use_ssl = false } started = pinned_connection(server).tap(&:start) + untracked = Net::HTTP.new(HOST, server.port, nil).tap { it.ipaddr = IP; it.use_ssl = true } - [ unpinned, proxied, plain, started ].each do |http| + [ unpinned, proxied, plain, started, untracked ].each do |http| assert_raises(ArgumentError) { @connections.request(http, push_request) } end assert_empty server.requests