use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeEditorTest method changeNodeTypeWExtraProps.
@Test
public void changeNodeTypeWExtraProps() throws CommitFailedException {
EditorHook hook = new EditorHook(new TypeEditorProvider());
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeState before = builder.getNodeState();
builder.child("testcontent").setProperty(JCR_PRIMARYTYPE, "nt:unstructured", Type.NAME);
builder.child("testcontent").setProperty("extra", "information");
NodeState after = builder.getNodeState();
root = hook.processCommit(before, after, CommitInfo.EMPTY);
builder = root.builder();
before = builder.getNodeState();
builder.child("testcontent").setProperty(JCR_PRIMARYTYPE, "nt:folder", Type.NAME);
try {
hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
fail("should not be able to change node type due to extra properties");
} catch (CommitFailedException e) {
assertTrue(e.isConstraintViolation());
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeEditorTest method changeNamedPropertyToBadRequiredType.
@Test
public void changeNamedPropertyToBadRequiredType() {
EditorHook hook = new EditorHook(new TypeEditorProvider());
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeBuilder testNode = builder.child("testNode");
testNode.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, Type.NAME);
testNode.setProperty(JCR_MIXINTYPES, ImmutableList.of("mix:title"), Type.NAMES);
testNode.setProperty("jcr:title", "title");
NodeState before = builder.getNodeState();
testNode.setProperty("jcr:title", true);
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 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();
}
}
Aggregations