Escape newlines in docker env files

When env variables were passed via `-e` newlines were escaped. This
updates the env file to do the same thing.
This commit is contained in:
Donal McBreen
2023-09-12 13:56:08 +01:00
parent 70a3c7195a
commit df2b76aee1
2 changed files with 32 additions and 5 deletions

View File

@@ -49,6 +49,30 @@ class UtilsTest < ActiveSupport::TestCase
ENV.delete "PASSWORD"
end
test "env file secret escaped newline" do
ENV["PASSWORD"] = "hello\\nthere"
env = {
"secret" => [ "PASSWORD" ]
}
assert_equal "PASSWORD=hello\\\\nthere\n", \
Kamal::Utils.env_file_with_secrets(env)
ensure
ENV.delete "PASSWORD"
end
test "env file secret newline" do
ENV["PASSWORD"] = "hello\nthere"
env = {
"secret" => [ "PASSWORD" ]
}
assert_equal "PASSWORD=hello\\nthere\n", \
Kamal::Utils.env_file_with_secrets(env)
ensure
ENV.delete "PASSWORD"
end
test "env file missing secret" do
env = {
"secret" => [ "PASSWORD" ]