Search in sources :

Example 16 with SetEnvironment

use of org.wso2.carbon.automation.engine.annotations.SetEnvironment in project product-is by wso2.

the class ProvisioningTestCase method createUserForSecondServer.

@Test(alwaysRun = true, description = "Add SCIM provisioning user on second server", dependsOnMethods = "createUser")
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void createUserForSecondServer() throws Exception {
    buildSCIMProvisioningConnector(PORT_OFFSET_1);
    addSP(PORT_OFFSET_1);
    scimClient = new SCIMClient();
    String encodedUser = getScimUser(2);
    // create a apache wink ClientHandler to intercept and identify response messages
    Resource userResource = getResource(scimClient, scim_url_1);
    BasicAuthInfo encodedBasicAuthInfo = getBasicAuthInfo(automationContextMap.get(PORT_OFFSET_0));
    String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, encodedUser);
    Assert.assertTrue(response.contains(userName2));
}
Also used : Resource(org.apache.wink.client.Resource) SCIMClient(org.wso2.charon.core.client.SCIMClient) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Example 17 with SetEnvironment

use of org.wso2.carbon.automation.engine.annotations.SetEnvironment in project product-is by wso2.

the class ProvisioningTestCase method createUser.

@Test(alwaysRun = true, description = "Add SCIM Provisioning user", priority = 1)
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
public void createUser() throws Exception {
    buildSCIMProvisioningConnector(PORT_OFFSET_0);
    addSP(PORT_OFFSET_0);
    scimClient = new SCIMClient();
    String encodedUser = getScimUser(1);
    // create a apache wink ClientHandler to intercept and identify response messages
    Resource userResource = getResource(scimClient, scim_url_0);
    BasicAuthInfo encodedBasicAuthInfo = getBasicAuthInfo(automationContextMap.get(PORT_OFFSET_0));
    String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, encodedUser);
    log.info(response);
    scimUserId = response.split(",")[0].split(":")[1].replace('"', ' ').trim();
    // userMgtServiceClients.get(PORT_OFFSET_2).listUsers(userName, 100);
    Assert.assertNotNull(scimUserId);
    Assert.assertTrue(isUserExists(userName));
}
Also used : Resource(org.apache.wink.client.Resource) SCIMClient(org.wso2.charon.core.client.SCIMClient) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Example 18 with SetEnvironment

use of org.wso2.carbon.automation.engine.annotations.SetEnvironment 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 19 with SetEnvironment

use of org.wso2.carbon.automation.engine.annotations.SetEnvironment in project product-is by wso2.

the class OAuth2TokenRevokeWithInvalidClientCredentialsTestCase 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 with invalid sending of client credentials.")
public void testRevokeTokenAfterCacheTimedOut() throws Exception {
    String clientKey = "dummyConsumerKey";
    String clientSecret = "dummyConsumerSecret";
    String accessToken = "dummyAccessToken";
    // Revoke access token
    ArrayList<NameValuePair> postParameters;
    HttpClient client = new DefaultHttpClient();
    HttpPost httpRevoke = new HttpPost(REVOKE_TOKEN_API_ENDPOINT);
    // Generate revoke token post request
    httpRevoke.setHeader("Authorization", "Basic " + getInvalidBase64EncodedString(clientKey, clientSecret));
    httpRevoke.setHeader("Content-Type", "application/x-www-form-urlencoded");
    postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("token", accessToken));
    httpRevoke.setEntity(new UrlEncodedFormEntity(postParameters));
    HttpResponse response = client.execute(httpRevoke);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    Object obj = JSONValue.parse(rd);
    Assert.assertNotNull(obj, "Returned error response should have produced a valid JSON.");
    Assert.assertNotNull(((JSONObject) obj).get("error"), "Returned error response should have 'error' defined.");
    String errorMessage = ((JSONObject) obj).get("error").toString();
    EntityUtils.consume(response.getEntity());
    Assert.assertEquals("invalid_client", errorMessage, "Invalid format in sending client credentials, should have produced : " + OAuth2Constant.INVALID_CLIENT + "error code");
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) InputStreamReader(java.io.InputStreamReader) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) BufferedReader(java.io.BufferedReader) HttpResponse(org.apache.http.HttpResponse) JSONObject(org.json.simple.JSONObject) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Example 20 with SetEnvironment

use of org.wso2.carbon.automation.engine.annotations.SetEnvironment in project product-is by wso2.

the class SCIMServiceProviderGroupTestCase method createGroupTest.

@Test(alwaysRun = true, description = "Add SCIM Group")
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void createGroupTest() throws Exception {
    // create a group according to SCIM Group Schema
    Group scimGroup = SCIMUtils.getSCIMGroup(scimClient, scimUserId, USERNAME, EXTERNAL_ID, DISPLAY_NAME);
    String encodedGroup = scimClient.encodeSCIMObject(scimGroup, SCIMConstants.JSON);
    Resource groupResource = SCIMUtils.getGroupResource(scimClient, scim_url);
    BasicAuthInfo encodedBasicAuthInfo = SCIMUtils.getBasicAuthInfo(userInfo);
    // send previously registered SCIM consumer credentials in http headers.
    String response = groupResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, encodedGroup);
    // decode the response
    log.info(response);
    Object obj = JSONValue.parse(response);
    scimGroupId = ((JSONObject) obj).get("id").toString();
    Assert.assertTrue(userMgtClient.roleNameExists(DISPLAY_NAME));
}
Also used : Group(org.wso2.charon.core.objects.Group) JSONObject(org.json.simple.JSONObject) Resource(org.apache.wink.client.Resource) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) JSONObject(org.json.simple.JSONObject) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Aggregations

SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)58 Test (org.testng.annotations.Test)45 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)29 Resource (org.apache.wink.client.Resource)16 BasicAuthInfo (org.wso2.identity.integration.test.utils.BasicAuthInfo)16 VerificationBean (org.wso2.carbon.identity.mgt.stub.beans.VerificationBean)14 ClientConfig (org.apache.wink.client.ClientConfig)12 RestClient (org.apache.wink.client.RestClient)12 SCIMResponseHandler (org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler)12 File (java.io.File)9 BeforeClass (org.testng.annotations.BeforeClass)9 UserIdentityClaimDTO (org.wso2.carbon.identity.mgt.stub.dto.UserIdentityClaimDTO)8 AuthenticatorClient (org.wso2.carbon.integration.common.admin.client.AuthenticatorClient)7 UserManagementClient (org.wso2.identity.integration.common.clients.UserManagementClient)6 ServerConfigurationManager (org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager)5 JSONObject (org.json.simple.JSONObject)4 FlaggedName (org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)4 SCIMClient (org.wso2.charon.core.client.SCIMClient)4 RemoteUserStoreManagerServiceClient (org.wso2.identity.integration.common.clients.usermgt.remote.RemoteUserStoreManagerServiceClient)4 ClaimValue (org.wso2.carbon.um.ws.api.stub.ClaimValue)3