Search in sources :

Example 61 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class RemoveAcesTest method testRemoveAce.

//test removing a single ace
public void testRemoveAce() throws IOException, JsonException {
    String folderUrl = createFolderWithAces(false);
    //remove the ace for the testUser principal
    String postUrl = folderUrl + ".deleteAce.html";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":applyTo", testUserId));
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    //fetch the JSON for the acl to verify the settings.
    String getUrl = folderUrl + ".acl.json";
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObject = JsonUtil.parseObject(json);
    assertNotNull(jsonObject);
    assertEquals(0, jsonObject.size());
}
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 62 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class RemoveAcesTest method createFolderWithAces.

private String createFolderWithAces(boolean addGroupAce) throws IOException, JsonException {
    testUserId = createTestUser();
    testFolderUrl = createTestFolder();
    String postUrl = testFolderUrl + ".modifyAce.html";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("principalId", testUserId));
    postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:write", "denied"));
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    if (addGroupAce) {
        testGroupId = createTestGroup();
        postParams = new ArrayList<NameValuePair>();
        postParams.add(new NameValuePair("principalId", testGroupId));
        postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
        assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    }
    //fetch the JSON for the acl to verify the settings.
    String getUrl = testFolderUrl + ".acl.json";
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObject = JsonUtil.parseObject(json);
    if (addGroupAce) {
        assertEquals(2, jsonObject.size());
    } else {
        assertEquals(1, jsonObject.size());
    }
    JsonObject aceObject = jsonObject.getJsonObject(testUserId);
    assertNotNull(aceObject);
    assertEquals(0, aceObject.getInt("order"));
    String principalString = aceObject.getString("principal");
    assertEquals(testUserId, principalString);
    JsonArray grantedArray = aceObject.getJsonArray("granted");
    assertNotNull(grantedArray);
    assertEquals("jcr:read", grantedArray.getString(0));
    JsonArray deniedArray = aceObject.getJsonArray("denied");
    assertNotNull(deniedArray);
    assertEquals("jcr:write", deniedArray.getString(0));
    if (addGroupAce) {
        aceObject = jsonObject.getJsonObject(testGroupId);
        assertNotNull(aceObject);
        principalString = aceObject.getString("principal");
        assertEquals(testGroupId, principalString);
        assertEquals(1, aceObject.getInt("order"));
        grantedArray = aceObject.getJsonArray("granted");
        assertNotNull(grantedArray);
        assertEquals("jcr:read", grantedArray.getString(0));
    }
    return testFolderUrl;
}
Also used : JsonArray(javax.json.JsonArray) 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 63 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class RemoveAcesTest method tearDown.

@Override
public void tearDown() throws Exception {
    super.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"));
        assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    }
    if (testGroupId != null) {
        //remove the test user if it exists.
        String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".delete.html";
        List<NameValuePair> postParams = new ArrayList<NameValuePair>();
        assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    }
    if (testUserId != null) {
        //remove the test user if it exists.
        String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".delete.html";
        List<NameValuePair> postParams = new ArrayList<NameValuePair>();
        assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    }
//todo delete test folder
}
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)

Example 64 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class AuthenticationResponseCodeTest method testValidatingCorrectHttpBasicCredentials.

@Test
public void testValidatingCorrectHttpBasicCredentials() throws Exception {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_validate", "true"));
    HttpMethod post = H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_OK, params, null);
    assertTrue(post.getResponseBodyAsString().length() == 0);
    HttpMethod get = H.assertHttpStatus(HttpTest.HTTP_BASE_URL + "/?j_validate=true", HttpServletResponse.SC_OK);
    assertTrue(get.getResponseBodyAsString().length() == 0);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) HttpMethod(org.apache.commons.httpclient.HttpMethod) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 65 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class AuthenticationResponseCodeTest method testWithoutAcceptHeaderIncorrectCredentials.

@Test
public void testWithoutAcceptHeaderIncorrectCredentials() throws Exception {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_username", "garbage"));
    params.add(new NameValuePair("j_password", "garbage"));
    H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_UNAUTHORIZED, params, null);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Aggregations

NameValuePair (org.apache.commons.httpclient.NameValuePair)217 ArrayList (java.util.ArrayList)114 Credentials (org.apache.commons.httpclient.Credentials)64 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)64 Test (org.junit.Test)61 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)49 JsonObject (javax.json.JsonObject)43 PostMethod (org.apache.commons.httpclient.methods.PostMethod)41 HashMap (java.util.HashMap)28 IOException (java.io.IOException)23 Header (org.apache.commons.httpclient.Header)21 JsonArray (javax.json.JsonArray)20 HttpClient (org.apache.commons.httpclient.HttpClient)19 HashSet (java.util.HashSet)17 HttpMethod (org.apache.commons.httpclient.HttpMethod)16 GetMethod (org.apache.commons.httpclient.methods.GetMethod)16 Cookie (org.apache.commons.httpclient.Cookie)13 GetRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest)10 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8