From 8d4a5264cf06059e6ca389f3d0ce1bd080f07c6b Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Sat, 17 Oct 2026 17:31:21 -0400 Subject: [PATCH] Raise the TLS alert from a subclass instead of extending one connection Co-Authored-By: Claude Opus 5.5 --- test/lib/web_push/connections_test.rb | 8 +++++--- test/test_helpers/push_service_test_helper.rb | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/lib/web_push/connections_test.rb b/test/lib/web_push/connections_test.rb index 9eb2b2b..1fb2d29 100644 --- a/test/lib/web_push/connections_test.rb +++ b/test/lib/web_push/connections_test.rb @@ -76,11 +76,13 @@ class WebPush::ConnectionsTest < ActiveSupport::TestCase end end - test "a TLS failure on a new connection before the push is written is reported as it is" do - failing_check = Module.new { private def begin_transport(*) = raise(OpenSSL::SSL::SSLError, "alert right after the handshake") } + class FailingCheckHTTP < WebPush::Connections::HTTP + private def begin_transport(*) = raise(OpenSSL::SSL::SSLError, "alert right after the handshake") + end + test "a TLS failure on a new connection before the push is written is reported as it is" do with_push_service do |server| - assert_raises(OpenSSL::SSL::SSLError) { @connections.request(pinned_connection(server).extend(failing_check), push_request) } + assert_raises(OpenSSL::SSL::SSLError) { @connections.request(pinned_connection(server, http_class: FailingCheckHTTP), push_request) } assert_empty server.requests end end diff --git a/test/test_helpers/push_service_test_helper.rb b/test/test_helpers/push_service_test_helper.rb index 1d4e701..ebe1cfd 100644 --- a/test/test_helpers/push_service_test_helper.rb +++ b/test/test_helpers/push_service_test_helper.rb @@ -108,8 +108,8 @@ module PushServiceTestHelper end # Built as WebPush::PersistentRequest builds it for a delivery. - def pinned_connection(server, ip = IP) - WebPush::Connections::HTTP.new(HOST, server.port, nil).tap do |http| + def pinned_connection(server, ip = IP, http_class: WebPush::Connections::HTTP) + http_class.new(HOST, server.port, nil).tap do |http| http.ipaddr = ip http.use_ssl = true end