Merge pull request #360 from Megala21/test_case_fixes

Fixing user management and role management integration test cases.
application-manager-new
sinthuja 8 years ago committed by GitHub
commit 477536aa68

@ -57,7 +57,11 @@ public final class Constants {
public static final class APIApplicationRegistration { public static final class APIApplicationRegistration {
public static final String API_APP_REGISTRATION_ENDPOINT = "/api-application-registration/register"; public static final String API_APP_REGISTRATION_ENDPOINT = "/api-application-registration/register";
public static final String TOKEN_ENDPOINT = "/token"; public static final String TOKEN_ENDPOINT = "/token";
public static final String OAUTH_TOKEN_PAYLOAD = "username=admin&password=admin&grant_type=password&scope=perm:android:enroll perm:android:wipe perm:android:ring perm:android:lock-devices perm:android:configure-vpn perm:android:configure-wifi perm:android:enroll perm:android:uninstall-application perm:android:manage-configuration perm:android:location perm:android:install-application perm:android:mute perm:android:change-lock-code perm:android:blacklist-applications perm:android:set-password-policy perm:android:encrypt-storage perm:android:clear-password perm:android:enterprise-wipe perm:android:info perm:android:view-configuration perm:android:upgrade-firmware perm:android:set-webclip perm:android:send-notification perm:android:disenroll perm:android:update-application perm:android:unlock-devices perm:android:control-camera perm:android:reboot perm:android:logcat appm:subscribe perm:sign-csr perm:admin:devices:view perm:roles:add perm:roles:add-users perm:roles:update perm:roles:permissions perm:roles:details perm:roles:view perm:roles:create-combined-role perm:roles:delete perm:dashboard:vulnerabilities perm:dashboard:non-compliant-count perm:dashboard:non-compliant perm:dashboard:by-groups perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:count-overview perm:dashboard:filtered-count perm:dashboard:details perm:get-activity perm:devices:delete perm:devices:applications perm:devices:effective-policy perm:devices:compliance-data perm:devices:features perm:devices:operations perm:devices:search perm:devices:details perm:devices:update perm:devices:view perm:view-configuration perm:manage-configuration perm:policies:remove perm:policies:priorities perm:policies:deactivate perm:policies:get-policy-details perm:policies:manage perm:policies:activate perm:policies:update perm:policies:changes perm:policies:get-details perm:users:add perm:users:details perm:users:count perm:users:delete perm:users:roles perm:users:user-details perm:users:credentials perm:users:search perm:users:is-exist perm:users:update perm:users:send-invitation perm:admin-users:view perm:groups:devices perm:groups:update perm:groups:add perm:groups:device perm:groups:devices-count perm:groups:remove perm:groups:groups perm:groups:groups-view perm:groups:share perm:groups:count perm:groups:roles perm:groups:devices-remove perm:groups:devices-add perm:groups:assign perm:device-types:features perm:device-types:types perm:applications:install perm:applications:uninstall perm:admin-groups:count perm:admin-groups:view perm:notifications:mark-checked perm:notifications:view perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:view perm:admin:certificates:add perm:admin:certificates:verify perm:ios:enroll perm:ios:view-device perm:ios:apn perm:ios:ldap perm:ios:enterprise-app perm:ios:store-application perm:ios:remove-application perm:ios:app-list perm:ios:profile-list perm:ios:lock perm:ios:enterprise-wipe perm:ios:device-info perm:ios:restriction perm:ios:email perm:ios:cellular perm:ios:applications perm:ios:wifi perm:ios:ring perm:ios:location perm:ios:notification perm:ios:airplay perm:ios:caldav perm:ios:cal-subscription perm:ios:passcode-policy perm:ios:webclip perm:ios:vpn perm:ios:per-app-vpn perm:ios:app-to-per-app-vpn perm:ios:app-lock perm:ios:clear-passcode perm:ios:remove-profile perm:ios:get-restrictions perm:ios:wipe-data perm:admin"; public static final String MULTI_TENANT_OAUTH_TOKEN_PAYLOAD = "&grant_type=password&scope=perm:android:enroll"
+ " perm:android:wipe perm:android:ring perm:android:lock-devices perm:android:configure-vpn perm:android:configure-wifi perm:android:enroll perm:android:uninstall-application perm:android:manage-configuration perm:android:location perm:android:install-application perm:android:mute perm:android:change-lock-code perm:android:blacklist-applications perm:android:set-password-policy perm:android:encrypt-storage perm:android:clear-password perm:android:enterprise-wipe perm:android:info perm:android:view-configuration perm:android:upgrade-firmware perm:android:set-webclip perm:android:send-notification perm:android:disenroll perm:android:update-application perm:android:unlock-devices perm:android:control-camera perm:android:reboot perm:android:logcat appm:subscribe perm:sign-csr perm:admin:devices:view perm:roles:add perm:roles:add-users perm:roles:update perm:roles:permissions perm:roles:details perm:roles:view perm:roles:create-combined-role perm:roles:delete perm:dashboard:vulnerabilities perm:dashboard:non-compliant-count perm:dashboard:non-compliant perm:dashboard:by-groups perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:count-overview perm:dashboard:filtered-count perm:dashboard:details perm:get-activity perm:devices:delete perm:devices:applications perm:devices:effective-policy perm:devices:compliance-data perm:devices:features perm:devices:operations perm:devices:search perm:devices:details perm:devices:update perm:devices:view perm:view-configuration perm:manage-configuration perm:policies:remove perm:policies:priorities perm:policies:deactivate perm:policies:get-policy-details perm:policies:manage perm:policies:activate perm:policies:update perm:policies:changes perm:policies:get-details perm:users:add perm:users:details perm:users:count perm:users:delete perm:users:roles perm:users:user-details perm:users:credentials perm:users:search perm:users:is-exist perm:users:update perm:users:send-invitation perm:admin-users:view perm:groups:devices perm:groups:update perm:groups:add perm:groups:device perm:groups:devices-count perm:groups:remove perm:groups:groups perm:groups:groups-view perm:groups:share perm:groups:count perm:groups:roles perm:groups:devices-remove perm:groups:devices-add perm:groups:assign perm:device-types:features perm:device-types:types perm:applications:install perm:applications:uninstall perm:admin-groups:count perm:admin-groups:view perm:notifications:mark-checked perm:notifications:view perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:view perm:admin:certificates:add perm:admin:certificates:verify perm:ios:enroll perm:ios:view-device perm:ios:apn perm:ios:ldap perm:ios:enterprise-app perm:ios:store-application perm:ios:remove-application perm:ios:app-list perm:ios:profile-list perm:ios:lock perm:ios:enterprise-wipe perm:ios:device-info perm:ios:restriction perm:ios:email perm:ios:cellular perm:ios:applications perm:ios:wifi perm:ios:ring perm:ios:location perm:ios:notification perm:ios:airplay perm:ios:caldav perm:ios:cal-subscription perm:ios:passcode-policy perm:ios:webclip perm:ios:vpn perm:ios:per-app-vpn perm:ios:app-to-per-app-vpn perm:ios:app-lock perm:ios:clear-passcode perm:ios:remove-profile perm:ios:get-restrictions perm:ios:wipe-data perm:admin";
public static final String OAUTH_TOKEN_PAYLOAD = "username=admin&password=admin" +
MULTI_TENANT_OAUTH_TOKEN_PAYLOAD;
private static StringBuffer dynamicClientPayloadBuffer = new StringBuffer(); private static StringBuffer dynamicClientPayloadBuffer = new StringBuffer();
public static final String API_APP_REGISTRATION_PAYLOAD = dynamicClientPayloadBuffer.append("{ \n" public static final String API_APP_REGISTRATION_PAYLOAD = dynamicClientPayloadBuffer.append("{ \n"
+ " \"applicationName\":\"app_123456\",\n" + " \"isAllowedToAllDomains\":false,\n" + " \"applicationName\":\"app_123456\",\n" + " \"isAllowedToAllDomains\":false,\n"
@ -309,11 +313,11 @@ public final class Constants {
public static final class UserManagement { public static final class UserManagement {
public static final String USER_MANAGEMENT_GROUP = "user-mgt"; public static final String USER_MANAGEMENT_GROUP = "user-mgt";
public static final String USER_NAME = "username123"; public static final String USER_NAME = "username123";
public static final String USER_ENDPOINT = "/mdm-admin/users"; public static final String USER_ENDPOINT = "/api/device-mgt/v1.0/users";
public static final String USER_PAYLOAD_FILE_NAME = "user-payloads.json"; public static final String USER_PAYLOAD_FILE_NAME = "user-payloads.json";
public static final String USER_RESPONSE_PAYLOAD_FILE_NAME = "user-response-payloads.json"; public static final String USER_RESPONSE_PAYLOAD_FILE_NAME = "user-response-payloads.json";
public static final String VIEW_USER_ENDPOINT = "/mdm-admin/users/view"; public static final String GET_ROLES_METHOD = "GET_ROLES";
public static final String RESET_PASSWORD_PAYLOAD = "RESET_PASSWORD";
private UserManagement() { private UserManagement() {
throw new AssertionError(); throw new AssertionError();
} }
@ -322,12 +326,10 @@ public final class Constants {
public static final class RoleManagement { public static final class RoleManagement {
public static final String ROLE_MANAGEMENT_GROUP = "role-mgt"; public static final String ROLE_MANAGEMENT_GROUP = "role-mgt";
public static final String ADD_ROLE_ENDPOINT = "/mdm-admin/roles"; public static final String ROLE_MANAGEMENT_END_POINT = "/api/device-mgt/v1.0/roles";
public static final String ROLE_PAYLOAD_FILE_NAME = "role-payloads.json"; public static final String ROLE_PAYLOAD_FILE_NAME = "role-payloads.json";
public static final String UPDATE_ROLE_PERMISSION_ENDPOINT = "/mdm-admin/roles?rolename=administration"; public static final String ROLE_RESPONSE_PAYLOAD_FILE_NAME = "role-response-payloads.json";
public static final String UPDATE_ROLE_PERMISSION_PAYLOAD_FILE_NAME = "role-payloads.json"; public static final String GET_FILTERED_ROLED_METHOD = "GET_FILTERED_ROLES";
public static final String REMOVE_ROLE_ENDPOINT = "/mdm-admin/roles?rolename=administration";
private RoleManagement() { private RoleManagement() {
throw new AssertionError(); throw new AssertionError();
} }

@ -20,6 +20,7 @@ package org.wso2.iot.integration.common;
import org.apache.commons.net.util.Base64; import org.apache.commons.net.util.Base64;
import org.json.JSONObject; import org.json.JSONObject;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
/** /**
@ -53,4 +54,31 @@ public class OAuthUtil {
jsonObj = new JSONObject(oAuthData.getData()); jsonObj = new JSONObject(oAuthData.getData());
return jsonObj; return jsonObj;
} }
/**
* To get the oauth token pair for the given auth string which is encoded in base64 format.
* @param authString encoded auth string
* @param backendHTTPURL backend http URL
* @param backendHTTPSURL backend https URL
* @return a JSON object which consist of oauth token pair
* @throws Exception Exception
*/
public static String getOAuthTokenPair(String authString, String backendHTTPURL, String backendHTTPSURL,
String username, String password) throws Exception {
RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, "Basic " + authString);
HttpResponse oAuthData = client.post(Constants.APIApplicationRegistration.API_APP_REGISTRATION_ENDPOINT,
Constants.APIApplicationRegistration.API_APP_REGISTRATION_PAYLOAD);
JSONObject jsonObj = new JSONObject(oAuthData.getData());
String clientId = jsonObj.get(Constants.OAUTH_CLIENT_ID).toString();
String clientSecret = jsonObj.get(Constants.OAUTH_CLIENT_SECRET).toString();
byte[] bytesEncoded = Base64.encodeBase64((clientId + ":" + clientSecret).getBytes());
String basicAuthString = "Basic " + new String(bytesEncoded);
//Initiate a RestClient to get OAuth token
client = new RestClient(backendHTTPSURL, Constants.APPLICATION_URL_ENCODED, basicAuthString);
oAuthData = client.post(Constants.APIApplicationRegistration.TOKEN_ENDPOINT,
"username=" + username + "&password=" + password + Constants.APIApplicationRegistration.MULTI_TENANT_OAUTH_TOKEN_PAYLOAD);
jsonObj = new JSONObject(oAuthData.getData());
return jsonObj.get(Constants.OAUTH_ACCESS_TOKEN).toString();
}
} }

@ -34,10 +34,11 @@ public class TestBase {
protected void init(TestUserMode userMode) throws Exception { protected void init(TestUserMode userMode) throws Exception {
automationContext = new AutomationContext(Constants.AUTOMATION_CONTEXT, userMode); automationContext = new AutomationContext(Constants.AUTOMATION_CONTEXT, userMode);
String tenantDomain = automationContext.getContextTenant().getDomain();
backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps().replace("9443", String.valueOf(Constants backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps().replace("9443", String.valueOf(Constants
.HTTPS_GATEWAY_PORT)); .HTTPS_GATEWAY_PORT)).replace("/t/" + tenantDomain , "");
backendHTTPURL = automationContext.getContextUrls().getWebAppURL().replace("9763", String.valueOf(Constants backendHTTPURL = automationContext.getContextUrls().getWebAppURL().replace("9763", String.valueOf(Constants
.HTTP_GATEWAY_PORT)); .HTTP_GATEWAY_PORT)).replace("/t/" + tenantDomain , "");
} }
protected void initPublisher(String productGroupName, String instanceName, protected void initPublisher(String productGroupName, String instanceName,
@ -68,6 +69,10 @@ public class TestBase {
return automationContext.getContextUrls().getServiceUrl(); return automationContext.getContextUrls().getServiceUrl();
} }
protected AutomationContext getAutomationContext() {
return automationContext;
}
protected String getTestArtifactLocation() { protected String getTestArtifactLocation() {
return FrameworkPathUtil.getSystemResourceLocation(); return FrameworkPathUtil.getSystemResourceLocation();
} }

@ -65,6 +65,9 @@ public class IOTServerExtension extends ExecutionListenerExtension {
String carbonHome = serverManager.startServer("core"); String carbonHome = serverManager.startServer("core");
log.info(carbonHome); log.info(carbonHome);
System.setProperty(ExtensionConstants.CARBON_HOME, carbonHome); System.setProperty(ExtensionConstants.CARBON_HOME, carbonHome);
// Need to give time for the apis to be added to the synapse configurations.
Thread.sleep(30000);
} }
} catch (Exception e) { } catch (Exception e) {
handleException("Fail to start carbon server ", e); handleException("Fail to start carbon server ", e);

@ -19,44 +19,103 @@ package org.wso2.iot.integration.role;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.net.util.Base64;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.automation.engine.context.beans.User;
import org.wso2.iot.integration.common.*; import org.wso2.iot.integration.common.*;
import javax.xml.xpath.XPathExpressionException;
import java.io.FileNotFoundException;
/** /**
* This class contains integration tests for role management backend services. * This class contains integration tests for role management backend services.
*/ */
public class RoleManagement extends TestBase { public class RoleManagement extends TestBase {
private IOTHttpClient client; private IOTHttpClient client;
private TestUserMode userMode;
@Factory(dataProvider = "userModeProvider")
public RoleManagement(TestUserMode userMode) {
this.userMode = userMode;
}
@BeforeClass(alwaysRun = true, groups = { Constants.RoleManagement.ROLE_MANAGEMENT_GROUP}) @BeforeClass(alwaysRun = true, groups = { Constants.RoleManagement.ROLE_MANAGEMENT_GROUP})
public void initTest() throws Exception { public void initTest() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN); super.init(userMode);
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); User currentUser = getAutomationContext().getContextTenant().getContextUser();
byte[] bytesEncoded = Base64
.encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes());
String encoded = new String(bytesEncoded);
String accessTokenString = "Bearer " + OAuthUtil
.getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(),
currentUser.getPassword());
this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
} }
@Test(description = "Test add role.") @Test(description = "Test add role.")
public void testAddRole() throws Exception { public void testAddRole() throws FileNotFoundException {
IOTResponse response = client.post(Constants.RoleManagement.ADD_ROLE_ENDPOINT, IOTResponse response = client.post(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT,
PayloadGenerator.getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, PayloadGenerator.getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_POST).toString()); Constants.HTTP_METHOD_POST).toString());
Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus()); Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus());
} }
@Test(description = "Test update permission role.", dependsOnMethods = {"testAddRole"}) @Test(description = "Test update permission role.", dependsOnMethods = {"testAddRole"})
public void testUpdateRolePermission() throws Exception { public void testUpdateRolePermission() throws FileNotFoundException {
IOTResponse response = client.put(Constants.RoleManagement.UPDATE_ROLE_PERMISSION_ENDPOINT, IOTResponse response = client.put(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/administration",
PayloadGenerator.getJsonPayload(Constants.RoleManagement.UPDATE_ROLE_PERMISSION_PAYLOAD_FILE_NAME, PayloadGenerator.getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_PUT).toString()); Constants.HTTP_METHOD_PUT).toString());
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
} }
@Test(description = "Test remove user.", dependsOnMethods = {"testUpdateRolePermission"}) @Test(description = "Test get roles.", dependsOnMethods = {"testUpdateRolePermission"})
public void testGetRoles() throws FileNotFoundException {
IOTResponse response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "?offset=0&limit=2");
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
AssertUtil.jsonPayloadCompare(PayloadGenerator
.getJsonPayload(Constants.RoleManagement.ROLE_RESPONSE_PAYLOAD_FILE_NAME,
Constants.UserManagement.GET_ROLES_METHOD).toString(), response.getBody(), true);
}
@Test(description = "Test getting roles that has particular prefix.", dependsOnMethods = {"testGetRoles"})
public void testGetFilteredRoles() throws FileNotFoundException {
IOTResponse response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT +
"/filter/administ?offset=0&limit=2");
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
AssertUtil.jsonPayloadCompare(PayloadGenerator
.getJsonPayload(Constants.RoleManagement.ROLE_RESPONSE_PAYLOAD_FILE_NAME,
Constants.RoleManagement.GET_FILTERED_ROLED_METHOD).toString(), response.getBody(), true);
}
@Test(description = "Test getting permissions of a role.", dependsOnMethods = {"testGetFilteredRoles"})
public void testGetRolePermissions() throws FileNotFoundException {
IOTResponse response = client
.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/administration/permissions");
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
}
@Test(description = "Test getting role details.", dependsOnMethods = {"testGetRolePermissions"})
public void testGetRole() throws FileNotFoundException {
IOTResponse response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT +
"/administration");
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
}
@Test(description = "Test remove user.", dependsOnMethods = {"testGetRole"})
public void testRemoveRole() throws Exception { public void testRemoveRole() throws Exception {
IOTResponse response = client.delete(Constants.RoleManagement.REMOVE_ROLE_ENDPOINT); IOTResponse response = client.delete(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT +"/administration");
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
} }
@DataProvider
private static Object[][] userModeProvider() {
return new TestUserMode[][]{
new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN},
new TestUserMode[]{TestUserMode.TENANT_ADMIN}
};
}
} }

