use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class WebSecurityBuilderGateDefaultsTest method testForbidden.
private void testForbidden(String uri, String username, String password) throws ExecutionException, InterruptedException {
WebClientResponse response = callProtected(uri, username, password);
assertThat(uri + " for user " + username + " should be forbidden", response.status(), is(Http.Status.FORBIDDEN_403));
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class WebSecurityBuilderGateDefaultsTest method testProtected.
private void testProtected(String uri, String username, String password, Set<String> expectedRoles, Set<String> invalidRoles) throws ExecutionException, InterruptedException {
WebClientResponse response = callProtected(uri, username, password);
assertThat(response.status(), is(Http.Status.OK_200));
response.content().as(String.class).thenAccept(it -> {
// check login
assertThat(it, containsString("id='" + username + "'"));
// check roles
expectedRoles.forEach(role -> assertThat(it, containsString(":" + role)));
invalidRoles.forEach(role -> assertThat(it, not(containsString(":" + role))));
}).toCompletableFuture().get();
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class WebSecurityBuilderGateDefaultsTest method basicTest401.
@Test
public void basicTest401() throws ExecutionException, InterruptedException {
// here we call the endpoint
webClient.get().uri(serverBaseUri + "/noRoles").request().thenAccept(it -> {
assertThat(it.status(), is(Http.Status.UNAUTHORIZED_401));
it.headers().first(Http.Header.WWW_AUTHENTICATE).ifPresentOrElse(header -> assertThat(header.toLowerCase(), is("basic realm=\"mic\"")), () -> {
throw new IllegalStateException("Header " + Http.Header.WWW_AUTHENTICATE + " is" + " not present in response!");
});
}).toCompletableFuture().get();
WebClientResponse webClientResponse = callProtected(serverBaseUri + "/noRoles", "invalidUser", "invalidPassword");
assertThat(webClientResponse.status(), is(Http.Status.UNAUTHORIZED_401));
webClientResponse.headers().first(Http.Header.WWW_AUTHENTICATE).ifPresentOrElse(header -> assertThat(header.toLowerCase(), is("basic realm=\"mic\"")), () -> {
throw new IllegalStateException("Header " + Http.Header.WWW_AUTHENTICATE + " is" + " not present in response!");
});
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class LifeCycleExtension method shutdown.
/**
* Shutdown test application
*/
public void shutdown() {
WebClient testClient = WebClient.builder().baseUri(String.format("http://localhost:%d", HelidonProcessRunner.HTTP_PORT)).build();
WebClientResponse response = testClient.get().path("/Exit").submit().await(1, TimeUnit.MINUTES);
LOGGER.info(() -> String.format("Status: %s", response.status()));
LOGGER.info(() -> String.format("Response: %s", response.content().as(String.class).await(1, TimeUnit.MINUTES)));
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class ContextCheckTest method testContextCheck.
@Test
void testContextCheck() {
WebClient webClient = createNewClient();
WebClientResponse r = webClient.get().path("/contextCheck").property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, "jack").property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, "password").request().await();
assertThat(r.status().code(), is(Http.Status.OK_200.code()));
}
Aggregations