Search in sources :

Example 1 with MemoryNodeBuilder

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder in project jackrabbit-oak by apache.

the class PrivilegeValidatorTest method testUnknownAggregate.

@Test
public void testUnknownAggregate() {
    try {
        NodeState newDef = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGE).setProperty(REP_BITS, 8).setProperty(REP_AGGREGATES, ImmutableList.of("unknown", JCR_READ), Type.NAMES).getNodeState();
        PrivilegeValidator validator = new PrivilegeValidator(root, root);
        validator.childNodeAdded("test", newDef);
        fail("unknown aggregate must be detected.");
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(51, e.getCode());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with MemoryNodeBuilder

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder in project jackrabbit-oak by apache.

the class PrivilegeValidatorTest method testCircularAggregate2.

@Test
public void testCircularAggregate2() {
    try {
        createPrivilegeTree("test2", "test");
        NodeState newDef = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGE).setProperty(REP_BITS, 8).setProperty(REP_AGGREGATES, ImmutableList.of("test2", JCR_READ), Type.NAMES).getNodeState();
        PrivilegeValidator validator = new PrivilegeValidator(root, root);
        validator.childNodeAdded("test", newDef);
        fail("unknown aggregate must be detected.");
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(52, e.getCode());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with MemoryNodeBuilder

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder in project jackrabbit-oak by apache.

the class VersionableState method getOPV.

private int getOPV(NodeBuilder parent, NodeBuilder child, String childName) throws RepositoryException {
    // ignore hidden tree
    if (childName.startsWith(":")) {
        return IGNORE;
    }
    ImmutableTree parentTree = new ImmutableTree(parent.getNodeState());
    NodeState childState;
    if (NT_FROZENNODE.equals(child.getName(JCR_PRIMARYTYPE))) {
        // need to translate into a regular node to get proper OPV value
        NodeBuilder builder = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE);
        builder.setProperty(JCR_PRIMARYTYPE, child.getName(JCR_FROZENPRIMARYTYPE), Type.NAME);
        builder.setProperty(JCR_MIXINTYPES, child.getNames(JCR_MIXINTYPES), Type.NAMES);
        childState = builder.getNodeState();
    } else {
        childState = child.getNodeState();
    }
    ImmutableTree childTree = new ImmutableTree(parentTree, childName, childState);
    return ntMgr.getDefinition(parentTree, childTree).getOnParentVersion();
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 4 with MemoryNodeBuilder

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder in project jackrabbit-oak by apache.

the class PrivilegeValidatorTest method testCircularAggregate.

@Test
public void testCircularAggregate() {
    try {
        createPrivilegeTree("test");
        NodeState newDef = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGE).setProperty(REP_BITS, 8).setProperty(REP_AGGREGATES, ImmutableList.of("test", JCR_READ), Type.NAMES).getNodeState();
        PrivilegeValidator validator = new PrivilegeValidator(root, root);
        validator.childNodeAdded("test", newDef);
        fail("unknown aggregate must be detected.");
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(52, e.getCode());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 5 with MemoryNodeBuilder

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder in project jackrabbit-oak by apache.

the class PrivilegeValidatorTest method testPrivBitsMissing.

@Test
public void testPrivBitsMissing() {
    try {
        NodeState newDef = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGE).getNodeState();
        PrivilegeValidator validator = new PrivilegeValidator(root, root);
        validator.childNodeAdded("test", newDef);
        fail("missing priv bits must be detected.");
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(48, e.getCode());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)5 MemoryNodeBuilder (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder)5 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)5 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)4 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4 Test (org.junit.Test)4 ImmutableTree (org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1