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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations