use of org.wso2.carbon.identity.conditional.auth.functions.common.internal.FunctionsDataHolder in project identity-conditional-auth-functions by wso2-extensions.
the class CallAnalyticsFunctionImplTest method testRiskScore.
@Test
public void testRiskScore() throws JsTestException, NoSuchFieldException, IllegalAccessException, IdentityGovernanceException {
IdentityGovernanceService identityGovernanceService = Mockito.mock(IdentityGovernanceService.class);
FunctionsDataHolder functionsDataHolder = Mockito.mock(FunctionsDataHolder.class);
Mockito.when(functionsDataHolder.getIdentityGovernanceService()).thenReturn(identityGovernanceService);
Property property = new Property();
property.setValue("http://localhost:" + microServicePort);
Mockito.when(identityGovernanceService.getConfiguration(new String[] { AnalyticsEngineConfigImpl.RECEIVER }, "test_domain")).thenReturn(new Property[] { property });
Field functionsDataHolderInstance = FunctionsDataHolder.class.getDeclaredField("instance");
functionsDataHolderInstance.setAccessible(true);
functionsDataHolderInstance.set(null, functionsDataHolder);
Field frameworkServiceDataHolderInstance = FrameworkServiceDataHolder.class.getDeclaredField("instance");
frameworkServiceDataHolderInstance.setAccessible(true);
FrameworkServiceDataHolder availableInstance = (FrameworkServiceDataHolder) frameworkServiceDataHolderInstance.get(null);
LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);
int connectionTimeout = 5000;
LongWaitStatusStoreService longWaitStatusStoreService = new LongWaitStatusStoreService(cacheBackedDao, connectionTimeout);
availableInstance.setLongWaitStatusStoreService(longWaitStatusStoreService);
ServiceProvider sp1 = sequenceHandlerRunner.loadServiceProviderFromResource("risk-test-sp.xml", this);
AuthenticationContext context = sequenceHandlerRunner.createAuthenticationContext(sp1);
SequenceConfig sequenceConfig = sequenceHandlerRunner.getSequenceConfig(context, sp1);
context.setSequenceConfig(sequenceConfig);
context.initializeAnalyticsData();
HttpServletRequest req = sequenceHandlerRunner.createHttpServletRequest();
HttpServletResponse resp = sequenceHandlerRunner.createHttpServletResponse();
sequenceHandlerRunner.handle(req, resp, context, "carbon.super");
assertNotNull(context.getSelectedAcr());
assertEquals(context.getSelectedAcr(), "1", "Expected acr value not found");
}
use of org.wso2.carbon.identity.conditional.auth.functions.common.internal.FunctionsDataHolder in project identity-conditional-auth-functions by wso2-extensions.
the class CallChoreoFunctionImplTest method testCallChoreo.
@Test(dataProvider = "choreoEpValidity")
public void testCallChoreo(boolean isValidChoreoDomain) throws JsTestException, NoSuchFieldException, IllegalAccessException, FrameworkException {
FunctionsDataHolder functionsDataHolder = Mockito.mock(FunctionsDataHolder.class);
Field functionsDataHolderInstance = FunctionsDataHolder.class.getDeclaredField("instance");
functionsDataHolderInstance.setAccessible(true);
functionsDataHolderInstance.set(null, functionsDataHolder);
Field frameworkServiceDataHolderInstance = FrameworkServiceDataHolder.class.getDeclaredField("instance");
frameworkServiceDataHolderInstance.setAccessible(true);
FrameworkServiceDataHolder availableInstance = (FrameworkServiceDataHolder) frameworkServiceDataHolderInstance.get(null);
ClientManager clientManager = new ClientManager();
ChoreoFunctionServiceHolder.getInstance().setClientManager(clientManager);
LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);
int connectionTimeout = 5000;
LongWaitStatusStoreService longWaitStatusStoreService = new LongWaitStatusStoreService(cacheBackedDao, connectionTimeout);
availableInstance.setLongWaitStatusStoreService(longWaitStatusStoreService);
ServiceProvider sp1 = sequenceHandlerRunner.loadServiceProviderFromResource("risk-test-sp.xml", this);
LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = sp1.getLocalAndOutBoundAuthenticationConfig();
AuthenticationScriptConfig authenticationScriptConfig = localAndOutboundAuthenticationConfig.getAuthenticationScriptConfig();
String content = authenticationScriptConfig.getContent();
if (isValidChoreoDomain) {
// Setting localhost as the valid domain as
// the unit test is calling a mock local endpoint.
setChoreoDomain("localhost");
} else {
setChoreoDomain("abc");
}
String newContent = String.format(content, microServicePort);
authenticationScriptConfig.setContent(newContent);
localAndOutboundAuthenticationConfig.setAuthenticationScriptConfig(authenticationScriptConfig);
sp1.setLocalAndOutBoundAuthenticationConfig(localAndOutboundAuthenticationConfig);
AuthenticationContext context = sequenceHandlerRunner.createAuthenticationContext(sp1);
SequenceConfig sequenceConfig = sequenceHandlerRunner.getSequenceConfig(context, sp1);
context.setSequenceConfig(sequenceConfig);
context.initializeAnalyticsData();
HttpServletRequest req = sequenceHandlerRunner.createHttpServletRequest();
HttpServletResponse resp = sequenceHandlerRunner.createHttpServletResponse();
sequenceHandlerRunner.handle(req, resp, context, "carbon.super");
if (isValidChoreoDomain) {
assertNotNull(context.getSelectedAcr());
assertEquals(context.getSelectedAcr(), "1", "Expected acr value not found");
} else {
assertEquals(context.getSelectedAcr(), FAILED, "Expected the request to fail");
}
}
Aggregations