use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class RemoveAuthorizablesTest method testRemoveGroupWithMembers.
/**
* Test the problem reported as SLING-1237
*/
public void testRemoveGroupWithMembers() throws IOException {
String groupId = createTestGroup();
String userId = createTestUser();
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String addMemberPostUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".update.html";
List<NameValuePair> addMemberPostParams = new ArrayList<NameValuePair>();
addMemberPostParams.add(new NameValuePair(":member", userId));
assertAuthenticatedPostStatus(creds, addMemberPostUrl, HttpServletResponse.SC_OK, addMemberPostParams, null);
String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
//make sure the profile request returns some data
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null);
String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".delete.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
//make sure the profile request returns some data
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, null);
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class UpdateGroupTest method testUpdateGroupMembers.
public void testUpdateGroupMembers() throws IOException, JsonException {
testGroupId = createTestGroup();
testUserId = createTestUser();
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
// verify that the members array exists, but is empty
JsonArray members = getTestGroupMembers(creds);
assertEquals(0, members.size());
JsonArray memberships = getTestUserMemberships(creds);
assertEquals(0, memberships.size());
String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
// add a group member
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":member", testUserId));
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
members = getTestGroupMembers(creds);
assertEquals(1, members.size());
assertEquals("/system/userManager/user/" + testUserId, members.getString(0));
memberships = getTestUserMemberships(creds);
assertEquals(1, memberships.size());
assertEquals("/system/userManager/group/" + testGroupId, memberships.getString(0));
// delete a group member
postParams.clear();
postParams.add(new NameValuePair(":member@Delete", testUserId));
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
members = getTestGroupMembers(creds);
assertEquals(0, members.size());
memberships = getTestUserMemberships(creds);
assertEquals(0, memberships.size());
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class UserPrivilegesInfoTest method cleanup.
@After
public void cleanup() throws Exception {
H.tearDown();
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
if (testFolderUrl != null) {
//remove the test user if it exists.
String postUrl = testFolderUrl;
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":operation", "delete"));
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
if (testGroupId != null) {
//remove the test user if it exists.
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".delete.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
if (testUserId != null) {
//remove the test user if it exists.
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".delete.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
if (testUserId2 != null) {
//remove the test user if it exists.
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId2 + ".delete.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
for (String script : toDelete) {
H.getTestClient().delete(script);
}
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class UserPrivilegesInfoTest method testCanUpdateUserProperties.
/**
* Checks whether the current user has been granted privileges
* to update the properties of the specified user.
*/
@Test
public void testCanUpdateUserProperties() throws IOException, JsonException {
testUserId = H.createTestUser();
//1. verify user can update thier own properties
String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".privileges-info.json";
//fetch the JSON for the test page to verify the settings.
Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");
String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObj = JsonUtil.parseObject(json);
//user can update their own properties
assertEquals(true, jsonObj.getBoolean("canUpdateProperties"));
//2. now try another user
testUserId2 = H.createTestUser();
//fetch the JSON for the test page to verify the settings.
Credentials testUser2Creds = new UsernamePasswordCredentials(testUserId2, "testPwd");
String json2 = H.getAuthenticatedContent(testUser2Creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json2);
JsonObject jsonObj2 = JsonUtil.parseObject(json2);
//user can not update other users properties
assertEquals(false, jsonObj2.getBoolean("canUpdateProperties"));
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class UserPrivilegesInfoTest method testCanRemoveUser.
/**
* Checks whether the current user has been granted privileges
* to remove the specified user.
*/
@Test
public void testCanRemoveUser() throws IOException, JsonException {
testUserId = H.createTestUser();
//1. verify user can not remove themselves
String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".privileges-info.json";
//fetch the JSON for the test page to verify the settings.
Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");
String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObj = JsonUtil.parseObject(json);
//user can not remove themselves
assertEquals(false, jsonObj.getBoolean("canRemove"));
//2. now try another user
testUserId2 = H.createTestUser();
//fetch the JSON for the test page to verify the settings.
Credentials testUser2Creds = new UsernamePasswordCredentials(testUserId2, "testPwd");
String json2 = H.getAuthenticatedContent(testUser2Creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json2);
JsonObject jsonObj2 = JsonUtil.parseObject(json2);
//user can not delete other users
assertEquals(false, jsonObj2.getBoolean("canRemove"));
}
Aggregations