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());
}
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());
}
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());
}
}
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());
}
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());
}
Aggregations