use of org.apache.commons.httpclient.UsernamePasswordCredentials in project sling by apache.
the class AuthenticationResponseCodeTest method testValidatingIncorrectHttpBasicCredentials.
@Test
public void testValidatingIncorrectHttpBasicCredentials() throws Exception {
// assume http and webdav are on the same host + port
URL url = new URL(HttpTest.HTTP_BASE_URL);
Credentials defaultcreds = new UsernamePasswordCredentials("garbage", "garbage");
H.getHttpClient().getState().setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);
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_FORBIDDEN, params, null);
assertXReason(post);
HttpMethod get = H.assertHttpStatus(HttpTest.HTTP_BASE_URL + "/?j_validate=true", HttpServletResponse.SC_FORBIDDEN);
assertXReason(get);
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project sling by apache.
the class ModifyAceTest method testAddAceOrderByFirst.
/**
* Test to verify adding an ACE in the first position of
* the ACL
*/
@Test
public void testAddAceOrderByFirst() throws IOException, JsonException {
createAceOrderTestFolderWithOneAce();
testGroupId = H.createTestGroup();
addOrUpdateAce(testFolderUrl, testGroupId, true, "first");
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(2, jsonObject.size());
JsonObject group = jsonObject.getJsonObject(testGroupId);
assertNotNull(group);
assertEquals(testGroupId, group.getString("principal"));
assertEquals(0, group.getInt("order"));
JsonObject user = jsonObject.getJsonObject(testUserId);
assertNotNull(user);
assertEquals(testUserId, user.getString("principal"));
assertEquals(1, user.getInt("order"));
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project sling by apache.
the class RemoveAcesTest method testRemoveAcesResponseAsJSON.
/**
* Test for SLING-1677
*/
public void testRemoveAcesResponseAsJSON() throws IOException, JsonException {
String folderUrl = createFolderWithAces(true);
//remove the ace for the testUser principal
String postUrl = folderUrl + ".deleteAce.json";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":applyTo", testUserId));
postParams.add(new NameValuePair(":applyTo", testGroupId));
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 jsonObject = JsonUtil.parseObject(json);
assertNotNull(jsonObject);
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project sling by apache.
the class ModifyAceTest method testModifyAceResponseAsJSON.
/**
* Test for SLING-1677
*/
@Test
public void testModifyAceResponseAsJSON() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.json";
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"));
//invalid value should be ignored.
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "bogus"));
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 jsonObject = JsonUtil.parseObject(json);
assertNotNull(jsonObject);
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project sling by apache.
the class ModifyAceTest method testAddAceOrderByAfter.
/**
* Test to verify adding an ACE after an existing ACE
* the ACL
*/
@Test
public void testAddAceOrderByAfter() throws IOException, JsonException {
createAceOrderTestFolderWithOneAce();
testGroupId = H.createTestGroup();
addOrUpdateAce(testFolderUrl, testGroupId, true, "after " + testUserId);
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(2, jsonObject.size());
JsonObject user = jsonObject.getJsonObject(testUserId);
assertNotNull(user);
assertEquals(testUserId, user.getString("principal"));
assertEquals(0, user.getInt("order"));
JsonObject group = jsonObject.getJsonObject(testGroupId);
assertNotNull(group);
assertEquals(testGroupId, group.getString("principal"));
assertEquals(1, group.getInt("order"));
}
Aggregations