use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testUserCheckCache.
@Test
public void testUserCheckCache() {
PersistentResource resource = newResource(UserCheckCacheRecord.class, false);
RequestScope requestScope = resource.getRequestScope();
// This should cache for updates, reads, etc.
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource, ALL_FIELDS));
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource, ALL_FIELDS));
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource, ALL_FIELDS));
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource, ALL_FIELDS));
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testUpdateFieldAwareFailureAny.
@Test
public void testUpdateFieldAwareFailureAny() {
PersistentResource resource = newResource(SampleBean.class, true);
RequestScope requestScope = resource.getRequestScope();
requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, null, UpdatePermission.class, "mayFailInCommit");
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testPassAnySpecificFieldAwareFailOperationSuccessCommit.
@Test
public void testPassAnySpecificFieldAwareFailOperationSuccessCommit() {
@Entity
@Include(rootLevel = false)
@UpdatePermission(expression = "Prefab.Role.None AND passingOp")
class Model {
@Id
public Long id;
@UpdatePermission(expression = "Prefab.Role.None OR passingOp")
public String field = "some data";
}
PersistentResource resource = newResource(new Model(), Model.class, true);
RequestScope requestScope = resource.getRequestScope();
assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, null, UpdatePermission.class, "field"));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testNoCache.
@Test
public void testNoCache() {
PersistentResource resource = newResource(AnnotationOnlyRecord.class, false);
RequestScope requestScope = resource.getRequestScope();
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource, ALL_FIELDS));
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource, ALL_FIELDS));
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testUserCheckOnFieldSuccess.
@Test
public void testUserCheckOnFieldSuccess() {
OpenBean openBean = new OpenBean();
openBean.id = 1L;
PersistentResource resource = newResource(OpenBean.class, false);
RequestScope requestScope = resource.getRequestScope();
ExpressionResult result = requestScope.getPermissionExecutor().checkUserPermissions(ClassType.of(OpenBean.class), ReadPermission.class, "open");
assertEquals(ExpressionResult.PASS, result);
}
Aggregations