use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class CreateUserTest method testCreateUserWrongConfirmPwd.
@Test
public void testCreateUserWrongConfirmPwd() throws IOException {
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
String userId = "testUser" + random.nextInt();
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":name", userId));
postParams.add(new NameValuePair("pwd", "testPwd"));
postParams.add(new NameValuePair("pwdConfirm", "testPwd2"));
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 CreateUserTest method testCreateUserMissingPwd.
@Test
public void testCreateUserMissingPwd() throws IOException {
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
String userId = "testUser" + random.nextInt();
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":name", userId));
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 CreateUserTest method testCreateUserUserAlreadyExists.
@Test
public void testCreateUserUserAlreadyExists() throws IOException {
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("pwd", "testPwd"));
postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//post the same info again, should fail
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 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);
}
Aggregations