Search in sources :

Example 16 with Request

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);
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 17 with Request

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);
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 18 with Request

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));
}
Also used : PolicyImpl(io.gravitee.gateway.policy.impl.PolicyImpl) OnResponse(io.gravitee.policy.api.annotations.OnResponse) OnRequest(io.gravitee.policy.api.annotations.OnRequest) ReflectionUtils.withAnnotation(org.reflections.ReflectionUtils.withAnnotation) PolicyFactoryImpl(io.gravitee.gateway.policy.impl.PolicyFactoryImpl) Set(java.util.Set) Test(org.junit.Test) ReflectionUtils.withModifier(org.reflections.ReflectionUtils.withModifier) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) Response(io.gravitee.gateway.api.Response) Request(io.gravitee.gateway.api.Request) Modifier(java.lang.reflect.Modifier) PolicyChain(io.gravitee.policy.api.PolicyChain) Annotation(java.lang.annotation.Annotation) ReflectionUtils(org.reflections.ReflectionUtils) Method(java.lang.reflect.Method) Before(org.junit.Before) OnResponse(io.gravitee.policy.api.annotations.OnResponse) Response(io.gravitee.gateway.api.Response) PolicyChain(io.gravitee.policy.api.PolicyChain) OnRequest(io.gravitee.policy.api.annotations.OnRequest) Request(io.gravitee.gateway.api.Request) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 19 with Request

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);
}
Also used : ArrayList(java.util.ArrayList) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 20 with Request

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);
}
Also used : ArrayList(java.util.ArrayList) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Aggregations

Request (io.gravitee.gateway.api.Request)51 Test (org.junit.Test)42 HttpHeaders (io.gravitee.common.http.HttpHeaders)24 Response (io.gravitee.gateway.api.Response)21 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)16 PolicyChain (io.gravitee.policy.api.PolicyChain)11 ArrayList (java.util.ArrayList)8 SubscriptionRepository (io.gravitee.repository.management.api.SubscriptionRepository)7 SubscriptionCriteria (io.gravitee.repository.management.api.search.SubscriptionCriteria)7 Metrics (io.gravitee.reporter.api.http.Metrics)6 Before (org.junit.Before)6 Subscription (io.gravitee.repository.management.model.Subscription)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 UUID (io.gravitee.common.utils.UUID)4 Handler (io.gravitee.gateway.api.handler.Handler)4 TimeUnit (java.util.concurrent.TimeUnit)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertNotNull (org.junit.Assert.assertNotNull)4 Mock (org.mockito.Mock)4 Mockito.when (org.mockito.Mockito.when)4