Search in sources :

Example 1 with Flow

use of io.gravitee.am.model.flow.Flow in project gravitee-access-management by gravitee-io.

the class FlowManagerTest method shouldFindByExtensionPoint_twoFlows_inherit_false.

@Test
public void shouldFindByExtensionPoint_twoFlows_inherit_false() {
    Step domainStep = mock(Step.class);
    when(domainStep.isEnabled()).thenReturn(true);
    when(domainStep.getPolicy()).thenReturn("step-policy");
    when(domainStep.getConfiguration()).thenReturn("domain-step-configuration");
    Step appStep = mock(Step.class);
    when(appStep.isEnabled()).thenReturn(true);
    when(appStep.getPolicy()).thenReturn("step-policy");
    when(appStep.getConfiguration()).thenReturn("app-step-configuration");
    Flow domainFlow = mock(Flow.class);
    when(domainFlow.getId()).thenReturn("domain-flow-id");
    when(domainFlow.getType()).thenReturn(Type.CONSENT);
    when(domainFlow.isEnabled()).thenReturn(true);
    when(domainFlow.getPre()).thenReturn(Collections.singletonList(domainStep));
    Flow appFlow = mock(Flow.class);
    when(appFlow.getId()).thenReturn("app-flow-id");
    when(appFlow.getType()).thenReturn(Type.CONSENT);
    when(appFlow.isEnabled()).thenReturn(true);
    when(appFlow.getPre()).thenReturn(Collections.singletonList(appStep));
    when(appFlow.getApplication()).thenReturn("app-id");
    Policy domainPolicy = mock(Policy.class);
    Policy appPolicy = mock(Policy.class);
    when(appPolicy.id()).thenReturn("app-policy");
    Client client = mock(Client.class);
    when(client.getId()).thenReturn("app-id");
    when(domain.getId()).thenReturn("domain-id");
    when(policyPluginManager.create(domainStep.getPolicy(), domainStep.getCondition(), domainStep.getConfiguration())).thenReturn(domainPolicy);
    when(policyPluginManager.create(appStep.getPolicy(), appStep.getCondition(), appStep.getConfiguration())).thenReturn(appPolicy);
    when(flowService.findAll(ReferenceType.DOMAIN, domain.getId())).thenReturn(Flowable.just(domainFlow, appFlow));
    flowManager.afterPropertiesSet();
    TestObserver<List<Policy>> obs = flowManager.findByExtensionPoint(ExtensionPoint.PRE_CONSENT, client, null).test();
    obs.awaitTerminalEvent();
    obs.assertValue(policies -> {
        Assert.assertTrue(policies.size() == 1);
        Assert.assertTrue(policies.get(0).id().equals(appPolicy.id()));
        return true;
    });
    verify(policyPluginManager, times(2)).create(anyString(), eq(null), anyString());
}
Also used : Policy(io.gravitee.am.gateway.policy.Policy) List(java.util.List) Step(io.gravitee.am.model.flow.Step) Client(io.gravitee.am.model.oidc.Client) Flow(io.gravitee.am.model.flow.Flow) Test(org.junit.Test)

Example 2 with Flow

use of io.gravitee.am.model.flow.Flow in project gravitee-access-management by gravitee-io.

the class FlowManagerTest method shouldFindByExtensionPoint_twoFlows_inherit_true.

