Search in sources :

Example 21 with ExecutionContext

use of io.gravitee.gateway.api.ExecutionContext in project gravitee-gateway by gravitee-io.

the class OAuth2AuthenticationHandlerTest method shouldReturnPolicies.

@Test
public void shouldReturnPolicies() {
    ExecutionContext executionContext = mock(ExecutionContext.class);
    List<AuthenticationPolicy> oauth2ProviderPolicies = authenticationHandler.handle(executionContext);
    Assert.assertEquals(2, oauth2ProviderPolicies.size());
    Iterator<AuthenticationPolicy> policyIte = oauth2ProviderPolicies.iterator();
    PluginAuthenticationPolicy policy = (PluginAuthenticationPolicy) policyIte.next();
    Assert.assertEquals(OAuth2AuthenticationHandler.AUTHENTICATION_HANDLER_NAME, policy.name());
    HookAuthenticationPolicy policy2 = (HookAuthenticationPolicy) policyIte.next();
    Assert.assertEquals(CheckSubscriptionPolicy.class, policy2.clazz());
}
Also used : ExecutionContext(io.gravitee.gateway.api.ExecutionContext) AuthenticationPolicy(io.gravitee.gateway.security.core.AuthenticationPolicy) HookAuthenticationPolicy(io.gravitee.gateway.security.core.HookAuthenticationPolicy) PluginAuthenticationPolicy(io.gravitee.gateway.security.core.PluginAuthenticationPolicy) HookAuthenticationPolicy(io.gravitee.gateway.security.core.HookAuthenticationPolicy) PluginAuthenticationPolicy(io.gravitee.gateway.security.core.PluginAuthenticationPolicy) Test(org.junit.Test)

Example 22 with ExecutionContext

use of io.gravitee.gateway.api.ExecutionContext in project gravitee-gateway by gravitee-io.

the class RequestPolicyChainTest method doNext_streamablePolicy.

@Test
public void doNext_streamablePolicy() throws Exception {
    StreamablePolicy policy4 = spy(new StreamablePolicy());
    ExecutionContext executionContext = mock(ExecutionContext.class);
    ReadWriteStream stream = spy(new BufferedReadWriteStream());
    when(policy4.onRequestContent(any(Request.class), any(Response.class), any(io.gravitee.policy.api.PolicyChain.class), eq(executionContext))).thenReturn(stream);
    PolicyChain chain = RequestPolicyChain.create(Collections.singletonList(policy4), executionContext);
    chain.setResultHandler(result -> {
    });
    chain.doNext(null, null);
    verify(stream, atLeastOnce()).bodyHandler(any(Handler.class));
    verify(stream, atLeastOnce()).endHandler(any(Handler.class));
    verify(policy4, atLeastOnce()).onRequest(null, null, chain, executionContext);
}
Also used : ReadWriteStream(io.gravitee.gateway.api.stream.ReadWriteStream) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Response(io.gravitee.gateway.api.Response) PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) RequestPolicyChain(io.gravitee.gateway.policy.impl.RequestPolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Request(io.gravitee.gateway.api.Request) Handler(io.gravitee.gateway.api.handler.Handler) Test(org.junit.Test)

Example 23 with ExecutionContext

use of io.gravitee.gateway.api.ExecutionContext in project gravitee-gateway by gravitee-io.

the class ResponsePolicyChainTest method doNext_streamablePolicies.

@Test
public void doNext_streamablePolicies() throws Exception {
    StreamablePolicy policy4 = spy(new StreamablePolicy());
    StreamablePolicy policy5 = spy(new StreamablePolicy());
    ExecutionContext executionContext = mock(ExecutionContext.class);
    ReadWriteStream streamPolicy4 = spy(new BufferedReadWriteStream());
    when(policy4.onResponseContent(any(Request.class), any(Response.class), any(io.gravitee.policy.api.PolicyChain.class), eq(executionContext))).thenReturn(streamPolicy4);
    ReadWriteStream streamPolicy5 = spy(new BufferedReadWriteStream());
    when(policy5.onResponseContent(any(Request.class), any(Response.class), any(io.gravitee.policy.api.PolicyChain.class), eq(executionContext))).thenReturn(streamPolicy5);
    InOrder inOrder = inOrder(streamPolicy4, streamPolicy5);
    PolicyChain chain = ResponsePolicyChain.create(Arrays.asList(policy4, policy5), executionContext);
    chain.setResultHandler(result -> {
    });
    chain.doNext(null, null);
    inOrder.verify(streamPolicy4, atLeastOnce()).bodyHandler(any(Handler.class));
    inOrder.verify(streamPolicy4, atLeastOnce()).endHandler(any(Handler.class));
    inOrder.verify(streamPolicy5, atLeastOnce()).bodyHandler(any(Handler.class));
    inOrder.verify(streamPolicy5, atLeastOnce()).endHandler(any(Handler.class));
    verify(policy4, atLeastOnce()).onResponse(null, null, chain, executionContext);
}
Also used : ReadWriteStream(io.gravitee.gateway.api.stream.ReadWriteStream) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Response(io.gravitee.gateway.api.Response) PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) ResponsePolicyChain(io.gravitee.gateway.policy.impl.ResponsePolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) InOrder(org.mockito.InOrder) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Request(io.gravitee.gateway.api.Request) Handler(io.gravitee.gateway.api.handler.Handler) Test(org.junit.Test)

