Search in sources :

Example 46 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class Log4jLoggerTest method shouldReturnResultWithoutModification.

@Test
public void shouldReturnResultWithoutModification() {
    // Given
    final Log4jLogger hook = new Log4jLogger();
    final Object result = mock(Object.class);
    final OperationChain opChain = new OperationChain.Builder().first(new GenerateObjects<>()).build();
    final User user = new User.Builder().opAuths("NoScore").build();
    // When
    final Object returnedResult = hook.postExecute(result, opChain, user);
    // Then
    assertSame(result, returnedResult);
}
Also used : GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Example 47 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAllowedAuth.

@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAllowedAuth() throws OperationException {
    // Given
    final OperationAuthoriser opAuthoriser = new OperationAuthoriser(StreamUtil.opAuths(getClass()));
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds()).then(new GetElements()).build();
    final User user = new User.Builder().opAuths("unknownAuth").build();
    // When/Then
    try {
        opAuthoriser.preExecute(opChain, user);
        fail("Exception expected");
    } catch (final UnauthorisedException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.Test)

Example 48 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAnyOpAuths.

@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAnyOpAuths() throws OperationException {
    // Given
    final OperationAuthoriser opAuthoriser = new OperationAuthoriser(StreamUtil.opAuths(getClass()));
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds()).then(new GetElements()).build();
    final User user = new User();
    // When/Then
    try {
        opAuthoriser.preExecute(opChain, user);
        fail("Exception expected");
    } catch (final UnauthorisedException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.Test)

Example 49 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForAllOperations.

@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForAllOperations() {
    // Given
    final OperationAuthoriser opAuthoriser = new OperationAuthoriser(StreamUtil.opAuths(getClass()));
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds()).then(// Requires AdminUser
    new GenerateObjects()).build();
    final User user = new User.Builder().opAuths("WriteUser", "ReadUser", "User").build();
    // When/Then
    try {
        opAuthoriser.preExecute(opChain, user);
        fail("Exception expected");
    } catch (final UnauthorisedException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.Test)

Example 50 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class OperationChainLimiterTest method shouldAcceptOperationChainWhenUserHasMaxAuthScoreGreaterThanChainScore.

@Test
public void shouldAcceptOperationChainWhenUserHasMaxAuthScoreGreaterThanChainScore() {
    // Given
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds()).then(new GetAdjacentEntitySeeds()).then(new GetAdjacentEntitySeeds()).then(new GenerateObjects()).build();
    final User user = new User.Builder().opAuths("SuperUser", "User").build();
    // When
    OPERATION_CHAIN_LIMITER.preExecute(opChain, user);
// Then - no exceptions
}
Also used : GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Aggregations

OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)65 Test (org.junit.Test)52 User (uk.gov.gchq.gaffer.user.User)38 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 Store (uk.gov.gchq.gaffer.store.Store)13 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)12 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)11 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)11 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)9 GetAdjacentEntitySeeds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds)8 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 Element (uk.gov.gchq.gaffer.data.element.Element)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)7 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)7 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 InOrder (org.mockito.InOrder)6 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)6 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)6