Skip to content

Commit 36c9465

Browse files
Merge pull request #132 from BrianDeacon/master
Normalize the address for VaultConfig for consistent pathing downstream.
2 parents f6321bc + a90f8c8 commit 36c9465

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/main/java/com/bettercloud/vault/VaultConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ public VaultConfig engineVersion(final Integer globalEngineVersion) {
108108
* @return This object, with address populated, ready for additional builder-pattern method calls or else finalization with the build() method
109109
*/
110110
public VaultConfig address(final String address) {
111-
this.address = address;
111+
this.address = address.trim();
112+
if (this.address.endsWith("/")) {
113+
this.address = this.address.substring(0, this.address.length() - 1);
114+
}
112115
return this;
113116
}
114117

src/test/java/com/bettercloud/vault/VaultConfigTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ public void testConfigConstructor() throws VaultException {
9696
assertEquals("token", config.getToken());
9797
}
9898

99+
/**
100+
* Test creating a new <code>VaultConfig</code> via its constructor, ensuring that addresses are normalized to
101+
* not have a trailing slash.
102+
*
103+
* @throws VaultException
104+
*/
105+
@Test
106+
public void testConfigConstructor_NormalizesAddress() throws VaultException {
107+
final VaultConfig config = new VaultConfig().address("https://localhost:8200/").build();
108+
assertEquals("https://localhost:8200", config.getAddress());
109+
}
110+
99111
/**
100112
* Test creating a new <code>VaultConfig</code> via its constructor, passing null address and token values AND
101113
* having them unavailable in the environment variables too. This should cause initialization failure.

0 commit comments

Comments
 (0)