@Test
public void shouldFindByExtensionPoint_twoFlows_inherit_true() {
    Step domainStep = mock(Step.class);
    when(domainStep.isEnabled()).thenReturn(true);
    when(domainStep.getPolicy()).thenReturn("step-policy");
    when(domainStep.getConfiguration()).thenReturn("domain-step-configuration");
    Step appStep = mock(Step.class);
    when(appStep.isEnabled()).thenReturn(true);
    when(appStep.getPolicy()).thenReturn("step-policy");
    when(appStep.getConfiguration()).thenReturn("app-step-configuration");
    Flow domainFlow = mock(Flow.class);
    when(domainFlow.getId()).thenReturn("domain-flow-id");
    when(domainFlow.getType()).thenReturn(Type.CONSENT);
    when(domainFlow.isEnabled()).thenReturn(true);
    when(domainFlow.getPre()).thenReturn(Collections.singletonList(domainStep));
    Flow appFlow = mock(Flow.class);
    when(appFlow.getId()).thenReturn("app-flow-id");
    when(appFlow.getType()).thenReturn(Type.CONSENT);
    when(appFlow.isEnabled()).thenReturn(true);
    when(appFlow.getPre()).thenReturn(Collections.singletonList(appStep));
    when(appFlow.getApplication()).thenReturn("app-id");
    Policy domainPolicy = mock(Policy.class);
    when(domainPolicy.id()).thenReturn("domain-policy");
    Policy appPolicy = mock(Policy.class);
    when(appPolicy.id()).thenReturn("app-policy");
    Client client = mock(Client.class);
    when(client.getId()).thenReturn("app-id");
    when(client.isFlowsInherited()).thenReturn(true);
    when(domain.getId()).thenReturn("domain-id");
    when(policyPluginManager.create(domainStep.getPolicy(), domainStep.getCondition(), domainStep.getConfiguration())).thenReturn(domainPolicy);
    when(policyPluginManager.create(appStep.getPolicy(), appStep.getCondition(), appStep.getConfiguration())).thenReturn(appPolicy);
    when(flowService.findAll(ReferenceType.DOMAIN, domain.getId())).thenReturn(Flowable.just(domainFlow, appFlow));
    flowManager.afterPropertiesSet();
    TestObserver<List<Policy>> obs = flowManager.findByExtensionPoint(ExtensionPoint.PRE_CONSENT, client, ExecutionPredicate.alwaysTrue()).test();
    obs.awaitTerminalEvent();
    obs.assertValue(policies -> {
        Assert.assertTrue(policies.size() == 2);
        Assert.assertTrue(policies.get(0).id().equals(domainPolicy.id()));
        Assert.assertTrue(policies.get(1).id().equals(appPolicy.id()));
        return true;
    });
    verify(policyPluginManager, times(2)).create(anyString(), eq(null), anyString());
}
Also used : Policy(io.gravitee.am.gateway.policy.Policy) List(java.util.List) Step(io.gravitee.am.model.flow.Step) Client(io.gravitee.am.model.oidc.Client) Flow(io.gravitee.am.model.flow.Flow) Test(org.junit.Test)

Example 3 with Flow

use of io.gravitee.am.model.flow.Flow in project gravitee-access-management by gravitee-io.

the class FlowManagerTest method shouldNotFindByExtensionPoint_noPolicy.

@Test
public void shouldNotFindByExtensionPoint_noPolicy() {
    Flow flow = mock(Flow.class);
    when(flow.getId()).thenReturn("flow-id");
    when(flow.getType()).thenReturn(Type.CONSENT);
    when(flow.isEnabled()).thenReturn(true);
    when(domain.getId()).thenReturn("domain-id");
    when(flowService.findAll(ReferenceType.DOMAIN, domain.getId())).thenReturn(Flowable.just(flow));
    flowManager.afterPropertiesSet();
    TestObserver<List<Policy>> obs = flowManager.findByExtensionPoint(ExtensionPoint.PRE_CONSENT, null, null).test();
    obs.awaitTerminalEvent();
    obs.assertValue(policies -> {
        Assert.assertTrue(policies.isEmpty());
        return true;
    });
    verify(policyPluginManager, never()).create(anyString(), eq(null), anyString());
}
Also used : List(java.util.List) Flow(io.gravitee.am.model.flow.Flow) Test(org.junit.Test)

Example 4 with Flow

use of io.gravitee.am.model.flow.Flow in project gravitee-access-management by gravitee-io.

the class FlowManagerTest method shouldNotFindByExtensionPoint_applicationPolicy_clientNull.