Example 24 with ExecutionContext

use of io.gravitee.gateway.api.ExecutionContext in project gravitee-gateway by gravitee-io.

the class ResponsePolicyChainTest method doNext_multiplePolicy.

@Test
public void doNext_multiplePolicy() throws Exception {
    ExecutionContext executionContext = mock(ExecutionContext.class);
    PolicyChain chain = ResponsePolicyChain.create(Arrays.asList(policy, policy2), executionContext);
    chain.setResultHandler(result -> {
    });
    chain.doNext(null, null);
    verify(policy, atLeastOnce()).onResponse(null, null, chain, executionContext);
    verify(policy2, atLeastOnce()).onResponse(null, null, chain, executionContext);
}
Also used : PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) ResponsePolicyChain(io.gravitee.gateway.policy.impl.ResponsePolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) Test(org.junit.Test)

Example 25 with ExecutionContext

use of io.gravitee.gateway.api.ExecutionContext in project gravitee-gateway by gravitee-io.

the class ResponsePolicyChainTest method doNext_streamablePolicies_streaming.

@Test
public void doNext_streamablePolicies_streaming() throws Exception {
    StreamablePolicy policy4 = spy(new StreamablePolicy());
    StreamablePolicy policy5 = spy(new StreamablePolicy());
    ExecutionContext executionContext = mock(ExecutionContext.class);
    ReadWriteStream streamPolicy4 = spy(new BufferedReadWriteStream());
    when(policy4.onResponseContent(any(Request.class), any(Response.class), any(io.gravitee.policy.api.PolicyChain.class), eq(executionContext))).thenReturn(streamPolicy4);
    ReadWriteStream streamPolicy5 = spy(new BufferedReadWriteStream());
    when(policy5.onResponseContent(any(Request.class), any(Response.class), any(io.gravitee.policy.api.PolicyChain.class), eq(executionContext))).thenReturn(streamPolicy5);
    InOrder inOrder = inOrder(streamPolicy4, streamPolicy5);
    PolicyChain chain = ResponsePolicyChain.create(Arrays.asList(policy4, policy5), executionContext);
    chain.setResultHandler(result -> {
    });
    chain.bodyHandler(mock(Handler.class));
    chain.endHandler(mock(Handler.class));
    chain.doNext(null, null);
    chain.write(Buffer.buffer("TEST"));
    chain.write(Buffer.buffer("TEST"));
    chain.end();
    inOrder.verify(streamPolicy4, atLeastOnce()).bodyHandler(any(Handler.class));
    inOrder.verify(streamPolicy4, atLeastOnce()).endHandler(any(Handler.class));
    inOrder.verify(streamPolicy5, atLeastOnce()).bodyHandler(any(Handler.class));
    inOrder.verify(streamPolicy5, atLeastOnce()).endHandler(any(Handler.class));
    verify(policy4, atLeastOnce()).onResponse(null, null, chain, executionContext);
}
Also used : ReadWriteStream(io.gravitee.gateway.api.stream.ReadWriteStream) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Response(io.gravitee.gateway.api.Response) PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) ResponsePolicyChain(io.gravitee.gateway.policy.impl.ResponsePolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) InOrder(org.mockito.InOrder) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Request(io.gravitee.gateway.api.Request) Handler(io.gravitee.gateway.api.handler.Handler) Test(org.junit.Test)

Aggregations

ExecutionContext (io.gravitee.gateway.api.ExecutionContext)28 Request (io.gravitee.gateway.api.Request)22 Test (org.junit.Test)21 Response (io.gravitee.gateway.api.Response)19 PolicyChain (io.gravitee.gateway.policy.impl.PolicyChain)12 Handler (io.gravitee.gateway.api.handler.Handler)9 PolicyChain (io.gravitee.policy.api.PolicyChain)9 SubscriptionRepository (io.gravitee.repository.management.api.SubscriptionRepository)7 SubscriptionCriteria (io.gravitee.repository.management.api.search.SubscriptionCriteria)7 BufferedReadWriteStream (io.gravitee.gateway.api.stream.BufferedReadWriteStream)6 ReadWriteStream (io.gravitee.gateway.api.stream.ReadWriteStream)6 ResponsePolicyChain (io.gravitee.gateway.policy.impl.ResponsePolicyChain)6 RequestPolicyChain (io.gravitee.gateway.policy.impl.RequestPolicyChain)5 Subscription (io.gravitee.repository.management.model.Subscription)5 AuthenticationPolicy (io.gravitee.gateway.security.core.AuthenticationPolicy)4 PluginAuthenticationPolicy (io.gravitee.gateway.security.core.PluginAuthenticationPolicy)4 InOrder (org.mockito.InOrder)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 HttpHeaders (io.gravitee.common.http.HttpHeaders)3 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)3