mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Add ssl support to the control_cli (#2052)
If I have a server running: ```sh bundle exec bin/puma test/rackup/hello.ru \ --control-url="ssl://127.0.0.1:9000?key=examples/puma/puma_keypair.pem&cert=examples/puma/cert_puma.pem" \ --control-token="token" ``` This commit will allow me to restart that server (or run any other control cli command) with: ```sh bundle exec bin/pumactl restart \ --control-url="ssl://127.0.0.1:9000" \ --control-token="token" ``` Before this commit the pumactl restart command would have raised an error: `"Invalid scheme: ssl"`
This commit is contained in:
parent
f767f61219
commit
7256d79abc
3 changed files with 47 additions and 13 deletions
|
@ -3,7 +3,7 @@
|
||||||
* Features
|
* Features
|
||||||
* Strip whitespace at end of HTTP headers (#2010)
|
* Strip whitespace at end of HTTP headers (#2010)
|
||||||
* Optimize HTTP parser for JRuby (#2012)
|
* Optimize HTTP parser for JRuby (#2012)
|
||||||
* Add SSL support for the control app (#2046)
|
* Add SSL support for the control app and cli (#2046, #2052)
|
||||||
|
|
||||||
* Bugfixes
|
* Bugfixes
|
||||||
* Fix Errno::EINVAL when SSL is enabled and browser rejects cert (#1564)
|
* Fix Errno::EINVAL when SSL is enabled and browser rejects cert (#1564)
|
||||||
|
|
|
@ -141,6 +141,12 @@ module Puma
|
||||||
|
|
||||||
# create server object by scheme
|
# create server object by scheme
|
||||||
server = case uri.scheme
|
server = case uri.scheme
|
||||||
|
when "ssl"
|
||||||
|
require 'openssl'
|
||||||
|
OpenSSL::SSL::SSLSocket.new(
|
||||||
|
TCPSocket.new(uri.host, uri.port),
|
||||||
|
OpenSSL::SSL::SSLContext.new
|
||||||
|
).tap(&:connect)
|
||||||
when "tcp"
|
when "tcp"
|
||||||
TCPSocket.new uri.host, uri.port
|
TCPSocket.new uri.host, uri.port
|
||||||
when "unix"
|
when "unix"
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
require_relative "helpers/config_file"
|
require_relative "helpers/config_file"
|
||||||
|
require_relative "helpers/ssl"
|
||||||
|
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'puma/control_cli'
|
require 'puma/control_cli'
|
||||||
|
|
||||||
class TestPumaControlCli < TestConfigFileBase
|
class TestPumaControlCli < TestConfigFileBase
|
||||||
|
include SSLHelper
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
# use a pipe to get info across thread boundary
|
# use a pipe to get info across thread boundary
|
||||||
@wait, @ready = IO.pipe
|
@wait, @ready = IO.pipe
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait_booted
|
def wait_booted
|
||||||
line = @wait.gets until line =~ /Listening on/
|
line = @wait.gets until line =~ /Use Ctrl-C to stop/
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
|
@ -139,18 +142,43 @@ class TestPumaControlCli < TestConfigFileBase
|
||||||
assert_match "200 OK", body
|
assert_match "200 OK", body
|
||||||
assert_match "embedded app", body
|
assert_match "embedded app", body
|
||||||
|
|
||||||
status_cmd = Puma::ControlCLI.new(opts + ["status"])
|
assert_command_cli_output opts + ["status"], "Puma is started"
|
||||||
out, _ = capture_subprocess_io do
|
assert_command_cli_output opts + ["stop"], "Command stop sent success"
|
||||||
status_cmd.run
|
|
||||||
end
|
|
||||||
assert_match "Puma is started\n", out
|
|
||||||
|
|
||||||
shutdown_cmd = Puma::ControlCLI.new(opts + ["halt"])
|
|
||||||
out, _ = capture_subprocess_io do
|
|
||||||
shutdown_cmd.run
|
|
||||||
end
|
|
||||||
assert_match "Command halt sent success\n", out
|
|
||||||
|
|
||||||
assert_kind_of Thread, t.join, "server didn't stop"
|
assert_kind_of Thread, t.join, "server didn't stop"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_control_ssl
|
||||||
|
host = "127.0.0.1"
|
||||||
|
port = find_open_port
|
||||||
|
url = "ssl://#{host}:#{port}?#{ssl_query}"
|
||||||
|
|
||||||
|
opts = [
|
||||||
|
"--control-url", url,
|
||||||
|
"--control-token", "ctrl",
|
||||||
|
"--config-file", "test/config/app.rb",
|
||||||
|
]
|
||||||
|
|
||||||
|
control_cli = Puma::ControlCLI.new (opts + ["start"]), @ready, @ready
|
||||||
|
t = Thread.new do
|
||||||
|
control_cli.run
|
||||||
|
end
|
||||||
|
|
||||||
|
wait_booted
|
||||||
|
|
||||||
|
assert_command_cli_output opts + ["status"], "Puma is started"
|
||||||
|
assert_command_cli_output opts + ["stop"], "Command stop sent success"
|
||||||
|
|
||||||
|
assert_kind_of Thread, t.join, "server didn't stop"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def assert_command_cli_output(options, expected_out)
|
||||||
|
cmd = Puma::ControlCLI.new(options)
|
||||||
|
out, _ = capture_subprocess_io do
|
||||||
|
cmd.run
|
||||||
|
end
|
||||||
|
assert_match expected_out, out
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue