Search in sources :

Example 66 with Credentials

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);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 67 with Credentials

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"));
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 68 with Credentials

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);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 69 with Credentials

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);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 70 with Credentials

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);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Aggregations

Credentials (org.apache.commons.httpclient.Credentials)102 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)102 ArrayList (java.util.ArrayList)64 NameValuePair (org.apache.commons.httpclient.NameValuePair)64 JsonObject (javax.json.JsonObject)52 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)51 Test (org.junit.Test)51 JsonArray (javax.json.JsonArray)19 AuthScope (org.apache.commons.httpclient.auth.AuthScope)17 HashSet (java.util.HashSet)14 GetMethod (org.apache.commons.httpclient.methods.GetMethod)12 HttpClient (org.apache.commons.httpclient.HttpClient)11 URL (java.net.URL)9 HttpMethod (org.apache.commons.httpclient.HttpMethod)5 IOException (java.io.IOException)4 HttpState (org.apache.commons.httpclient.HttpState)4 After (org.junit.After)4 InputStream (java.io.InputStream)3 Header (org.apache.commons.httpclient.Header)3 HttpException (org.apache.commons.httpclient.HttpException)3