Repository: puma/puma
File: test/test_puma_localhost_authority.rb (Ruby)

Code before:
# helper is required first since it loads Puma, which needs to be
# loaded so HAS_SSL is defined
require_relative "helper"
require "localhost/authority"

if ::Puma::HAS_SSL && !Puma::IS_JRUBY
  require "puma/minissl"
  require "puma/events"
  require "net/http"

  class SSLEventsHelper < ::Puma::Events
    attr_accessor :addr, :cert, :error

    def ssl_error(error, ssl_socket)
      self.error = error
      self.addr = ssl_socket.peeraddr.last rescue "<unknown>"
      self.cert = ssl_socket.peercert
    end
  end


  # net/http (loaded in helper) does not necessarily load OpenSSL
  require "openssl" unless Object.const_defined? :OpenSSL


  puts "", RUBY_DESCRIPTION, "RUBYOPT: #{ENV['RUBYOPT']}",
       "                         Puma::MiniSSL                   OpenSSL",
       "OPENSSL_LIBRARY_VERSION: #{Puma::MiniSSL::OPENSSL_LIBRARY_VERSION.ljust 32}#{OpenSSL::OPENSSL_LIBRARY_VERSION}",
       "        OPENSSL_VERSION: #{Puma::MiniSSL::OPENSSL_VERSION.ljust 32}#{OpenSSL::OPENSSL_VERSION}", ""

end

class TestPumaLocalhostAuthority < Minitest::Test
  parallelize_me!
  def setup
    @http = nil
    @server = nil
  end

  def teardown
    @http.finish if @http && @http.started?
    @server.stop(true) if @server
  end

  # yields ctx to block, use for ctx setup & configuration
  def start_server
    @host = "localhost"
    app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }

    @events = SSLEventsHelper.new STDOUT, STDERR
    @server = Puma::Server.new app, @events

Review comment (suggestion):
This is not necessary because it's already logged in another SSL test file (can't remember which one)

See double output here: 
https://github.com/puma/puma/pull/2610/checks?check_run_id=2932850256#step:9:25

Code after:
# helper is required first since it loads Puma, which needs to be
# loaded so HAS_SSL is defined
require_relative "helper"
require "localhost/authority"

if ::Puma::HAS_SSL && !Puma::IS_JRUBY
  require "puma/minissl"
  require "puma/events"
  require "net/http"

  class SSLEventsHelper < ::Puma::Events
    attr_accessor :addr, :cert, :error

    def ssl_error(error, ssl_socket)
      self.error = error
      self.addr = ssl_socket.peeraddr.last rescue "<unknown>"
      self.cert = ssl_socket.peercert
    end
  end

  # net/http (loaded in helper) does not necessarily load OpenSSL
  require "openssl" unless Object.const_defined? :OpenSSL
end

class TestPumaLocalhostAuthority < Minitest::Test
  parallelize_me!
  def setup
    @http = nil
    @server = nil
  end

  def teardown
    @http.finish if @http && @http.started?
    @server.stop(true) if @server
  end

  # yields ctx to block, use for ctx setup & configuration
  def start_server
    @host = "localhost"
    app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }

    @events = SSLEventsHelper.new STDOUT, STDERR
    @server = Puma::Server.new app, @events
    @server.app = app
    @server.add_ssl_listener @host, 0,nil
    @http = Net::HTTP.new @host, @server.connected_ports[0]

    @http.use_ssl = true
    # Disabling verification since its self signed
    @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    # @http.verify_mode = OpenSSL::SSL::VERIFY_NONE