use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testUpdateFieldAwareSuccessAll.
@Test
public void testUpdateFieldAwareSuccessAll() {
SampleBean sampleBean = new SampleBean();
sampleBean.id = 1L;
PersistentResource resource = newResource(sampleBean, SampleBean.class, true);
RequestScope requestScope = resource.getRequestScope();
assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, new ChangeSpec(null, null, null, null), UpdatePermission.class, "allVisible"));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testReadCheckExpressionForNewlyCreatedObject.
@Test
public void testReadCheckExpressionForNewlyCreatedObject() {
@Entity
@Include(rootLevel = false)
@ReadPermission(expression = "FailOp")
class Model {
}
PersistentResource resource = newResource(new Model(), Model.class, true);
RequestScope requestScope = resource.getRequestScope();
requestScope.getDictionary().bindEntity(Model.class);
assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource));
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testSuccessfulCommitChecks.
@Test
public void testSuccessfulCommitChecks() throws Exception {
@Entity
@Include(rootLevel = false)
@UpdatePermission(expression = "sampleOperation")
class Model implements SampleOperationModel {
}
PersistentResource resource = newResource(new Model(), Model.class, true);
RequestScope requestScope = resource.getRequestScope();
// Because the object is newly created, the check is DEFERRED.
assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource, ALL_FIELDS));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testSpecificFieldCommitCheckFailByOveriddenField.
@Test
public void testSpecificFieldCommitCheckFailByOveriddenField() {
PersistentResource resource = newResource(CheckedEntity.class, true);
RequestScope requestScope = resource.getRequestScope();
assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, new ChangeSpec(null, null, null, null), UpdatePermission.class, "hello"));
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class EntityProjectionMakerTest method testNestedEntityNoQueryParams.
@Test
public void testNestedEntityNoQueryParams() {
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
String path = "/author/1/books/3/publisher/1";
RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
EntityProjection expected = EntityProjection.builder().type(Author.class).relationship("books", EntityProjection.builder().type(Book.class).relationship("publisher", EntityProjection.builder().type(Publisher.class).attribute(Attribute.builder().name("name").type(String.class).build()).attribute(Attribute.builder().name("updateHookInvoked").type(boolean.class).build()).relationship("books", EntityProjection.builder().type(Book.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build()).build()).build();
EntityProjection actual = maker.parsePath(path);
projectionEquals(expected, actual);
}
Aggregations