Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Olichwirowicz committed Oct 4, 2021
1 parent 2f41a31 commit 1215cdf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/puma/minissl/context_builder.rb
Expand Up @@ -38,7 +38,7 @@ def context
ctx.keystore_pass = params['keystore-pass']
ctx.ssl_cipher_list = params['ssl_cipher_list'] if params['ssl_cipher_list']
else
unless params['key']
if params['key'].nil? || params['key'] == ""
if localhost_authority
params['key'] = localhost_authority_context[0]
else
Expand All @@ -48,7 +48,7 @@ def context

ctx.key = params['key']

unless params['cert']
if params['cert'].nil? || params['cert'] == ""
if localhost_authority
params['cert'] = localhost_authority_context[1]
else
Expand Down
53 changes: 39 additions & 14 deletions test/test_integration_ssl.rb
@@ -1,6 +1,7 @@
require_relative 'helper'
require_relative "helpers/integration"


# These tests are used to verify that Puma works with SSL sockets. Only
# integration tests isolate the server from the test environment, so there
# should be a few SSL tests.
Expand All @@ -15,18 +16,10 @@ class TestIntegrationSSL < TestIntegration
require "net/http"
require "openssl"

def teardown
@server.close unless @server.closed?
@server = nil
super
end

def generate_config(opts = nil)
def setup
@bind_port = UniquePort.call
@control_tcp_port = UniquePort.call

config = <<RUBY
#{opts}
@default_config = <<RUBY
if ::Puma.jruby?
keystore = '#{File.expand_path '../examples/puma/keystore.jks', __dir__}'
keystore_pass = 'jruby_puma'
Expand Down Expand Up @@ -54,14 +47,35 @@ def generate_config(opts = nil)
end
RUBY

@localhost_config = <<RUBY
require 'localhost/authority'
ssl_bind '#{HOST}', '#{@bind_port}'
activate_control_app 'tcp://#{HOST}:#{@control_tcp_port}', { auth_token: '#{TOKEN}' }
app do |env|
[200, {}, [env['rack.url_scheme']]]
end
RUBY

super
end

def teardown
@server.close unless @server.closed?
@server = nil
super
end

def generate_config(config)
config_file = Tempfile.new %w(config .rb)
config_file.write config
config_file.write(config)
config_file.close
config_file.path
end

def start_server(opts = nil)
cmd = "#{BASE} bin/puma -C #{generate_config opts}"
def start_server(cmd)
@server = IO.popen cmd, 'r'
wait_for_server_to_boot
@pid = @server.pid
Expand All @@ -81,12 +95,23 @@ def stop_server

def test_ssl_run
body = nil
start_server
start_server("#{BASE} bin/puma -C #{generate_config(@default_config)}")
@http.start do
req = Net::HTTP::Get.new '/', {}
@http.request(req) { |resp| body = resp.body }
end
assert_equal 'https', body
stop_server
end

def test_ssl_run_with_localhost_authority
body = nil
start_server("#{BASE} bin/puma -C #{generate_config(@localhost_config)}")
@http.start do
req = Net::HTTP::Get.new '/', {}
@http.request(req) { |resp| body = resp.body }
end
assert_equal 'https', body
stop_server
end unless ::Puma::IS_JRUBY
end if ::Puma::HAS_SSL

0 comments on commit 1215cdf

Please sign in to comment.