From 914769f56a1b5b9c66d4419e6b1ca0e178cef399 Mon Sep 17 00:00:00 2001 From: Priyambada Roul <75459506+roulpriya@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:06:01 +0530 Subject: [PATCH] Do not allow empty env vars (#5983) Fixes #5026 Signed-off-by: Priyambada Roul --- .../utility/TestcontainersConfiguration.java | 5 ++++- .../utility/TestcontainersConfigurationTest.java | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java b/core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java index e647a8d50b3..f3bb8f8319a 100644 --- a/core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java +++ b/core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java @@ -230,7 +230,10 @@ private String getConfigurable( } if (environment.containsKey(envVarName)) { - return environment.get(envVarName); + String value = environment.get(envVarName); + if (!value.isEmpty()) { + return value; + } } for (final Properties properties : propertiesSources) { diff --git a/core/src/test/java/org/testcontainers/utility/TestcontainersConfigurationTest.java b/core/src/test/java/org/testcontainers/utility/TestcontainersConfigurationTest.java index d51bc89348c..fcc0a654ef5 100644 --- a/core/src/test/java/org/testcontainers/utility/TestcontainersConfigurationTest.java +++ b/core/src/test/java/org/testcontainers/utility/TestcontainersConfigurationTest.java @@ -126,6 +126,14 @@ public void shouldReadDockerSettingsFromUserProperties() { .isEqualTo("some value"); } + @Test + public void shouldNotReadSettingIfCorrespondingEnvironmentVarIsEmptyString() { + environment.put("DOCKER_FOO", ""); + assertThat(newConfig().getEnvVarOrUserProperty("docker.foo", "default")) + .as("reads unprefixed env vars for docker. settings") + .isEqualTo("default"); + } + @Test public void shouldNotReadDockerClientStrategyFromClasspathProperties() { String currentValue = newConfig().getDockerClientStrategyClassName();