Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize address when load from env #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/bettercloud/vault/VaultConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public VaultConfig build() throws VaultException {
if (this.address == null) {
final String addressFromEnv = environmentLoader.loadVariable(VAULT_ADDR);
if (addressFromEnv != null) {
this.address = addressFromEnv;
address(addressFromEnv);
} else {
throw new VaultException("No address is set");
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/bettercloud/vault/VaultConfigTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ public void testConfigConstructor_NormalizesAddress() throws VaultException {
assertEquals("https://localhost:8200", config.getAddress());
}

/**
* Test creating a new <code>VaultConfig</code> via its constructor, take address from environment and ensuring
* that addresses are normalized to not have a trailing slash.
*
* @throws VaultException
*/
@Test
public void testConfigConstructor_NormalizesAddressFromEnv() throws VaultException {
final MockEnvironmentLoader mock = new MockEnvironmentLoader();
mock.override("VAULT_ADDR", "https://localhost:8200/");

final VaultConfig config = new VaultConfig()
.environmentLoader(mock)
.build();
assertEquals("https://localhost:8200", config.getAddress());
}

/**
* Test creating a new <code>VaultConfig</code> via its constructor, passing null address and token values AND
* having them unavailable in the environment variables too. This should cause initialization failure.
Expand Down