Search in sources :

Example 1 with PrefixAwareUriTemplateHandler

use of org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler in project spring-vault by spring-projects.

the class VaultClientsUnitTests method shouldAllowNamespaceOverride.

@Test
void shouldAllowNamespaceOverride() {
    RestTemplate restTemplate = VaultClients.createRestTemplate();
    restTemplate.getInterceptors().add(VaultClients.createNamespaceInterceptor("foo/bar"));
    restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());
    MockRestServiceServer mockRest = MockRestServiceServer.createServer(restTemplate);
    mockRest.expect(requestTo("/auth/foo")).andExpect(method(HttpMethod.GET)).andExpect(header(VaultHttpHeaders.VAULT_NAMESPACE, "baz")).andRespond(withSuccess());
    HttpHeaders headers = new HttpHeaders();
    headers.add(VaultHttpHeaders.VAULT_NAMESPACE, "baz");
    restTemplate.exchange("/auth/foo", HttpMethod.GET, new HttpEntity<>(headers), String.class);
}
Also used : PrefixAwareUriTemplateHandler(org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler) HttpHeaders(org.springframework.http.HttpHeaders) RestTemplate(org.springframework.web.client.RestTemplate) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) Test(org.junit.jupiter.api.Test)

Example 2 with PrefixAwareUriTemplateHandler

use of org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler in project spring-vault by spring-projects.

the class VaultClientsUnitTests method uriHandlerShouldNotPrefixAbsoluteUrl.

@Test
void uriHandlerShouldNotPrefixAbsoluteUrl() {
    VaultEndpoint localhost = VaultEndpoint.create("localhost", 8200);
    PrefixAwareUriTemplateHandler handler = new PrefixAwareUriTemplateHandler(() -> localhost);
    URI uri = handler.expand("https://foo/path/{bar}", "bar");
    assertThat(uri).hasScheme("https").hasHost("foo").hasPort(-1).hasPath("/path/bar");
}
Also used : PrefixAwareUriTemplateHandler(org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 3 with PrefixAwareUriTemplateHandler

use of org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler in project spring-vault by spring-projects.

the class LoginTokenAdapterUnitTests method before.

@BeforeEach
void before() throws Exception {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());
    this.mockRest = MockRestServiceServer.createServer(restTemplate);
    this.restTemplate = restTemplate;
}
Also used : PrefixAwareUriTemplateHandler(org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler) RestTemplate(org.springframework.web.client.RestTemplate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with PrefixAwareUriTemplateHandler

use of org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler in project spring-vault by spring-projects.

the class ClientCertificateAuthenticationUnitTests method before.

@BeforeEach
void before() {
    RestTemplate restTemplate = VaultClients.createRestTemplate();
    restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());
    this.mockRest = MockRestServiceServer.createServer(restTemplate);
    this.restTemplate = restTemplate;
}
Also used : PrefixAwareUriTemplateHandler(org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler) RestTemplate(org.springframework.web.client.RestTemplate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with PrefixAwareUriTemplateHandler

use of org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler in project spring-vault by spring-projects.

the class CubbyholeAuthenticationUnitTests method before.

@BeforeEach
void before() {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());
    this.mockRest = MockRestServiceServer.createServer(restTemplate);
    this.restTemplate = restTemplate;
}
Also used : PrefixAwareUriTemplateHandler(org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler) RestTemplate(org.springframework.web.client.RestTemplate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

PrefixAwareUriTemplateHandler (org.springframework.vault.client.VaultClients.PrefixAwareUriTemplateHandler)18 RestTemplate (org.springframework.web.client.RestTemplate)15 BeforeEach (org.junit.jupiter.api.BeforeEach)13 Test (org.junit.jupiter.api.Test)5 URI (java.net.URI)3 MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)2 HttpHeaders (org.springframework.http.HttpHeaders)1