Search in sources :

Example 1 with TestAccessMode

use of org.neo4j.internal.kernel.api.security.TestAccessMode in project neo4j by neo4j.

the class NodeTransactionStateTestBase method shouldCountNewNodesFromTxStateRestrictedUser.

@Test
void shouldCountNewNodesFromTxStateRestrictedUser() throws Exception {
    // Given
    createNode();
    createNode();
    SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
    try (KernelTransaction tx = beginTransaction(loginContext)) {
        // when
        tx.dataWrite().nodeCreate();
        long countTxState = tx.dataRead().countsForNode(-1);
        long countNoTxState = tx.dataRead().countsForNodeWithoutTxState(-1);
        // then
        assertEquals(3, countTxState);
        assertEquals(2, countNoTxState);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) TestAccessMode(org.neo4j.internal.kernel.api.security.TestAccessMode) Test(org.junit.jupiter.api.Test)

Example 2 with TestAccessMode

use of org.neo4j.internal.kernel.api.security.TestAccessMode in project neo4j by neo4j.

the class NodeTransactionStateTestBase method shouldCountNewLabelsFromTxStateRestrictedUser.

@Test
void shouldCountNewLabelsFromTxStateRestrictedUser() throws Exception {
    // Given
    Node node1 = createNode("label");
    Node node2 = createNode();
    SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
    try (KernelTransaction tx = beginTransaction(loginContext)) {
        // when
        tx.dataWrite().nodeAddLabel(node2.node, node1.labels[0]);
        long countTxState = tx.dataRead().countsForNode(node1.labels[0]);
        long countNoTxState = tx.dataRead().countsForNodeWithoutTxState(node1.labels[0]);
        // then
        assertEquals(2, countTxState);
        assertEquals(1, countNoTxState);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) TestAccessMode(org.neo4j.internal.kernel.api.security.TestAccessMode) Test(org.junit.jupiter.api.Test)

Example 3 with TestAccessMode

use of org.neo4j.internal.kernel.api.security.TestAccessMode in project neo4j by neo4j.

the class RelationshipTransactionStateTestBase method shouldIncludeAddedRelationshipsByTypeAndDirection.

@Test
void shouldIncludeAddedRelationshipsByTypeAndDirection() throws Exception {
    int typeId1;
    int typeId2;
    long relationship1;
    long relationship2;
    long sourceNode;
    long targetNode;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        typeId1 = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        typeId2 = tx.tokenWrite().relationshipTypeGetOrCreateForName("R2");
        sourceNode = write.nodeCreate();
        relationship1 = write.relationshipCreate(sourceNode, typeId1, write.nodeCreate());
        relationship2 = write.relationshipCreate(sourceNode, typeId2, write.nodeCreate());
        targetNode = write.nodeCreate();
        tx.commit();
    }
    SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
    try (KernelTransaction tx = beginTransaction(loginContext);
        NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
        RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
        Write write = tx.dataWrite();
        // OUTGOING :R
        long r1 = write.relationshipCreate(sourceNode, typeId1, targetNode);
        // INCOMING :R
        long r2 = write.relationshipCreate(targetNode, typeId1, sourceNode);
        // LOOP :R
        long r3 = write.relationshipCreate(sourceNode, typeId1, sourceNode);
        // OUTGOING :R2
        long r4 = write.relationshipCreate(sourceNode, typeId2, targetNode);
        // INCOMING :R2
        long r5 = write.relationshipCreate(targetNode, typeId2, sourceNode);
        // LOOP :R2
        long r6 = write.relationshipCreate(sourceNode, typeId2, sourceNode);
        org.neo4j.internal.kernel.api.Read read = tx.dataRead();
        read.singleNode(sourceNode, node);
        assertTrue(node.next());
        assertRelationships(node, traversal, ALL_RELATIONSHIPS, relationship1, relationship2, r1, r2, r3, r4, r5, r6);
        assertRelationships(node, traversal, selection(OUTGOING), relationship1, relationship2, r1, r3, r4, r6);
        assertRelationships(node, traversal, selection(typeId1, BOTH), relationship1, r1, r2, r3);
        assertRelationships(node, traversal, selection(typeId1, OUTGOING), relationship1, r1, r3);
        assertRelationships(node, traversal, selection(typeId1, INCOMING), r2, r3);
        assertRelationships(node, traversal, selection(typeId2, BOTH), relationship2, r4, r5, r6);
        assertRelationships(node, traversal, selection(typeId2, OUTGOING), relationship2, r4, r6);
        assertRelationships(node, traversal, selection(typeId2, INCOMING), r5, r6);
        assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, BOTH), relationship1, relationship2, r1, r2, r3, r4, r5, r6);
        assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, OUTGOING), relationship1, relationship2, r1, r3, r4, r6);
        assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, INCOMING), r2, r3, r5, r6);
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Read(org.neo4j.internal.kernel.api.Read) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) TestAccessMode(org.neo4j.internal.kernel.api.security.TestAccessMode) Test(org.junit.jupiter.api.Test)

Example 4 with TestAccessMode

use of org.neo4j.internal.kernel.api.security.TestAccessMode in project neo4j by neo4j.

the class RelationshipTransactionStateTestBase method shouldCountNewRelationshipsRestrictedUser.

@Test
void shouldCountNewRelationshipsRestrictedUser() throws Exception {
    int relationship;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        relationship = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        write.relationshipCreate(write.nodeCreate(), relationship, write.nodeCreate());
        tx.commit();
    }
    SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
    try (KernelTransaction tx = beginTransaction(loginContext)) {
        Write write = tx.dataWrite();
        write.relationshipCreate(write.nodeCreate(), relationship, write.nodeCreate());
        long countsTxState = tx.dataRead().countsForRelationship(-1, relationship, -1);
        long countsNoTxState = tx.dataRead().countsForRelationshipWithoutTxState(-1, relationship, -1);
        assertEquals(2, countsTxState);
        assertEquals(1, countsNoTxState);
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) TestAccessMode(org.neo4j.internal.kernel.api.security.TestAccessMode) Test(org.junit.jupiter.api.Test)

Example 5 with TestAccessMode

use of org.neo4j.internal.kernel.api.security.TestAccessMode in project neo4j by neo4j.

the class RelationshipTransactionStateTestBase method shouldNotCountRemovedRelationshipsRestrictedUser.

@Test
void shouldNotCountRemovedRelationshipsRestrictedUser() throws Exception {
    int relationshipId;
    long relationship;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        relationshipId = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        relationship = write.relationshipCreate(write.nodeCreate(), relationshipId, write.nodeCreate());
        tx.commit();
    }
    SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
    try (KernelTransaction tx = beginTransaction(loginContext)) {
        Write write = tx.dataWrite();
        write.relationshipDelete(relationship);
        long countsTxState = tx.dataRead().countsForRelationship(-1, relationshipId, -1);
        long countsNoTxState = tx.dataRead().countsForRelationshipWithoutTxState(-1, relationshipId, -1);
        assertEquals(0, countsTxState);
        assertEquals(1, countsNoTxState);
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) TestAccessMode(org.neo4j.internal.kernel.api.security.TestAccessMode) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)7 SecurityContext (org.neo4j.internal.kernel.api.security.SecurityContext)7 TestAccessMode (org.neo4j.internal.kernel.api.security.TestAccessMode)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 Write (org.neo4j.internal.kernel.api.Write)3 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)1 Read (org.neo4j.internal.kernel.api.Read)1 RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)1