Sha256: f2f93d480f0045a2fcd581333c05c6ca8c687236b6c270a09981060596bb30cd

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

require "rbconfig"
require 'test/unit'
require 'socket'
require 'openssl'

require 'puma/server'

require 'net/https'

class TestPumaServer < Test::Unit::TestCase

  def setup
    @port = 3212
    @host = "127.0.0.1"

    @app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }

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

    @ssl_key =  File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__
    @ssl_cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__
  end

  def teardown
    @server.stop
  end

  def test_url_scheme_for_https
    ctx = OpenSSL::SSL::SSLContext.new

    ctx.key = OpenSSL::PKey::RSA.new File.read(@ssl_key)

    ctx.cert = OpenSSL::X509::Certificate.new File.read(@ssl_cert)

    ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE

    @server.add_ssl_listener @host, @port, ctx
    @server.run

    http = Net::HTTP.new @host, @port
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE

    body = nil
    http.start do
      req = Net::HTTP::Get.new "/", {}

      http.request(req) do |rep|
        body = rep.body
      end
    end

    assert_equal "https", body
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puma-1.3.0-java test/test_puma_server.rb
puma-1.3.0 test/test_puma_server.rb
puma-1.2.2-java test/test_puma_server.rb
puma-1.2.2 test/test_puma_server.rb
puma-1.2.1-java test/test_puma_server.rb
puma-1.2.1 test/test_puma_server.rb