Search in sources :

Example 1 with Utils

use of org.wso2.ei.dashboard.micro.integrator.commons.Utils in project product-is by wso2.

the class OAuth2TokenRevokeAfterCacheTimeOutTestCase method testRevokeTokenAfterCacheTimedOut.

/**
 * This tests written for test for token revocation after cache timed out CARBON-15028
 * This test needed two APIM nodes with clustering enabled
 * During the test one node is use to generate the token and other node use to revoke the token
 * After cache timeout new token should issued after it revoked
 *
 * @throws Exception
 */
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@Test(description = "Revoke token after cache timed out")
public void testRevokeTokenAfterCacheTimedOut() throws Exception {
    // Application utils
    OAuthConsumerAppDTO appDto = createApplication();
    consumerKey = appDto.getOauthConsumerKey();
    consumerSecret = appDto.getOauthConsumerSecret();
    // request for token
    String token = requestAccessToken(consumerKey, consumerSecret, TOKEN_API_ENDPOINT, "admin", "admin");
    // Sleep for 1m for cache timeout
    Thread.sleep(60 * 1000);
    // Revoke access token
    revokeAccessToken(consumerKey, consumerSecret, token, REVOKE_TOKEN_API_ENDPOINT);
    // Generate new token
    String newToken = requestAccessToken(consumerKey, consumerSecret, TOKEN_API_ENDPOINT, "admin", "admin");
    Assert.assertNotEquals(token, newToken, "Token revocation failed");
}
Also used : OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Example 2 with Utils

use of org.wso2.ei.dashboard.micro.integrator.commons.Utils in project identity-governance by wso2-extensions.

the class MeApiServiceImplTest method testMeResendCodePost.

@Test
public void testMeResendCodePost() throws IdentityRecoveryException {
    try {
        String carbonHome = Paths.get(System.getProperty("user.dir"), "src", "test", "resources").toString();
        System.setProperty(CarbonBaseConstants.CARBON_HOME, carbonHome);
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(USERNAME);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(-1234);
        Mockito.when(resendConfirmationManager.resendConfirmationCode(isNull(), anyString(), anyString(), anyString(), isNull())).thenReturn(notificationResponseBean);
        mockedUtils.when(() -> Utils.getUserRecoveryData(any(ResendCodeRequestDTO.class), anyString())).thenReturn(userRecoveryData);
        mockedUtils.when(Utils::getResendConfirmationManager).thenReturn(resendConfirmationManager);
        Mockito.when(userRecoveryData.getRecoveryScenario()).thenReturn(RecoveryScenarios.getRecoveryScenario("MOBILE_VERIFICATION_ON_UPDATE"));
        Mockito.when(userRecoveryData.getRecoveryStep()).thenReturn(RecoverySteps.getRecoveryStep("VERIFY_MOBILE_NUMBER"));
        assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTO()).getStatus(), 201);
        assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTOWithInvalidScenarioProperty()).getStatus(), 400);
        mockedUtils.when(() -> Utils.getUserRecoveryData(any(ResendCodeRequestDTO.class), anyString())).thenReturn(null);
        assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTO()).getStatus(), 400);
        Mockito.when(userRecoveryData.getRecoveryScenario()).thenReturn(RecoveryScenarios.getRecoveryScenario("ASK_PASSWORD"));
        assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTO()).getStatus(), 400);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
Also used : MeResendCodeRequestDTO(org.wso2.carbon.identity.user.endpoint.dto.MeResendCodeRequestDTO) ResendCodeRequestDTO(org.wso2.carbon.identity.user.endpoint.dto.ResendCodeRequestDTO) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 3 with Utils

use of org.wso2.ei.dashboard.micro.integrator.commons.Utils in project identity-governance by wso2-extensions.

the class PiInfoApiServiceImplTest method testGetUserById.

@Test
public void testGetUserById() throws Exception {
    RealmService realmService = Mockito.mock(RealmService.class);
    TenantManager tenantManager = Mockito.mock(TenantManager.class);
    Mockito.when(tenantManager.getTenantId(anyString())).thenReturn(-1234);
    Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    PiInfoApiServiceImpl piInfoApiService = new PiInfoApiServiceImpl();
    mockedUtils.when(Utils::getRealmService).thenReturn(realmService);
    mockedUtils.when(Utils::getUserInformationService).thenReturn(new MockUserInformationService());
    Assert.assertEquals(piInfoApiService.getUserById("ZHVtbXlVc2Vy").getStatus(), 200);
}
Also used : RealmService(org.wso2.carbon.user.core.service.RealmService) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Test(org.testng.annotations.Test)

Example 4 with Utils

use of org.wso2.ei.dashboard.micro.integrator.commons.Utils in project carbon-apimgt by wso2.

the class UtilsTestCase method setup.

@Before
public void setup() {
    messageContext = Mockito.mock(Axis2MessageContext.class);
    axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
    Mockito.when(axis2MsgCntxt.getProperty(APIMgtGatewayConstants.REQUEST_RECEIVED_TIME)).thenReturn("1506576365");
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(Axis2Sender.class);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    PowerMockito.when(serviceReferenceHolder.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    try {
        PowerMockito.doNothing().when(Axis2Sender.class, "sendBack", messageContext);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception is thrown while setup Utils test cases");
    }
    headers = Mockito.mock(Map.class);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.gateway.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Map(java.util.Map) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Before(org.junit.Before)

Example 5 with Utils

use of org.wso2.ei.dashboard.micro.integrator.commons.Utils in project ballerina by ballerina-lang.

the class IterableCodeDesugar method createForeachVariables.

/* Some Utils methods */
private List<BLangVariable> createForeachVariables(IterableContext ctx, BLangVariable firstOperationArg, BLangFunction funcNode) {
    List<BLangVariable> foreachVariables = new ArrayList<>();
    if (firstOperationArg.type.tag != TypeTags.TUPLE) {
        foreachVariables.add(firstOperationArg);
        defineVariable(firstOperationArg, ctx.env.enclPkg.symbol.pkgID, funcNode);
        return foreachVariables;
    }
    final List<BType> tupleTypes = ((BTupleType) firstOperationArg.type).tupleTypes;
    int index = 0;
    for (BType type : tupleTypes) {
        String varName = VAR_FOREACH_VAL + index++;
        final BLangVariable variable = ASTBuilderUtil.createVariable(funcNode.pos, varName, type);
        foreachVariables.add(variable);
        defineVariable(variable, ctx.env.enclPkg.symbol.pkgID, funcNode);
    }
    return foreachVariables;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Aggregations

Test (org.testng.annotations.Test)7 UserDTO (org.wso2.carbon.identity.user.rename.core.dto.UserDTO)4 UsernameUpdateClientException (org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateClientException)3 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 MessageContext (org.apache.synapse.MessageContext)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 Before (org.junit.Before)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 BTupleType (org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 ServiceReferenceHolder (org.wso2.carbon.apimgt.gateway.internal.ServiceReferenceHolder)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)1 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO)1 MeResendCodeRequestDTO (org.wso2.carbon.identity.user.endpoint.dto.MeResendCodeRequestDTO)1 ResendCodeRequestDTO (org.wso2.carbon.identity.user.endpoint.dto.ResendCodeRequestDTO)1 UsernameUpdateException (org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateException)1 RealmService (org.wso2.carbon.user.core.service.RealmService)1