Do not inject base URI components to absolute URIs.
PrefixAwareUriBuilderFactory now no longer injects components from a base URI into a URI that is considered an absolute one (URI starting with https: or http: protocol schemes). Resolves gh-377.
This commit is contained in:
@@ -191,6 +191,10 @@ public class VaultClients {
|
||||
@Override
|
||||
public UriBuilder uriString(String uriTemplate) {
|
||||
|
||||
if (uriTemplate.startsWith("http:") || uriTemplate.startsWith("https:")) {
|
||||
return UriComponentsBuilder.fromUriString(uriTemplate);
|
||||
}
|
||||
|
||||
VaultEndpoint endpoint = endpointProvider.getVaultEndpoint();
|
||||
|
||||
String baseUri = toBaseUri(endpoint);
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.vault.client.VaultClients.PrefixAwareUriBuilderFactory;
|
||||
import org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -32,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class VaultClientsUnitTests {
|
||||
|
||||
@Test
|
||||
public void shouldPrefixRelativeUrl() {
|
||||
public void uriHandlerShouldPrefixRelativeUrl() {
|
||||
|
||||
VaultEndpoint localhost = VaultEndpoint.create("localhost", 8200);
|
||||
PrefixAwareUriTemplateHandler handler = new PrefixAwareUriTemplateHandler(
|
||||
@@ -44,7 +45,7 @@ public class VaultClientsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotPrefixAbsoluteUrl() {
|
||||
public void uriHandlerShouldNotPrefixAbsoluteUrl() {
|
||||
|
||||
VaultEndpoint localhost = VaultEndpoint.create("localhost", 8200);
|
||||
PrefixAwareUriTemplateHandler handler = new PrefixAwareUriTemplateHandler(
|
||||
@@ -55,4 +56,29 @@ public class VaultClientsUnitTests {
|
||||
assertThat(uri).hasScheme("https").hasHost("foo").hasPort(-1)
|
||||
.hasPath("/path/bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriBuilderShouldPrefixRelativeUrl() {
|
||||
|
||||
VaultEndpoint localhost = VaultEndpoint.create("localhost", 8200);
|
||||
PrefixAwareUriBuilderFactory handler = new PrefixAwareUriBuilderFactory(
|
||||
() -> localhost);
|
||||
|
||||
URI uri = handler.expand("/path/{bar}", "bar");
|
||||
|
||||
assertThat(uri).hasHost("localhost").hasPort(8200).hasPath("/v1/path/bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriBuilderShouldNotPrefixAbsoluteUrl() {
|
||||
|
||||
VaultEndpoint localhost = VaultEndpoint.create("localhost", 8200);
|
||||
PrefixAwareUriBuilderFactory handler = new PrefixAwareUriBuilderFactory(
|
||||
() -> localhost);
|
||||
|
||||
URI uri = handler.expand("https://foo/path/{bar}", "bar");
|
||||
|
||||
assertThat(uri).hasScheme("https").hasHost("foo").hasPort(-1)
|
||||
.hasPath("/path/bar");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user