Search in sources :

Example 11 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain in project gravitee-gateway by gravitee-io.

the class SecurityPolicyChainResolverTest method shouldReturnUnauthorizedPolicyChain_onRequest.

@Test
public void shouldReturnUnauthorizedPolicyChain_onRequest() {
    when(securityManager.resolve(request)).thenReturn(null);
    PolicyChain policyChain = securityPolicyChainResolver.resolve(StreamType.ON_REQUEST, request, response, executionContext);
    assertEquals(DirectPolicyChain.class, policyChain.getClass());
}
Also used : PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) RequestPolicyChain(io.gravitee.gateway.policy.impl.RequestPolicyChain) Test(org.junit.Test)

Example 12 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain in project gravitee-gateway by gravitee-io.

the class SecurityPolicyChainResolverTest method shouldReturnNoOpPolicyChain_onResponse.

@Test
public void shouldReturnNoOpPolicyChain_onResponse() {
    PolicyChain policyChain = securityPolicyChainResolver.resolve(StreamType.ON_RESPONSE, request, response, executionContext);
    assertEquals(NoOpPolicyChain.class, policyChain.getClass());
}
Also used : PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) RequestPolicyChain(io.gravitee.gateway.policy.impl.RequestPolicyChain) Test(org.junit.Test)

Example 13 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain in project gravitee-gateway by gravitee-io.

the class SecurityPolicyChainResolverTest method shouldReturnRequestPolicyChain_onRequest.

@Test
public void shouldReturnRequestPolicyChain_onRequest() {
    AuthenticationHandler securityProvider = mock(AuthenticationHandler.class);
    when(securityProvider.name()).thenReturn("my-provider");
    when(securityProvider.handle(executionContext)).thenReturn(Collections.emptyList());
    Policy policy = mock(Policy.class);
    when(policyManager.create(StreamType.ON_REQUEST, "my-policy", null)).thenReturn(policy);
    when(securityManager.resolve(request)).thenReturn(securityProvider);
    PolicyChain policyChain = securityPolicyChainResolver.resolve(StreamType.ON_REQUEST, request, response, executionContext);
    assertEquals(RequestPolicyChain.class, policyChain.getClass());
}
Also used : PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) RequestPolicyChain(io.gravitee.gateway.policy.impl.RequestPolicyChain) Test(org.junit.Test)

Example 14 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain 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 15 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain in project gravitee-gateway by gravitee-io.

the class RequestPolicyChainTest method doNext_emptyPolicies.

@Test
public void doNext_emptyPolicies() throws Exception {
    PolicyChain chain = RequestPolicyChain.create(new ArrayList<>(), mock(ExecutionContext.class));
    chain.setResultHandler(result -> {
    });
    chain.doNext(null, null);
    verify(policy, never()).onRequest();
    verify(policy, never()).onResponse();
}
Also used : PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) RequestPolicyChain(io.gravitee.gateway.policy.impl.RequestPolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) Test(org.junit.Test)

Aggregations

PolicyChain (io.gravitee.gateway.policy.impl.PolicyChain)21 Test (org.junit.Test)20 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)17 RequestPolicyChain (io.gravitee.gateway.policy.impl.RequestPolicyChain)12 ResponsePolicyChain (io.gravitee.gateway.policy.impl.ResponsePolicyChain)9 Request (io.gravitee.gateway.api.Request)8 InOrder (org.mockito.InOrder)7 Response (io.gravitee.gateway.api.Response)6 Handler (io.gravitee.gateway.api.handler.Handler)6 BufferedReadWriteStream (io.gravitee.gateway.api.stream.BufferedReadWriteStream)6 ReadWriteStream (io.gravitee.gateway.api.stream.ReadWriteStream)6 Metrics (io.gravitee.reporter.api.http.Metrics)2 DirectProxyConnection (io.gravitee.gateway.http.core.direct.DirectProxyConnection)1