use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class UpdateGroupTest method testUpdateGroupResponseAsJSON.
/**
* Test for SLING-1677
*/
public void testUpdateGroupResponseAsJSON() throws IOException, JsonException {
testGroupId = createTestGroup();
String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.json";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("displayName", "My Updated Test Group"));
postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//make sure the json response can be parsed as a JSON object
JsonObject jsonObj = JsonUtil.parseObject(json);
assertNotNull(jsonObj);
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class UpdateUserTest method testUpdateUser.
@Test
public void testUpdateUser() throws IOException, JsonException {
testUserId = H.createTestUser();
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".update.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("displayName", "My Updated Test User"));
postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
// add nested param (SLING-6747)
postParams.add(new NameValuePair("nested/param", "value"));
Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
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";
//make sure the profile request returns some data
H.assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null);
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals("My Updated Test User", jsonObj.getString("displayName"));
assertEquals("http://www.apache.org/updated", jsonObj.getString("url"));
// get path (SLING-6753)
String path = jsonObj.getString("path");
assertNotNull(path);
// retrieve nested property via regular GET servlet
getUrl = HttpTest.HTTP_BASE_URL + path + "/nested.json";
json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
jsonObj = JsonUtil.parseObject(json);
assertEquals("value", jsonObj.getString("param"));
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class UpdateUserTest method testChangeUserPassword.
@Test
public void testChangeUserPassword() throws IOException {
testUserId = H.createTestUser();
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".changePassword.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("oldPwd", "testPwd"));
postParams.add(new NameValuePair("newPwd", "testNewPwd"));
postParams.add(new NameValuePair("newPwdConfirm", "testNewPwd"));
Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class UpdateUserTest method testChangeUserPasswordWrongConfirmPwd.
@Test
public void testChangeUserPasswordWrongConfirmPwd() throws IOException {
testUserId = H.createTestUser();
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".changePassword.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("oldPwd", "testPwd"));
postParams.add(new NameValuePair("newPwd", "testNewPwd"));
postParams.add(new NameValuePair("newPwdConfirm", "wrongTestNewPwd"));
//Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class UserManagerTestUtil method addUserToGroup.
/**
* Helper to assist adding a user to a group
* @param testUserId the user
* @param testGroupId the group
*/
public void addUserToGroup(String testUserId, String testGroupId) throws IOException {
String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":member", testUserId));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
final String info = "Adding user " + testUserId + " to group via " + postUrl;
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, info);
}
Aggregations