use of org.apache.commons.httpclient.UsernamePasswordCredentials in project sling by apache.
the class CreateGroupTest method testCreateGroupWithExtraProperties.
public void testCreateGroupWithExtraProperties() throws IOException, JsonException {
String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.html";
testGroupId = "testGroup" + random.nextInt();
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":name", testGroupId));
postParams.add(new NameValuePair("marker", testGroupId));
postParams.add(new NameValuePair("displayName", "My Test Group"));
postParams.add(new NameValuePair("url", "http://www.apache.org"));
assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the group profile json to verify the settings
String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(testGroupId, jsonObj.getString("marker"));
assertEquals("My Test Group", jsonObj.getString("displayName"));
assertEquals("http://www.apache.org", jsonObj.getString("url"));
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project sling by apache.
the class CreateUserTest method testCreateUserResponseAsJSON.
/**
* Test for SLING-1677
*/
@Test
public void testCreateUserResponseAsJSON() throws IOException, JsonException {
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.json";
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"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.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.UsernamePasswordCredentials in project sling by apache.
the class CreateUserTest method testCreateUser.
/*
<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>
<input type="submit" value="Submit" />
</form>
*/
@Test
public void testCreateUser() throws IOException, JsonException {
testUserId = "testUser" + random.nextInt() + System.currentTimeMillis();
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
final 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"));
final Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
{
// fetch the user profile json to verify the settings
final String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
final String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
final JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(testUserId, jsonObj.getString("marker"));
assertFalse(jsonObj.containsKey(":name"));
assertFalse(jsonObj.containsKey("pwd"));
assertFalse(jsonObj.containsKey("pwdConfirm"));
}
{
// fetch the session info to verify that the user can log in
final Credentials newUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");
final String getUrl = HttpTest.HTTP_BASE_URL + "/system/sling/info.sessionInfo.json";
final String json = H.getAuthenticatedContent(newUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
final JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(testUserId, jsonObj.getString("userID"));
}
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials 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.UsernamePasswordCredentials 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"));
}
Aggregations