use of jakarta.ws.rs.container.ContainerRequestContext in project OpenGrok by OpenGrok.
the class CorsFilterTest method testBoth.
private void testBoth(String origin, List<Object> headerValue) {
CorsFilter filter = new CorsFilter();
ContainerRequestContext request = mock(ContainerRequestContext.class);
when(request.getHeaderString(CORS_REQUEST_HEADER)).thenReturn(origin);
ContainerResponseContext response = mock(ContainerResponseContext.class);
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
when(response.getHeaders()).thenReturn(headers);
filter.filter(request, response);
assertEquals(headerValue, headers.get(ALLOW_CORS_HEADER));
}
use of jakarta.ws.rs.container.ContainerRequestContext 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.container.ContainerRequestContext 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.container.ContainerRequestContext 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.container.ContainerRequestContext in project OpenGrok by OpenGrok.
the class IncomingFilterTest method mockContainerRequestContext.
private ContainerRequestContext mockContainerRequestContext(final String path) {
ContainerRequestContext context = mock(ContainerRequestContext.class);
UriInfo info = mock(UriInfo.class);
when(info.getPath()).thenReturn(path);
when(context.getUriInfo()).thenReturn(info);
return context;
}
Aggregations