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