@ -18,71 +18,180 @@
package org.wso2.iot.integration.user; package org.wso2.iot.integration.user;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.net.util.Base64;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.automation.engine.context.beans.User;
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
import org.wso2.iot.integration.common.*; import org.wso2.iot.integration.common.AssertUtil;
import org.wso2.iot.integration.common.Constants;
import org.wso2.iot.integration.common.OAuthUtil;
import org.wso2.iot.integration.common.PayloadGenerator;
import org.wso2.iot.integration.common.RestClient;
import org.wso2.iot.integration.common.TestBase;
/** /**
* This class contains integration tests for user management backend services. * This class contains integration tests for user management backend services.
*/ */
public class UserManagement extends TestBase { public class UserManagement extends TestBase {
private String NON_EXISTING_USERNAME = "non_exiting";
private RestClient client; private RestClient client;
private TestUserMode userMode;
@Factory(dataProvider = "userModeProvider")
public UserManagement(TestUserMode userMode) {
this.userMode = userMode;
}
@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP})
public void initTest() throws Exception { public void initTest() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN); super.init(userMode);
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); User currentUser = getAutomationContext().getContextTenant().getContextUser();
byte[] bytesEncoded = Base64
.encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes());
String encoded = new String(bytesEncoded);
String accessTokenString = "Bearer " + OAuthUtil
.getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(),
currentUser.getPassword());
this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
} }
@Test(description = "Test add user.") @Test(description = "Test add user.")
public void testAddUser() throws Exception { public void testAddUser() throws Exception {
HttpResponse response = client.post(Constants.UserManagement.USER_ENDPOINT, // Add a user with the details and check whether that user is added correctly.
PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_PAYLOAD_FILE_NAME, HttpResponse response = client.post(Constants.UserManagement.USER_ENDPOINT, PayloadGenerator
Constants.HTTP_METHOD_POST).toString()); .getJsonPayload(Constants.UserManagement.USER_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST)
.toString());
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME, AssertUtil.jsonPayloadCompare(PayloadGenerator
Constants.HTTP_METHOD_POST).toString(), response.getData().toString(), true); .getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST)
.toString(), response.getData(), true);
} }
@Test(description = "Test update user.", dependsOnMethods = {"testAddUser"}) @Test(description = "Test update user.", dependsOnMethods = {"testAddUser"})
public void testUpdateUser() throws Exception { public void testUpdateUser() throws Exception {
String url = GetURL(Constants.UserManagement.USER_ENDPOINT); // Update a existing user
HttpResponse response = client.put(url, String url = Constants.UserManagement.USER_ENDPOINT + "/" + Constants.UserManagement.USER_NAME;
PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_PAYLOAD_FILE_NAME, HttpResponse response = client.put(url, PayloadGenerator
Constants.HTTP_METHOD_PUT).toString()); .getJsonPayload(Constants.UserManagement.USER_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_PUT).toString());
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME, AssertUtil.jsonPayloadCompare(PayloadGenerator
Constants.HTTP_METHOD_PUT).toString(), response.getData().toString(), true); .getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_PUT)
.toString(), response.getData(), true);
} }
@Test(description = "Test view user.", dependsOnMethods = {"testUpdateUser"}) @Test(description = "Test view user.", dependsOnMethods = {"testUpdateUser"})
public void testViewUser() throws Exception { public void testViewUser() throws Exception {
String url = GetURL(Constants.UserManagement.VIEW_USER_ENDPOINT); String url = Constants.UserManagement.USER_ENDPOINT + "/" + Constants.UserManagement.USER_NAME;
HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator
.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_GET)
.toString(), response.getData(), true);
}
@Test(description = "Test getting user roles.", dependsOnMethods = {"testViewUser"})
public void testGetUserRoles() throws Exception {
String url = Constants.UserManagement.USER_ENDPOINT + "/" + Constants.UserManagement.USER_NAME + "/roles";
HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator
.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME,
Constants.UserManagement.GET_ROLES_METHOD).toString(), response.getData(), true);
url = Constants.UserManagement.USER_ENDPOINT + "/" + NON_EXISTING_USERNAME + "/roles";
response = client.get(url);
Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getResponseCode());
}
@Test(description = "Test the API that checks whether user exist.", dependsOnMethods = {"testGetUserRoles"})
public void testIsUserExist() throws Exception {
String url = Constants.UserManagement.USER_ENDPOINT + "/checkUser?username=" + Constants.UserManagement
.USER_NAME;
HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
Assert.assertEquals(
"CheckUser API return false even the user with the username " + Constants.UserManagement.USER_NAME
+ "exists", true, Boolean.parseBoolean(response.getData()));
url = Constants.UserManagement.USER_ENDPOINT + "/checkUser?username=" + NON_EXISTING_USERNAME;
response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
Assert.assertEquals("CheckUser API return true but user with " + NON_EXISTING_USERNAME + "exists", false,
Boolean.parseBoolean(response.getData()));
}
@Test(description = "Test whether correct user count is returned.", dependsOnMethods = {"testIsUserExist"})
public void testUserCount() throws Exception {
String url = Constants.UserManagement.USER_ENDPOINT + "/count";
HttpResponse response = client.get(url); HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_GET).toString(), response.getData().toString(), true); JsonObject jsonElement = new JsonParser().parse(response.getData()).getAsJsonObject();
Assert.assertEquals("Actual user count does not match with the returned user count", 4,
jsonElement.get("count").getAsInt());
} }
@Test(description = "Test remove user.", dependsOnMethods = {"testViewUser"}) @Test(description = "Test whether the API that is used to get the users returns all the user details.",
dependsOnMethods = {"testUserCount"})
public void testGetUsers() throws Exception {
String url = Constants.UserManagement.USER_ENDPOINT + "/?offset=0&limit=100";
HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
JsonObject jsonElement = new JsonParser().parse(response.getData()).getAsJsonObject();
Assert.assertEquals("All the users list is not returned", 4, jsonElement.get("users").getAsJsonArray().size());
}
@Test(description = "Test whether the API that is used to get the users with particular filter returns all the "
+ "user details that satisfy particular filter.", dependsOnMethods = {"testGetUsers"})
public void testSearchUserNames() throws Exception {
String url = Constants.UserManagement.USER_ENDPOINT + "/search/usernames?filter="
+ Constants.UserManagement.USER_NAME;
HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
Assert.assertEquals("Relevant filtered user list in not returned correctly.", 1,
jsonArray.size());
url = Constants.UserManagement.USER_ENDPOINT + "/search/usernames?filter=" + NON_EXISTING_USERNAME;
response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
Assert.assertEquals("Relevant filtered user list in not returned correctly. Return a list of users for "
+ "non-existing username", 0, jsonArray.size());
}
@Test(description = "Test remove user.", dependsOnMethods = {"testSearchUserNames"})
public void testRemoveUser() throws Exception { public void testRemoveUser() throws Exception {
String url = GetURL(Constants.UserManagement.USER_ENDPOINT); String url = Constants.UserManagement.USER_ENDPOINT + "/" + Constants.UserManagement.USER_NAME ;
HttpResponse response = client.delete(url); HttpResponse response = client.delete(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_DELETE).toString(), response.getData().toString(), true);
} }
private String GetURL(String endPoint) { @Test(description = "Test whether the API that is used to change the password works as expected.",
return endPoint + "?username=" + Constants.UserManagement.USER_NAME; dependsOnMethods = {"testRemoveUser"})
public void testChangePassword() throws Exception {
String url = Constants.UserManagement.USER_ENDPOINT + "/credentials";
HttpResponse response = client.put(url, PayloadGenerator
.getJsonPayload(Constants.UserManagement.USER_PAYLOAD_FILE_NAME,
Constants.UserManagement.RESET_PASSWORD_PAYLOAD).toString());
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
Assert.assertEquals("Password of the user cannot be changed",
"\"UserImpl password by " + "username: admin was successfully changed.\"", response.getData());
} }
@DataProvider
private static Object[][] userModeProvider() {
return new TestUserMode[][]{
new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN},
new TestUserMode[]{TestUserMode.TENANT_ADMIN}
};
}
} }

