This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 8231d2fc148 NIFI-15652 Fixed HashiCorp Vault test failures when 
VAULT_TOKEN environment variable is set (#10942)
8231d2fc148 is described below

commit 8231d2fc1487928086635a803e7ea77012439a20
Author: Pierre Villard <[email protected]>
AuthorDate: Sat Feb 28 20:25:27 2026 +0100

    NIFI-15652 Fixed HashiCorp Vault test failures when VAULT_TOKEN environment 
variable is set (#10942)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../config/HashiCorpVaultConfiguration.java        | 13 ++++++++++-
 .../hashicorp/TestHashiCorpVaultConfiguration.java | 25 +++++++++++++++++-----
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git 
a/nifi-commons/nifi-hashicorp-vault/src/main/java/org/apache/nifi/vault/hashicorp/config/HashiCorpVaultConfiguration.java
 
b/nifi-commons/nifi-hashicorp-vault/src/main/java/org/apache/nifi/vault/hashicorp/config/HashiCorpVaultConfiguration.java
index c71be9d2e52..46c406fb6f8 100644
--- 
a/nifi-commons/nifi-hashicorp-vault/src/main/java/org/apache/nifi/vault/hashicorp/config/HashiCorpVaultConfiguration.java
+++ 
b/nifi-commons/nifi-hashicorp-vault/src/main/java/org/apache/nifi/vault/hashicorp/config/HashiCorpVaultConfiguration.java
@@ -77,12 +77,23 @@ public class HashiCorpVaultConfiguration extends 
EnvironmentVaultConfiguration {
 
     /**
      * Creates a HashiCorpVaultConfiguration from property sources, in 
increasing precedence.
+     * The environment includes system environment variables and system 
properties as fallback sources.
      * @param propertySources A series of Spring PropertySource objects (the 
last in the list take precedence over
      *                        sources earlier in the list)
      * @throws HashiCorpVaultConfigurationException If the authentication 
properties file could not be read
      */
     public HashiCorpVaultConfiguration(final PropertySource<?>... 
propertySources) {
-        final ConfigurableEnvironment env = new StandardEnvironment();
+        this(new StandardEnvironment(), propertySources);
+    }
+
+    /**
+     * Creates a HashiCorpVaultConfiguration from property sources with a 
provided environment.
+     * @param env The ConfigurableEnvironment to use for property resolution
+     * @param propertySources A series of Spring PropertySource objects (the 
last in the list take precedence over
+     *                        sources earlier in the list)
+     * @throws HashiCorpVaultConfigurationException If the authentication 
properties file could not be read
+     */
+    public HashiCorpVaultConfiguration(final ConfigurableEnvironment env, 
final PropertySource<?>... propertySources) {
         for (final PropertySource<?> propertySource : propertySources) {
             env.getPropertySources().addFirst(propertySource);
         }
diff --git 
a/nifi-commons/nifi-hashicorp-vault/src/test/java/org/apache/nifi/vault/hashicorp/TestHashiCorpVaultConfiguration.java
 
b/nifi-commons/nifi-hashicorp-vault/src/test/java/org/apache/nifi/vault/hashicorp/TestHashiCorpVaultConfiguration.java
index 190b9aa6ce6..41bf16b3b38 100644
--- 
a/nifi-commons/nifi-hashicorp-vault/src/test/java/org/apache/nifi/vault/hashicorp/TestHashiCorpVaultConfiguration.java
+++ 
b/nifi-commons/nifi-hashicorp-vault/src/test/java/org/apache/nifi/vault/hashicorp/TestHashiCorpVaultConfiguration.java
@@ -23,6 +23,8 @@ import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.StandardEnvironment;
 import org.springframework.vault.authentication.ClientAuthentication;
 import org.springframework.vault.client.VaultEndpoint;
 import org.springframework.vault.core.VaultKeyValueOperationsSupport;
@@ -118,15 +120,26 @@ public class TestHashiCorpVaultConfiguration {
         }
     }
 
+    private static ConfigurableEnvironment createIsolatedEnvironment() {
+        final ConfigurableEnvironment environment = new StandardEnvironment();
+        
environment.getPropertySources().remove(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
+        
environment.getPropertySources().remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
+        return environment;
+    }
+
     public void runTest(final String expectedScheme) {
-        config = new HashiCorpVaultConfiguration(new 
HashiCorpVaultPropertySource(propertiesBuilder.build()));
+        runTest(expectedScheme, new StandardEnvironment());
+    }
+
+    public void runTest(final String expectedScheme, final 
ConfigurableEnvironment environment) {
+        config = new HashiCorpVaultConfiguration(environment, new 
HashiCorpVaultPropertySource(propertiesBuilder.build()));
 
-        VaultEndpoint endpoint = config.vaultEndpoint();
+        final VaultEndpoint endpoint = config.vaultEndpoint();
         assertEquals("localhost", endpoint.getHost());
         assertEquals(8200, endpoint.getPort());
         assertEquals(expectedScheme, endpoint.getScheme());
 
-        ClientAuthentication clientAuthentication = 
config.clientAuthentication();
+        final ClientAuthentication clientAuthentication = 
config.clientAuthentication();
         assertNotNull(clientAuthentication);
     }
 
@@ -198,7 +211,8 @@ public class TestHashiCorpVaultConfiguration {
             authProperties = writeVaultAuthProperties(props);
             
propertiesBuilder.setAuthPropertiesFilename(authProperties.getAbsolutePath());
 
-            assertThrows(IllegalArgumentException.class, () -> 
this.runTest("http"));
+            final ConfigurableEnvironment isolatedEnvironment = 
createIsolatedEnvironment();
+            assertThrows(IllegalArgumentException.class, () -> 
this.runTest("http", isolatedEnvironment));
         } finally {
             if (authProperties != null) {
                 Files.deleteIfExists(authProperties.toPath());
@@ -214,7 +228,8 @@ public class TestHashiCorpVaultConfiguration {
             authProperties = writeVaultAuthProperties(props);
             
propertiesBuilder.setAuthPropertiesFilename(authProperties.getAbsolutePath());
 
-            assertThrows(IllegalArgumentException.class, () -> 
this.runTest("http"));
+            final ConfigurableEnvironment isolatedEnvironment = 
createIsolatedEnvironment();
+            assertThrows(IllegalArgumentException.class, () -> 
this.runTest("http", isolatedEnvironment));
         } finally {
             if (authProperties != null) {
                 Files.deleteIfExists(authProperties.toPath());

Reply via email to