use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class NodeCorruptionTest method testCopyMultiSingleValue.
public void testCopyMultiSingleValue() throws Exception {
Node root = superuser.getRootNode();
String nodeName = "testCopyMulti" + System.currentTimeMillis();
if (root.hasNode(nodeName)) {
root.getNode(nodeName).remove();
superuser.save();
}
Node test = root.addNode(nodeName);
test.setProperty("x", "Hi");
superuser.save();
String wsp = superuser.getWorkspace().getName();
String workspace2 = getAlternativeWorkspaceName();
if (workspace2 == null) {
throw new NotExecutableException();
}
Session s2 = getHelper().getSuperuserSession(workspace2);
s2.getWorkspace().clone(wsp, "/" + nodeName, "/" + nodeName, true);
Node test2 = s2.getRootNode().getNode(nodeName);
test2.setProperty("x", (Value) null);
test2.setProperty("x", new String[] {});
s2.save();
test.update(workspace2);
try {
Value[] values = test.getProperty("x").getValues();
assertEquals(0, values.length);
} catch (RepositoryException e) {
// if we get here, it's a bug, as it is a multi-valued property now
// anyway, let's see what happens if we try to read it as a single valued property
test.getProperty("x").getValue();
// even if that works: it's still a bug
throw e;
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class WriteTest method testEditor2.
public void testEditor2() throws NotExecutableException, RepositoryException {
UserManager uMgr = getUserManager(superuser);
User u = null;
User u2 = null;
try {
u = uMgr.createUser("t", "t");
u2 = uMgr.createUser("tt", "tt", new TestPrincipal("tt"), "t/tt");
if (!uMgr.isAutoSave()) {
superuser.save();
}
Principal p = u.getPrincipal();
Principal p2 = u2.getPrincipal();
if (p instanceof ItemBasedPrincipal && p2 instanceof ItemBasedPrincipal && Text.isDescendant(((ItemBasedPrincipal) p).getPath(), ((ItemBasedPrincipal) p2).getPath())) {
JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) getAccessControlManager(superuser);
JackrabbitAccessControlPolicy[] acls = acMgr.getApplicablePolicies(p2);
acMgr.setPolicy(acls[0].getPath(), acls[0]);
acls = acMgr.getApplicablePolicies(p);
String path = acls[0].getPath();
Node n = superuser.getNode(path);
assertEquals("rep:PrincipalAccessControl", n.getPrimaryNodeType().getName());
} else {
throw new NotExecutableException();
}
} finally {
superuser.refresh(false);
if (u2 != null)
u2.remove();
if (u != null)
u.remove();
if (!uMgr.isAutoSave()) {
superuser.save();
}
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class WriteTest method testInvalidPrincipal.
public void testInvalidPrincipal() throws Exception {
PrincipalManager pMgr = ((JackrabbitSession) superuser).getPrincipalManager();
String unknown = "unknown";
while (pMgr.hasPrincipal(unknown)) {
unknown = unknown + "_";
}
Principal principal = new PrincipalImpl(unknown);
if (acMgr instanceof JackrabbitAccessControlManager) {
// first try applicable policies
try {
AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acMgr).getApplicablePolicies(principal);
assertNotNull(policies);
assertEquals(0, policies.length);
} catch (AccessControlException e) {
// success
}
// second existing policies
try {
AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acMgr).getPolicies(principal);
assertNotNull(policies);
assertEquals(0, policies.length);
} catch (AccessControlException e) {
// success
}
} else {
throw new NotExecutableException();
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class AdministratorTest method testAdminNodeCollidingWithAuthorizableFolder.
/**
* Test for collisions that would prevent from recreate the admin user.
* - an intermediate rep:AuthorizableFolder node with the same name
*/
public void testAdminNodeCollidingWithAuthorizableFolder() throws RepositoryException, NotExecutableException {
Authorizable admin = userMgr.getAuthorizable(adminId);
if (admin == null || !(admin instanceof AuthorizableImpl)) {
throw new NotExecutableException();
}
// access the node corresponding to the admin user and remove it
NodeImpl adminNode = ((AuthorizableImpl) admin).getNode();
String adminPath = adminNode.getPath();
String adminNodeName = adminNode.getName();
Node parentNode = adminNode.getParent();
Session s = adminNode.getSession();
adminNode.remove();
// use session obtained from the node as usermgr may point to a dedicated
// system workspace different from the superusers workspace.
s.save();
Session s2 = null;
String collidingPath = null;
try {
// now create a colliding node:
Node n = parentNode.addNode(adminNodeName, "rep:AuthorizableFolder");
collidingPath = n.getPath();
s.save();
// force recreation of admin user.
s2 = getHelper().getSuperuserSession();
admin = userMgr.getAuthorizable(adminId);
assertNotNull(admin);
assertEquals(adminNodeName, ((AuthorizableImpl) admin).getNode().getName());
assertFalse(adminPath.equals(((AuthorizableImpl) admin).getNode().getPath()));
} finally {
if (s2 != null) {
s2.logout();
}
// remove the extra folder and the admin user (created underneath) again.
if (collidingPath != null) {
s.getNode(collidingPath).remove();
s.save();
}
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class AuthorizableActionTest method assertAcAction.
private static void assertAcAction(Authorizable a, UserManagerImpl umgr) throws RepositoryException, NotExecutableException {
Session s = umgr.getSession();
AccessControlManager acMgr = s.getAccessControlManager();
boolean hasACL = false;
AccessControlPolicyIterator it = acMgr.getApplicablePolicies("/");
while (it.hasNext()) {
if (it.nextAccessControlPolicy() instanceof AccessControlList) {
hasACL = true;
break;
}
}
if (!hasACL) {
for (AccessControlPolicy p : acMgr.getPolicies("/")) {
if (p instanceof AccessControlList) {
hasACL = true;
break;
}
}
}
if (!hasACL) {
throw new NotExecutableException("No ACLs in workspace containing users.");
}
String path = a.getPath();
assertEquals(1, acMgr.getPolicies(path).length);
assertTrue(acMgr.getPolicies(path)[0] instanceof AccessControlList);
}
Aggregations