use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class OAuth2AuthenticationHandlerTest method shouldHandleRequest_ignoreCaseAuthorizationHeader.
@Test
public void shouldHandleRequest_ignoreCaseAuthorizationHeader() {
HttpHeaders headers = new HttpHeaders();
Request request = mock(Request.class);
when(request.headers()).thenReturn(headers);
headers.add(HttpHeaders.AUTHORIZATION, "BeaRer xxx-xx-xxx-xx-xx");
boolean handle = authenticationHandler.canHandle(request);
Assert.assertTrue(handle);
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class OAuth2AuthenticationHandlerTest method shouldNotHandleRequest_noBearerValue.
@Test
public void shouldNotHandleRequest_noBearerValue() {
HttpHeaders headers = new HttpHeaders();
Request request = mock(Request.class);
when(request.headers()).thenReturn(headers);
headers.add(HttpHeaders.AUTHORIZATION, OAuth2AuthenticationHandler.BEARER_AUTHORIZATION_TYPE + " ");
boolean handle = authenticationHandler.canHandle(request);
Assert.assertFalse(handle);
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class OAuth2AuthenticationHandlerTest method shouldNotHandleRequest_noAuthorizationHeader.
@Test
public void shouldNotHandleRequest_noAuthorizationHeader() {
Request request = mock(Request.class);
when(request.headers()).thenReturn(new HttpHeaders());
boolean handle = authenticationHandler.canHandle(request);
Assert.assertFalse(handle);
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class PolicyTest method onResponse_mockParameters.
@Test
public void onResponse_mockParameters() throws Exception {
PolicyMetadata policyDefinition = mock(PolicyMetadata.class);
when(policyDefinition.policy()).then((Answer<Class>) invocationOnMock -> DummyPolicy.class);
DummyPolicy policyInst = Mockito.spy((DummyPolicy) policyFactory.create(policyDefinition, null));
Method onResponseMethod = resolvePolicyMethod(DummyPolicy.class, OnResponse.class);
when(policyDefinition.method(OnResponse.class)).thenReturn(onResponseMethod);
Policy policy = PolicyImpl.target(policyInst).definition(policyDefinition).build();
Request mockRequest = mock(Request.class);
Response mockResponse = mock(Response.class);
policy.onResponse(mockRequest, mockResponse);
verify(policyInst, atLeastOnce()).onResponse(eq(mockRequest), eq(mockResponse), any(PolicyChain.class));
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class DefaultReactor method route.
@Override
public void route(Request serverRequest, Response serverResponse, final Handler<Response> handler) {
LOGGER.debug("Receiving a request {} for path {}", serverRequest.id(), serverRequest.path());
// Prepare handler chain
Handler<Request> requestHandlerChain = transactionHandlerFactory.create(request -> {
ReactorHandler reactorHandler = reactorHandlerResolver.resolve(request);
if (reactorHandler != null) {
// Prepare the handler chain
Handler<Response> responseHandlerChain = new ResponseTimeHandler(request, new ReporterHandler(reporterService, request, handler));
reactorHandler.handle(request, serverResponse, responseHandlerChain);
} else {
LOGGER.debug("No handler can be found for request {}, returning NOT_FOUND (404)", request.path());
sendNotFound(serverResponse, handler);
}
}, serverResponse);
// Set gateway tenant
serverRequest.metrics().setTenant(gatewayConfiguration.tenant().orElse(null));
// And handle the request
requestHandlerChain.handle(serverRequest);
}
Aggregations