use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class OAuth2AuthenticationHandlerTest method shouldHandleRequest_validAuthorizationHeader.
@Test
public void shouldHandleRequest_validAuthorizationHeader() {
HttpHeaders headers = new HttpHeaders();
Request request = mock(Request.class);
when(request.headers()).thenReturn(headers);
headers.add(HttpHeaders.AUTHORIZATION, OAuth2AuthenticationHandler.BEARER_AUTHORIZATION_TYPE + " 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_invalidAuthorizationHeader.
@Test
public void shouldNotHandleRequest_invalidAuthorizationHeader() {
HttpHeaders headers = new HttpHeaders();
Request request = mock(Request.class);
when(request.headers()).thenReturn(headers);
headers.add(HttpHeaders.AUTHORIZATION, "");
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 onRequest_mockParameters.
@Test
public void onRequest_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 onRequestMethod = resolvePolicyMethod(DummyPolicy.class, OnRequest.class);
when(policyDefinition.method(OnRequest.class)).thenReturn(onRequestMethod);
Policy policy = PolicyImpl.target(policyInst).definition(policyDefinition).build();
Request mockRequest = mock(Request.class);
Response mockResponse = mock(Response.class);
policy.onRequest(mockRequest, mockResponse);
verify(policyInst, atLeastOnce()).onRequest(any(PolicyChain.class), eq(mockRequest), eq(mockResponse));
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class ReactorHandlerResolverTest method test_uniqContextPath_unknownRequestPath.
@Test
public void test_uniqContextPath_unknownRequestPath() {
Collection<ReactorHandler> handlers = new ArrayList<>(new ArrayList<ReactorHandler>() {
{
add(createMockHandler("/teams"));
}
});
when(handlerRegistry.getReactorHandlers()).thenReturn(handlers);
Request request = Mockito.mock(Request.class);
when(request.path()).thenReturn("/team");
ReactorHandler handler = handlerResolver.resolve(request);
Assert.assertNull(handler);
}
use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.
the class ReactorHandlerResolverTest method test_multipleContextPath_extraSeparatorUnknownRequestPath.
@Test
public void test_multipleContextPath_extraSeparatorUnknownRequestPath() {
Collection<ReactorHandler> handlers = new ArrayList<>(new ArrayList<ReactorHandler>() {
{
add(createMockHandler("/teams2"));
add(createMockHandler("/teams"));
}
});
when(handlerRegistry.getReactorHandlers()).thenReturn(handlers);
Request request = Mockito.mock(Request.class);
Mockito.when(request.path()).thenReturn("/teamss/");
ReactorHandler handler = handlerResolver.resolve(request);
Assert.assertNull(handler);
}
Aggregations