Search in sources :

Example 6 with Response

use of jakarta.ws.rs.core.Response in project OpenGrok by OpenGrok.

the class SuggesterControllerTest method testAllowedFields.

@Test
void testAllowedFields() {
    env.getSuggesterConfig().setAllowedFields(Collections.singleton(QueryBuilder.DEFS));
    Response r = target(SuggesterController.PATH).queryParam(AuthorizationFilter.PROJECTS_PARAM, "java", "kotlin").queryParam("field", QueryBuilder.FULL).queryParam(QueryBuilder.FULL, "me").request().get();
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), r.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) Test(org.junit.jupiter.api.Test)

Example 7 with Response

use of jakarta.ws.rs.core.Response in project OpenGrok by OpenGrok.

the class IncomingFilterTest method nonLocalhostTestWithTokenChange.

@Test
public void nonLocalhostTestWithTokenChange() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String token = "foobar";
    Map<String, String> headers = new TreeMap<>();
    final String authHeaderValue = IncomingFilter.BEARER + token;
    headers.put(HttpHeaders.AUTHORIZATION, authHeaderValue);
    assertTrue(env.getAuthenticationTokens().isEmpty());
    IncomingFilter filter = mockWithRemoteAddress("192.168.1.1", headers, true);
    ContainerRequestContext context = mockContainerRequestContext("test");
    ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    // No tokens configured.
    filter.filter(context);
    verify(context).abortWith(captor.capture());
    // Setting tokens without refreshing configuration should have no effect.
    Set<String> tokens = new HashSet<>();
    tokens.add(token);
    env.setAuthenticationTokens(tokens);
    filter.filter(context);
    verify(context, times(2)).abortWith(captor.capture());
    // The request should pass only after applyConfig().
    env.applyConfig(false, CommandTimeoutType.RESTFUL);
    context = mockContainerRequestContext("test");
    filter.filter(context);
    verify(context, never()).abortWith(captor.capture());
}
Also used : Response(jakarta.ws.rs.core.Response) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) ContainerRequestContext(jakarta.ws.rs.container.ContainerRequestContext) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 8 with Response

use of jakarta.ws.rs.core.Response in project OpenGrok by OpenGrok.

the class IncomingFilterTest method nonLocalhostTestWithToken.

private void nonLocalhostTestWithToken(boolean allowed, String token) throws Exception {
    Map<String, String> headers = new TreeMap<>();
    final String authHeaderValue = IncomingFilter.BEARER + token;
    headers.put(HttpHeaders.AUTHORIZATION, authHeaderValue);
    IncomingFilter filter = mockWithRemoteAddress("192.168.1.1", headers, true);
    ContainerRequestContext context = mockContainerRequestContext("test");
    ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    filter.filter(context);
    if (allowed) {
        verify(context, never()).abortWith(captor.capture());
    } else {
        verify(context).abortWith(captor.capture());
    }
}
Also used : Response(jakarta.ws.rs.core.Response) ContainerRequestContext(jakarta.ws.rs.container.ContainerRequestContext) TreeMap(java.util.TreeMap)

Example 9 with Response

use of jakarta.ws.rs.core.Response in project OpenGrok by OpenGrok.

the class IncomingFilterTest method nonLocalhostTestWithoutToken.

@Test
public void nonLocalhostTestWithoutToken() throws Exception {
    IncomingFilter filter = mockWithRemoteAddress("192.168.1.1");
    ContainerRequestContext context = mockContainerRequestContext("test");
    ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    filter.filter(context);
    verify(context).abortWith(captor.capture());
    assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), captor.getValue().getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) ContainerRequestContext(jakarta.ws.rs.container.ContainerRequestContext) Test(org.junit.jupiter.api.Test)

Example 10 with Response

use of jakarta.ws.rs.core.Response in project OpenGrok by OpenGrok.

the class MessagesControllerTest method addMessageWithInvalidLevel.

@Test
public void addMessageWithInvalidLevel() throws JsonProcessingException {
    // Construct correct Message object first.
    Message msg = new Message("message with broken message level", Collections.singleton(MessagesContainer.MESSAGES_MAIN_PAGE_TAG), Message.MessageLevel.INFO, Duration.ofMinutes(10));
    // Convert it to JSON string and replace the messageLevel value.
    ObjectMapper objectMapper = new ObjectMapper();
    final String invalidMessageLevel = "invalid";
    String msgAsString = objectMapper.writeValueAsString(msg);
    msgAsString = msgAsString.replaceAll(Message.MessageLevel.INFO.toString(), invalidMessageLevel);
    assertTrue(msgAsString.contains(invalidMessageLevel));
    // Finally, send the request as JSON string.
    Response r = target("messages").request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(msgAsString));
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) AcceptedMessage(org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage) Message(org.opengrok.indexer.web.messages.Message) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

Response (jakarta.ws.rs.core.Response)665 Test (org.junit.jupiter.api.Test)551 AsyncInvoker (jakarta.ws.rs.client.AsyncInvoker)78 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)71 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)67 Invocation (jakarta.ws.rs.client.Invocation)65 CompletionStageRxInvoker (jakarta.ws.rs.client.CompletionStageRxInvoker)51 Path (jakarta.ws.rs.Path)44 IOException (java.io.IOException)43 SyncInvoker (jakarta.ws.rs.client.SyncInvoker)41 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)33 POST (jakarta.ws.rs.POST)27 Client (jakarta.ws.rs.client.Client)25 WebTarget (jakarta.ws.rs.client.WebTarget)24 Link (jakarta.ws.rs.core.Link)23 Status (jakarta.ws.rs.core.Response.Status)23 MediaType (jakarta.ws.rs.core.MediaType)22 Annotation (java.lang.annotation.Annotation)22 Date (java.util.Date)21 GET (jakarta.ws.rs.GET)18