use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeEditorTest method changeMandatoryPropertyToBadRequiredType.
@Test
public void changeMandatoryPropertyToBadRequiredType() {
EditorHook hook = new EditorHook(new TypeEditorProvider());
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeBuilder acl = builder.child(AccessControlConstants.REP_POLICY);
acl.setProperty(JCR_PRIMARYTYPE, AccessControlConstants.NT_REP_ACL, Type.NAME);
NodeBuilder ace = acl.child("first");
ace.setProperty(JCR_PRIMARYTYPE, AccessControlConstants.NT_REP_GRANT_ACE, Type.NAME);
ace.setProperty(AccessControlConstants.REP_PRINCIPAL_NAME, EveryonePrincipal.NAME);
ace.setProperty(AccessControlConstants.REP_PRIVILEGES, ImmutableList.of(PrivilegeConstants.JCR_READ), Type.NAMES);
NodeState before = builder.getNodeState();
// change to invalid type
ace.setProperty(AccessControlConstants.REP_PRIVILEGES, ImmutableList.of(PrivilegeConstants.JCR_READ), Type.STRINGS);
try {
hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
fail();
} catch (CommitFailedException e) {
assertTrue(e.isConstraintViolation());
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeEditorTest method addMandatoryPropertyWithBadRequiredType.
@Test
public void addMandatoryPropertyWithBadRequiredType() {
EditorHook hook = new EditorHook(new TypeEditorProvider());
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeState before = builder.getNodeState();
NodeBuilder acl = builder.child(AccessControlConstants.REP_POLICY);
acl.setProperty(JCR_PRIMARYTYPE, AccessControlConstants.NT_REP_ACL, Type.NAME);
NodeBuilder ace = acl.child("first");
ace.setProperty(JCR_PRIMARYTYPE, AccessControlConstants.NT_REP_GRANT_ACE, Type.NAME);
ace.setProperty(AccessControlConstants.REP_PRINCIPAL_NAME, EveryonePrincipal.NAME);
ace.setProperty(AccessControlConstants.REP_PRIVILEGES, ImmutableList.of(PrivilegeConstants.JCR_READ), Type.STRINGS);
try {
hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
fail();
} catch (CommitFailedException e) {
assertTrue(e.isConstraintViolation());
assertEquals(55, e.getCode());
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class PermissionValidatorTest method testChangePrimaryTypeToPolicyNode.
@Test
public void testChangePrimaryTypeToPolicyNode() throws Exception {
// create a rep:policy node that is not detected as access control content
testRootNode.getChild("child").addChild(AccessControlConstants.REP_POLICY, NT_UNSTRUCTURED);
root.commit();
// grant the test session the ability to read/write that node but don't
// allow to modify access control content
grant(TEST_ROOT_PATH, PrivilegeConstants.JCR_READ, PrivilegeConstants.JCR_READ_ACCESS_CONTROL, PrivilegeConstants.REP_WRITE);
ContentSession testSession = createTestSession();
try {
Root testRoot = testSession.getLatestRoot();
Tree testChild = testRoot.getTree(TEST_CHILD_PATH);
testChild.setProperty(PropertyStates.createProperty(JcrConstants.JCR_MIXINTYPES, ImmutableList.of(AccessControlConstants.MIX_REP_ACCESS_CONTROLLABLE), Type.NAMES));
Tree testPolicy = testChild.getChild(AccessControlConstants.REP_POLICY);
testPolicy.setOrderableChildren(true);
testPolicy.setProperty(JCR_PRIMARYTYPE, AccessControlConstants.NT_REP_ACL, Type.NAME);
testRoot.commit();
fail("Turning a false policy node into access control content requires the ability to write AC content.");
} catch (CommitFailedException e) {
assertTrue(e.isAccessViolation());
assertEquals(0, e.getCode());
} finally {
testSession.close();
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class CugValidatorTest method testChangePrimaryTypeOfCug.
@Test
public void testChangePrimaryTypeOfCug() throws Exception {
node.setNames(JcrConstants.JCR_MIXINTYPES, MIX_REP_CUG_MIXIN);
NodeUtil cug = node.addChild(REP_CUG_POLICY, NT_REP_CUG_POLICY);
cug.setStrings(REP_PRINCIPAL_NAMES, EveryonePrincipal.NAME);
root.commit();
try {
cug.setName(JcrConstants.JCR_PRIMARYTYPE, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
root.commit();
fail();
} catch (CommitFailedException e) {
assertTrue(e.isAccessControlViolation());
assertEquals(21, e.getCode());
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class CugValidatorTest method testMissingMixin.
@Test
public void testMissingMixin() throws Exception {
NodeUtil cug = node.addChild(REP_CUG_POLICY, NT_REP_CUG_POLICY);
cug.setStrings(REP_PRINCIPAL_NAMES, EveryonePrincipal.NAME);
try {
root.commit();
fail();
} catch (CommitFailedException e) {
assertTrue(e.isAccessControlViolation());
assertEquals(22, e.getCode());
} finally {
root.refresh();
}
}
Aggregations