Search in sources :

Example 1 with BlockingHttpClient

use of io.micronaut.http.client.BlockingHttpClient in project micronaut-security by micronaut-projects.

the class LoggersTest method loggersEndpointIsAccessibleForUsersWithRoleROLE_SYSTEM.

@Test
void loggersEndpointIsAccessibleForUsersWithRoleROLE_SYSTEM() {
    BlockingHttpClient client = httpClient.toBlocking();
    HttpRequest<?> request = HttpRequest.GET("/loggers").basicAuth("system", "password");
    HttpResponse<Map> response = client.exchange(request, Argument.of(Map.class));
    assertEquals(HttpStatus.OK, response.status());
    Map m = response.body();
    assertTrue(m.containsKey("levels"));
    assertTrue(m.containsKey("loggers"));
}
Also used : BlockingHttpClient(io.micronaut.http.client.BlockingHttpClient) Map(java.util.Map) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 2 with BlockingHttpClient

use of io.micronaut.http.client.BlockingHttpClient in project micronaut-security by micronaut-projects.

the class LoggersTest method loggersEndpointIsSecured.

@Test
void loggersEndpointIsSecured() {
    BlockingHttpClient client = httpClient.toBlocking();
    Executable e = () -> client.exchange(HttpRequest.GET("/loggers"));
    HttpClientResponseException thrown = assertThrows(HttpClientResponseException.class, e);
    assertEquals(HttpStatus.UNAUTHORIZED, thrown.getStatus());
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) BlockingHttpClient(io.micronaut.http.client.BlockingHttpClient) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 3 with BlockingHttpClient

use of io.micronaut.http.client.BlockingHttpClient in project micronaut-security by micronaut-projects.

the class LoggersTest method healthEndpointIsNotSecured.

@Test
void healthEndpointIsNotSecured() {
    BlockingHttpClient client = httpClient.toBlocking();
    HttpResponse<?> response = client.exchange(HttpRequest.GET("/health"));
    assertEquals(HttpStatus.OK, response.status());
}
Also used : BlockingHttpClient(io.micronaut.http.client.BlockingHttpClient) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 4 with BlockingHttpClient

use of io.micronaut.http.client.BlockingHttpClient in project micronaut-security by micronaut-projects.

the class LoggersTest method loggersEndpointIsNotAccessibleForUsersWithoutRoleROLE_SYSTEM.

@Test
void loggersEndpointIsNotAccessibleForUsersWithoutRoleROLE_SYSTEM() {
    BlockingHttpClient client = httpClient.toBlocking();
    Executable e = () -> client.exchange(HttpRequest.GET("/loggers").basicAuth("user", "password"));
    HttpClientResponseException thrown = assertThrows(HttpClientResponseException.class, e);
    assertEquals(HttpStatus.FORBIDDEN, thrown.getStatus());
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) BlockingHttpClient(io.micronaut.http.client.BlockingHttpClient) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 5 with BlockingHttpClient

use of io.micronaut.http.client.BlockingHttpClient in project micronaut-security by micronaut-projects.

the class SensitiveEndpointRuleReplacementTest method testAccessingASensitiveEndpointWithAuthenticationAndASensitiveEndpointRuleReplacementWorks.

@Test
void testAccessingASensitiveEndpointWithAuthenticationAndASensitiveEndpointRuleReplacementWorks() {
    BlockingHttpClient client = httpClient.toBlocking();
    Executable e = () -> client.exchange(HttpRequest.GET("/beans"));
    HttpClientResponseException thrown = assertThrows(HttpClientResponseException.class, e);
    assertEquals(HttpStatus.UNAUTHORIZED, thrown.getStatus());
    e = () -> client.exchange(HttpRequest.GET("/beans").basicAuth("user", "password"));
    assertDoesNotThrow(e);
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) BlockingHttpClient(io.micronaut.http.client.BlockingHttpClient) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Aggregations

BlockingHttpClient (io.micronaut.http.client.BlockingHttpClient)17 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)17 Test (org.junit.jupiter.api.Test)17 FruitsController (io.micronaut.views.model.FruitsController)5 HttpClientResponseException (io.micronaut.http.client.exceptions.HttpClientResponseException)4 Executable (org.junit.jupiter.api.function.Executable)4 HttpClient (io.micronaut.http.client.HttpClient)2 EmbeddedServer (io.micronaut.runtime.server.EmbeddedServer)2 ConfigViewModelProcessor (io.micronaut.views.model.ConfigViewModelProcessor)2 UnmodifiableFruitsController (io.micronaut.views.model.UnmodifiableFruitsController)2 Map (java.util.Map)1