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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations