From 8df7d7d92dc04bd79319d725466ffdd4176c4d87 Mon Sep 17 00:00:00 2001 From: Dmytro Shteflyuk Date: Sat, 28 Sep 2024 20:13:14 -0400 Subject: [PATCH] Do not allow both host and hosts for proxy configuration --- lib/kamal/configuration/docs/proxy.yml | 2 +- lib/kamal/configuration/validator/proxy.rb | 4 ++++ test/configuration/proxy_test.rb | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/kamal/configuration/docs/proxy.yml b/lib/kamal/configuration/docs/proxy.yml index 092a7f32..444e2da7 100644 --- a/lib/kamal/configuration/docs/proxy.yml +++ b/lib/kamal/configuration/docs/proxy.yml @@ -31,7 +31,7 @@ proxy: # Hosts # # The hosts that will be used to serve the app. The proxy will only route requests - # to this host to your app. + # to these hosts to your app. # # If no hosts are set, then all requests will be forwarded, except for matching # requests for other apps deployed on that server that do have a host set. diff --git a/lib/kamal/configuration/validator/proxy.rb b/lib/kamal/configuration/validator/proxy.rb index c6dbcb2d..3e2eda19 100644 --- a/lib/kamal/configuration/validator/proxy.rb +++ b/lib/kamal/configuration/validator/proxy.rb @@ -6,6 +6,10 @@ class Kamal::Configuration::Validator::Proxy < Kamal::Configuration::Validator if config["host"].blank? && config["hosts"].blank? && config["ssl"] error "Must set a host to enable automatic SSL" end + + if config["host"].present? && config["hosts"].present? + error "Must use either 'host' or 'hosts', not both" + end end end end diff --git a/test/configuration/proxy_test.rb b/test/configuration/proxy_test.rb index 7772012d..1bdfaeab 100644 --- a/test/configuration/proxy_test.rb +++ b/test/configuration/proxy_test.rb @@ -28,6 +28,11 @@ class ConfigurationProxyTest < ActiveSupport::TestCase assert_raises(Kamal::ConfigurationError) { config.proxy.ssl? } end + test "ssl with both host and hosts" do + @deploy[:proxy] = { "ssl" => true, host: "example.com", hosts: [ "anotherexample.com" ] } + assert_raises(Kamal::ConfigurationError) { config.proxy.ssl? } + end + test "ssl false" do @deploy[:proxy] = { "ssl" => false } assert_not config.proxy.ssl?