Raise the TLS alert from a subclass instead of extending one connection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam RubyandClaude Opus 5.5 authored and Rosa Gutierrez committed 2026-10-21 21:04:16 +09:00
1 parent ce7b5d4ea0
commit 8d4a5264cf
2 files changed
+7 -5

No files matched your search

+5 -3
View File
@@ -76,11 +76,13 @@ class WebPush::ConnectionsTest < ActiveSupport::TestCase
end end
end end
test "a TLS failure on a new connection before the push is written is reported as it is" do class FailingCheckHTTP < WebPush::Connections::HTTP
failing_check = Module.new { private def begin_transport(*) = raise(OpenSSL::SSL::SSLError, "alert right after the handshake") } 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| 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 assert_empty server.requests
end end
end end
@@ -108,8 +108,8 @@ module PushServiceTestHelper
end end
# Built as WebPush::PersistentRequest builds it for a delivery. # Built as WebPush::PersistentRequest builds it for a delivery.
def pinned_connection(server, ip = IP) def pinned_connection(server, ip = IP, http_class: WebPush::Connections::HTTP)
WebPush::Connections::HTTP.new(HOST, server.port, nil).tap do |http| http_class.new(HOST, server.port, nil).tap do |http|
http.ipaddr = ip http.ipaddr = ip
http.use_ssl = true http.use_ssl = true
end end