Search in sources :

Example 1 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.

the class AddNamedOperationHandlerTest method shouldAddNamedOperationFieldsToNamedOperationDetailCorrectly.

@Test
public void shouldAddNamedOperationFieldsToNamedOperationDetailCorrectly() throws OperationException, CacheOperationFailedException {
    final List<String> readAuths = asList("readAuth1", "readAuth2");
    final List<String> writeAuths = asList("writeAuth1", "writeAuth2");
    OperationChain opChain = new OperationChain.Builder().first(new AddElements()).build();
    addNamedOperation.setOperationChain(opChain);
    addNamedOperation.setScore(2);
    addNamedOperation.setOperationName("testOp");
    addNamedOperation.setLabels(asList("test label"));
    addNamedOperation.setReadAccessRoles(readAuths);
    addNamedOperation.setWriteAccessRoles(writeAuths);
    handler.doOperation(addNamedOperation, context, store);
    final NamedOperationDetail result = mockCache.getNamedOperation("testOp", new User(), EMPTY_ADMIN_AUTH);
    assert cacheContains("testOp");
    assertTrue(result.getScore() == 2);
    assertEquals(asList("test label"), result.getLabels());
    final AccessPredicate expectedReadAccessPredicate = new AccessPredicate(context.getUser(), readAuths);
    assertEquals(expectedReadAccessPredicate, result.getOrDefaultReadAccessPredicate());
    final AccessPredicate expectedWriteAccessPredicate = new AccessPredicate(context.getUser(), writeAuths);
    assertEquals(expectedWriteAccessPredicate, result.getOrDefaultWriteAccessPredicate());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Example 2 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.

the class NamedOperationDetailTest method shouldDefaultWriteAccessPredicateIfNoneSpecified.

@Test
public void shouldDefaultWriteAccessPredicateIfNoneSpecified() {
    final List<String> writers = asList("writerAuth1", "writerAuth2");
    final NamedOperationDetail namedOperationDetail = getBaseNamedOperationDetailBuilder().writers(writers).build();
    assertEquals(new AccessPredicate(new User.Builder().userId("creatorUserId").build(), writers), namedOperationDetail.getOrDefaultWriteAccessPredicate());
}
Also used : AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Example 3 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.

the class NamedOperationDetailTest method shouldDefaultReadAccessPredicateIfNoneSpecified.

@Test
public void shouldDefaultReadAccessPredicateIfNoneSpecified() {
    final List<String> readers = asList("readerAuth1", "readerAuth2");
    final NamedOperationDetail namedOperationDetail = getBaseNamedOperationDetailBuilder().readers(readers).build();
    assertEquals(new AccessPredicate(new User.Builder().userId("creatorUserId").build(), readers), namedOperationDetail.getOrDefaultReadAccessPredicate());
}
Also used : AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Example 4 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.

the class NamedOperationDetailTest method shouldDeserialiseCustomAccessPredicate.

@Test
public void shouldDeserialiseCustomAccessPredicate() throws SerialisationException {
    // Given
    String json = "{" + "   \"operationName\": \"operationName\"," + "   \"creatorId\": \"creatorUserId\"," + "   \"operationChain\": {\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetAllElements\"}]}," + "   \"readAccessPredicate\": {" + "       \"class\": \"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\"," + "       \"userPredicate\": {" + "           \"class\": \"uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate\"" + "       }" + "   }" + "}";
    // When
    NamedOperationDetail deserialised = JSONSerialiser.deserialise(json, NamedOperationDetail.class);
    // Then
    AccessPredicate expected = new AccessPredicate(new CustomUserPredicate());
    assertEquals(expected, deserialised.getReadAccessPredicate());
}
Also used : CustomUserPredicate(uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Example 5 with AccessPredicate

use of uk.gov.gchq.gaffer.access.predicate.AccessPredicate in project Gaffer by gchq.

the class NamedOperationDetailTest method shouldBeJavaSerialisable.

@Test
public void shouldBeJavaSerialisable() throws IOException, ClassNotFoundException {
    // Given
    final AccessPredicate customAccessPredicate = new AccessPredicate(new CustomUserPredicate());
    final NamedOperationDetail namedOperationDetail = getBaseNamedOperationDetailBuilder().readAccessPredicate(customAccessPredicate).build();
    // When
    NamedOperationDetail deserialised = (NamedOperationDetail) deserialise(serialise(namedOperationDetail));
    // Then
    assertEquals(namedOperationDetail, deserialised);
}
Also used : CustomUserPredicate(uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)22 AccessPredicate (uk.gov.gchq.gaffer.access.predicate.AccessPredicate)22 CustomUserPredicate (uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate)7 UnrestrictedAccessPredicate (uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate)4 NamedViewWriteAccessPredicate (uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate)4 CallMethod (uk.gov.gchq.koryphe.impl.function.CallMethod)4 AdaptedPredicate (uk.gov.gchq.koryphe.predicate.AdaptedPredicate)4 NoAccessPredicate (uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate)3 FederatedGraphReadAccessPredicate (uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphReadAccessPredicate)3 FederatedGraphWriteAccessPredicate (uk.gov.gchq.gaffer.federatedstore.access.predicate.FederatedGraphWriteAccessPredicate)3 Context (uk.gov.gchq.gaffer.store.Context)3 Schema (uk.gov.gchq.gaffer.store.schema.Schema)3 User (uk.gov.gchq.gaffer.user.User)3 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)3 AccessPredicateTest (uk.gov.gchq.gaffer.access.predicate.AccessPredicateTest)2 NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)2 NamedOperationDetail (uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)2 CollectionContains (uk.gov.gchq.koryphe.impl.predicate.CollectionContains)2