use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class CreateUserTest method testCreateUserWithExtraProperties.
/*
<form action="/system/userManager/user.create.html" method="POST">
<div>Name: <input type="text" name=":name" value="testUser" /></div>
<div>Password: <input type="text" name="pwd" value="testUser" /></div>
<div>Password Confirm: <input type="text" name="pwdConfirm" value="testUser" /></div>
<div>Extra Property #1: <input type="text" name="displayName" value="My Test User" /></div>
<div>Extra Property #2: <input type="text" name="url" value="http://www.apache.org" /></div>
<input type="submit" value="Submit" />
</form>
*/
@Test
public void testCreateUserWithExtraProperties() throws IOException, JsonException {
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
testUserId = "testUser" + random.nextInt();
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":name", testUserId));
postParams.add(new NameValuePair("marker", testUserId));
postParams.add(new NameValuePair("pwd", "testPwd"));
postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
postParams.add(new NameValuePair("displayName", "My Test User"));
postParams.add(new NameValuePair("url", "http://www.apache.org"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the user profile json to verify the settings
String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(testUserId, jsonObj.getString("marker"));
assertEquals("My Test User", jsonObj.getString("displayName"));
assertEquals("http://www.apache.org", jsonObj.getString("url"));
assertFalse(jsonObj.containsKey(":name"));
assertFalse(jsonObj.containsKey("pwd"));
assertFalse(jsonObj.containsKey("pwdConfirm"));
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class RemoveAuthorizablesTest method testRemoveAuthorizables.
public void testRemoveAuthorizables() throws IOException {
String userId = createTestUser();
String groupId = createTestGroup();
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
//make sure the profile request returns some data
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null);
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.delete.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":applyTo", "group/" + groupId));
postParams.add(new NameValuePair(":applyTo", "user/" + userId));
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
//make sure the profile request returns some data
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, 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 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);
}
}
Aggregations