use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MutualTlsTest method testClientAndServerUpdateTls.
@Test
public void testClientAndServerUpdateTls() {
int portSecured = webServer.port("secured");
int portDefault = webServer.port();
WebClient webClientFirst = createWebClient(CONFIG.get("success"));
WebClient webClientSecond = createWebClient(CONFIG.get("client-second-valid"));
assertThat(executeRequest(webClientFirst, "https", portSecured), is("Hello Helidon-client!"));
CompletionException exception = assertThrows(CompletionException.class, () -> executeRequest(webClientSecond, "https", portSecured));
assertThat(exception.getCause().getMessage(), endsWith("unable to find valid certification path to requested target"));
String response = webClientFirst.get().uri("http://localhost:" + portDefault + "/reload").request(String.class).await();
assertThat(response, is("SslContext reloaded. Affected named socket: secured"));
assertThat(executeRequest(webClientSecond, "https", portSecured), is("Hello Oracle-client!"));
exception = assertThrows(CompletionException.class, () -> executeRequest(webClientFirst, "https", portSecured));
assertThat(exception.getCause().getMessage(), endsWith("unable to find valid certification path to requested target"));
response = webClientFirst.get().uri("http://localhost:" + portDefault + "/reload").request(String.class).await();
assertThat(response, is("SslContext reloaded. Affected named socket: secured"));
assertThat(executeRequest(webClientFirst, "https", portSecured), is("Hello Helidon-client!"));
exception = assertThrows(CompletionException.class, () -> executeRequest(webClientSecond, "https", portSecured));
assertThat(exception.getCause().getMessage(), endsWith("unable to find valid certification path to requested target"));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MutualTlsTest method testClientNoCa.
@Test
public void testClientNoCa() {
int port = webServer.port("client-no-ca");
WebClient webClientOne = createWebClient(CONFIG.get("client-no-ca"));
CompletionException exception = assertThrows(CompletionException.class, () -> executeRequest(webClientOne, "https", port));
assertThat(exception.getCause().getMessage(), endsWith("unable to find valid certification path to requested target"));
WebClient webClientTwo = createWebClient(CONFIG.get("client-trust-all"));
assertThat(executeRequest(webClientTwo, "https", port), is("Hello Helidon-client!"));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MutualTlsTest method testAccessSuccessful.
@Test
public void testAccessSuccessful() {
WebClient webClient = createWebClient(CONFIG.get("success"));
String result = webClient.get().uri("http://localhost:" + webServer.port()).request(String.class).await();
assertThat(result, is("Hello world unsecured!"));
assertThat(executeRequest(webClient, "https", webServer.port("secured")), is("Hello Helidon-client!"));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class TestParent method createNewClient.
protected static WebClient createNewClient(WebClientService... clientServices) {
Security security = Security.builder().addProvider(HttpBasicAuthProvider.builder().build()).build();
SecurityContext securityContext = security.createContext("unit-test");
Context context = Context.builder().id("unit-test").build();
context.register(securityContext);
WebClient.Builder builder = WebClient.builder().baseUri("http://localhost:" + webServer.port() + "/greet").config(CONFIG.get("client")).context(context).addMediaSupport(JsonpSupport.create());
Stream.of(clientServices).forEach(builder::addService);
return builder.build();
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class UriPartTest method testQueryNotDoubleEncoded.
@Test
public void testQueryNotDoubleEncoded() {
WebClient webClient = createNewClient(request -> {
assertThat(request.query(), is("first%26second%26=val%26ue%26"));
return Single.just(request);
});
String response = webClient.get().queryParam("first&second%26", "val&ue%26").request(String.class).await();
assertThat(response.trim(), is("{\"message\":\"Hello World!\"}"));
}
Aggregations