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:
@@ -219,6 +219,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);
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
import org.springframework.vault.client.VaultClients.PrefixAwareUriBuilderFactory;
|
||||
import org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@@ -40,7 +41,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
public class VaultClientsUnitTests {
|
||||
|
||||
@Test
|
||||
public void shouldPrefixRelativeUrl() {
|
||||
public void uriHandlerShouldPrefixRelativeUrl() {
|
||||
|
||||
VaultEndpoint localhost = VaultEndpoint.create("localhost", 8200);
|
||||
PrefixAwareUriTemplateHandler handler = new PrefixAwareUriTemplateHandler(
|
||||
@@ -52,7 +53,7 @@ public class VaultClientsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotPrefixAbsoluteUrl() {
|
||||
public void uriHandlerShouldNotPrefixAbsoluteUrl() {
|
||||
|
||||
VaultEndpoint localhost = VaultEndpoint.create("localhost", 8200);
|
||||
PrefixAwareUriTemplateHandler handler = new PrefixAwareUriTemplateHandler(
|
||||
@@ -64,6 +65,31 @@ public class VaultClientsUnitTests {
|
||||
.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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldApplyNamespace() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user