Merge pull request #1531 from acidtib/feat/custom-ssl
feat: Add support for custom certificates
This commit is contained in:
@@ -220,6 +220,21 @@ class CliAppTest < CliTestCase
|
||||
end
|
||||
end
|
||||
|
||||
test "boot with custom ssl certificate" do
|
||||
Kamal::Configuration::Proxy.any_instance.stubs(:custom_ssl_certificate?).returns(true)
|
||||
Kamal::Configuration::Proxy.any_instance.stubs(:certificate_pem_content).returns("CERTIFICATE CONTENT")
|
||||
Kamal::Configuration::Proxy.any_instance.stubs(:private_key_pem_content).returns("PRIVATE KEY CONTENT")
|
||||
|
||||
stub_running
|
||||
run_command("boot", config: :with_proxy).tap do |output|
|
||||
assert_match "Writing SSL certificates for web on 1.1.1.1", output
|
||||
assert_match "mkdir -p .kamal/proxy/apps-config/app/tls", output
|
||||
assert_match "sh -c [REDACTED]", output
|
||||
assert_match "--tls-certificate-path=\"/home/kamal-proxy/.apps-config/app/tls/cert.pem\"", output
|
||||
assert_match "--tls-private-key-path=\"/home/kamal-proxy/.apps-config/app/tls/key.pem\"", output
|
||||
end
|
||||
end
|
||||
|
||||
test "start" do
|
||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info).returns("999") # old version
|
||||
|
||||
|
||||
@@ -149,8 +149,6 @@ class CommandsAppTest < ActiveSupport::TestCase
|
||||
new_command.remove.join(" ")
|
||||
end
|
||||
|
||||
|
||||
|
||||
test "logs" do
|
||||
assert_equal \
|
||||
"sh -c 'docker ps --latest --quiet --filter label=service=app --filter label=destination= --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''{{.ID}}'\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=destination= --filter label=role=web --filter status=running --filter status=restarting' | head -1 | xargs docker logs --timestamps 2>&1",
|
||||
|
||||
@@ -25,5 +25,7 @@ class ConfigurationProxyBootTest < ActiveSupport::TestCase
|
||||
assert_equal "/home/kamal-proxy/.apps-config/app", @proxy_boot_config.app_container_directory
|
||||
assert_equal ".kamal/proxy/apps-config/app/error_pages", @proxy_boot_config.error_pages_directory
|
||||
assert_equal "/home/kamal-proxy/.apps-config/app/error_pages", @proxy_boot_config.error_pages_container_directory
|
||||
assert_equal ".kamal/proxy/apps-config/app/tls", @proxy_boot_config.tls_directory
|
||||
assert_equal "/home/kamal-proxy/.apps-config/app/tls", @proxy_boot_config.tls_container_directory
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,6 +45,64 @@ class ConfigurationProxyTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
test "ssl with certificate and private key from secrets" do
|
||||
with_test_secrets("secrets" => "CERT_PEM=certificate\nKEY_PEM=private_key") do
|
||||
@deploy[:proxy] = {
|
||||
"ssl" => {
|
||||
"certificate_pem" => "CERT_PEM",
|
||||
"private_key_pem" => "KEY_PEM"
|
||||
},
|
||||
"host" => "example.com"
|
||||
}
|
||||
|
||||
proxy = config.proxy
|
||||
assert_equal "/home/kamal-proxy/.apps-config/app/tls/cert.pem", proxy.certificate_pem
|
||||
assert_equal "/home/kamal-proxy/.apps-config/app/tls/key.pem", proxy.private_key_pem
|
||||
end
|
||||
end
|
||||
|
||||
test "deploy options with custom ssl certificates" do
|
||||
with_test_secrets("secrets" => "CERT_PEM=certificate\nKEY_PEM=private_key") do
|
||||
@deploy[:proxy] = {
|
||||
"ssl" => {
|
||||
"certificate_pem" => "CERT_PEM",
|
||||
"private_key_pem" => "KEY_PEM"
|
||||
},
|
||||
"host" => "example.com"
|
||||
}
|
||||
|
||||
proxy = config.proxy
|
||||
options = proxy.deploy_options
|
||||
assert_equal true, options[:tls]
|
||||
assert_equal "/home/kamal-proxy/.apps-config/app/tls/cert.pem", options[:"tls-certificate-path"]
|
||||
assert_equal "/home/kamal-proxy/.apps-config/app/tls/key.pem", options[:"tls-private-key-path"]
|
||||
end
|
||||
end
|
||||
|
||||
test "ssl with certificate and no private key" do
|
||||
with_test_secrets("secrets" => "CERT_PEM=certificate") do
|
||||
@deploy[:proxy] = {
|
||||
"ssl" => {
|
||||
"certificate_pem" => "CERT_PEM"
|
||||
},
|
||||
"host" => "example.com"
|
||||
}
|
||||
assert_raises(Kamal::ConfigurationError) { config.proxy.ssl? }
|
||||
end
|
||||
end
|
||||
|
||||
test "ssl with private key and no certificate" do
|
||||
with_test_secrets("secrets" => "KEY_PEM=private_key") do
|
||||
@deploy[:proxy] = {
|
||||
"ssl" => {
|
||||
"private_key_pem" => "KEY_PEM"
|
||||
},
|
||||
"host" => "example.com"
|
||||
}
|
||||
assert_raises(Kamal::ConfigurationError) { config.proxy.ssl? }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def config
|
||||
Kamal::Configuration.new(@deploy)
|
||||
|
||||
@@ -386,7 +386,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
Kamal::Configuration.new(@deploy_with_roles)
|
||||
end
|
||||
|
||||
assert_equal "SSL is only supported on a single server, found 2 servers for role workers", exception.message
|
||||
assert_equal "SSL is only supported on a single server unless you provide custom certificates, found 2 servers for role workers", exception.message
|
||||
end
|
||||
|
||||
test "two proxy ssl roles with same host" do
|
||||
|
||||
Reference in New Issue
Block a user