@ -6,10 +6,12 @@
] ]
}, },
"PUT": { "PUT": {
"roleName": "administration",
"users": [
"admin"
],
"permissions": [ "permissions": [
"permission/admin/device-mgt/android/operations/disenroll", "/permission/admin/device-mgt/admin/groups"
"permission/admin/device-mgt/android/operations/notification",
"/permission/admin/device-mgt/windows/operation/lock"
] ]
} }
} }

@ -0,0 +1,10 @@
{
"GET_ROLES": {
"roles": ["admin", "administration"],
"count": 2
},
"GET_FILTERED_ROLES": {
"roles": ["administration"],
"count": 1
}
}

@ -18,5 +18,9 @@
"admin", "admin",
"Internal/everyone" "Internal/everyone"
] ]
},
"RESET_PASSWORD" : {
"oldPassword" : "admin",
"newPassword" : "admin"
} }
} }

@ -1,24 +1,28 @@
{ {
"POST": { "POST": {
"statusCode": 201, "username":"PRIMARY/username123",
"messageFromServer": "User by username: PRIMARY/username123 was successfully added." "firstname":"userfirstname",
"lastname":"userlastname",
"emailAddress":"user123@gmail.com"
}, },
"PUT": { "PUT": {
"statusCode": 201, "username":"username123",
"messageFromServer": "User by username: username123 was successfully updated." "firstname":"userfname",
"lastname":"userlname",
"emailAddress":"user1234@gmail.com"
}, },
"GET": { "GET": {
"statusCode": 200,
"messageFromServer": "User information was retrieved successfully.",
"responseContent": {
"username": "username123", "username": "username123",
"firstname": "userfname", "firstname": "userfname",
"lastname": "userlname", "lastname": "userlname",
"emailAddress": "user1234@gmail.com" "emailAddress": "user1234@gmail.com"
}
}, },
"DELETE": { "GET_ROLES": {
"statusCode": 200, "roles": ["admin"],
"messageFromServer": "User by username: username123 was successfully removed." "count": 0
},
"GET_USERS": {
"users": ["admin"],
"count": 3
} }
} }

@ -73,16 +73,11 @@
<!--<class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagement"/>--> <!--<class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagement"/>-->
<!--</classes>--> <!--</classes>-->
<!--</test>--> <!--</test>-->
<!--<test name="user-mgt" preserve-order="true" parallel="false">--> <test name="role-mgt" preserve-order="true" parallel="false">
<!--<classes>--> <classes>
<!--<class name="org.wso2.iot.integration.user.UserManagement"/>--> <class name="org.wso2.iot.integration.role.RoleManagement"/>
<!--</classes>--> </classes>
<!--</test>--> </test>
<!--<test name="role-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.role.RoleManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="policy-mgt" preserve-order="true" parallel="false">--> <!--<test name="policy-mgt" preserve-order="true" parallel="false">-->
<!--<classes>--> <!--<classes>-->
<!--<class name="org.wso2.iot.integration.policy.PolicyManagement"/>--> <!--<class name="org.wso2.iot.integration.policy.PolicyManagement"/>-->
@ -108,4 +103,9 @@
<!--<class name="org.wso2.iot.integration.notification.NotificationManagement"/>--> <!--<class name="org.wso2.iot.integration.notification.NotificationManagement"/>-->
<!--</classes>--> <!--</classes>-->
<!--</test>--> <!--</test>-->
<test name="user-mgt" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.user.UserManagement"/>
</classes>
</test>
</suite> </suite>

@ -1518,7 +1518,7 @@
<!-- Carbon Device Management --> <!-- Carbon Device Management -->
<carbon.device.mgt.version>2.0.42</carbon.device.mgt.version> <carbon.device.mgt.version>2.0.43</carbon.device.mgt.version>
<carbon.device.mgt.version.range>[2.0.0, 3.0.0)</carbon.device.mgt.version.range> <carbon.device.mgt.version.range>[2.0.0, 3.0.0)</carbon.device.mgt.version.range>
<!-- IOT Device Management --> <!-- IOT Device Management -->

Loading…
Cancel
Save