@Test
public void shouldNotFindByExtensionPoint_applicationPolicy_clientNull() {
    Step step = mock(Step.class);
    when(step.isEnabled()).thenReturn(true);
    when(step.getPolicy()).thenReturn("step-policy");
    when(step.getConfiguration()).thenReturn("step-configuration");
    Flow flow = mock(Flow.class);
    when(flow.getId()).thenReturn("flow-id");
    when(flow.getType()).thenReturn(Type.CONSENT);
    when(flow.isEnabled()).thenReturn(true);
    when(flow.getPre()).thenReturn(Collections.singletonList(step));
    when(flow.getApplication()).thenReturn("app-id");
    Policy policy = mock(Policy.class);
    when(domain.getId()).thenReturn("domain-id");
    when(policyPluginManager.create(step.getPolicy(), step.getCondition(), step.getConfiguration())).thenReturn(policy);
    when(flowService.findAll(ReferenceType.DOMAIN, domain.getId())).thenReturn(Flowable.just(flow));
    flowManager.afterPropertiesSet();
    TestObserver<List<Policy>> obs = flowManager.findByExtensionPoint(ExtensionPoint.PRE_CONSENT, null, null).test();
    obs.awaitTerminalEvent();
    obs.assertValue(policies -> {
        Assert.assertTrue(policies.isEmpty());
        return true;
    });
    verify(policyPluginManager, times(1)).create(anyString(), eq(null), anyString());
}
Also used : Policy(io.gravitee.am.gateway.policy.Policy) List(java.util.List) Step(io.gravitee.am.model.flow.Step) Flow(io.gravitee.am.model.flow.Flow) Test(org.junit.Test)

Example 5 with Flow

use of io.gravitee.am.model.flow.Flow in project gravitee-access-management by gravitee-io.

the class FlowManagerTest method shouldFindByExtensionPoint_domainPolicy.

@Test
public void shouldFindByExtensionPoint_domainPolicy() {
    Step step = mock(Step.class);
    when(step.isEnabled()).thenReturn(true);
    when(step.getPolicy()).thenReturn("step-policy");
    when(step.getConfiguration()).thenReturn("step-configuration");
    when(step.getCondition()).thenReturn("step-condition");
    Flow flow = mock(Flow.class);
    when(flow.getId()).thenReturn("flow-id");
    when(flow.getType()).thenReturn(Type.CONSENT);
    when(flow.isEnabled()).thenReturn(true);
    when(flow.getPre()).thenReturn(Collections.singletonList(step));
    Policy policy = mock(Policy.class);
    when(domain.getId()).thenReturn("domain-id");
    when(policyPluginManager.create(step.getPolicy(), step.getCondition(), step.getConfiguration())).thenReturn(policy);
    when(flowService.findAll(ReferenceType.DOMAIN, domain.getId())).thenReturn(Flowable.just(flow));
    flowManager.afterPropertiesSet();
    TestObserver<List<Policy>> obs = flowManager.findByExtensionPoint(ExtensionPoint.PRE_CONSENT, null, null).test();
    obs.awaitTerminalEvent();
    obs.assertValue(policies -> {
        Assert.assertTrue(policies.size() == 1);
        return true;
    });
    verify(policyPluginManager, times(1)).create(anyString(), anyString(), anyString());
}
Also used : Policy(io.gravitee.am.gateway.policy.Policy) List(java.util.List) Step(io.gravitee.am.model.flow.Step) Flow(io.gravitee.am.model.flow.Flow) Test(org.junit.Test)

Aggregations

Flow (io.gravitee.am.model.flow.Flow)55 Test (org.junit.Test)40 List (java.util.List)17 TestObserver (io.reactivex.observers.TestObserver)14 Event (io.gravitee.am.model.common.event.Event)11 Step (io.gravitee.am.model.flow.Step)10 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)10 ReferenceType (io.gravitee.am.model.ReferenceType)9 Policy (io.gravitee.am.gateway.policy.Policy)8 Type (io.gravitee.am.model.flow.Type)7 FlowService (io.gravitee.am.service.FlowService)7 Collectors (java.util.stream.Collectors)7 User (io.gravitee.am.identityprovider.api.User)6 Client (io.gravitee.am.model.oidc.Client)5 Maybe (io.reactivex.Maybe)5 EventType (io.gravitee.am.common.audit.EventType)4 Action (io.gravitee.am.common.event.Action)3 RandomString (io.gravitee.am.common.utils.RandomString)3 FlowRepository (io.gravitee.am.repository.management.api.FlowRepository)3 FlowNotFoundException (io.gravitee.am.service.exception.FlowNotFoundException)3