use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testFailAllFieldAwareSuccessOperationFailCommit.
@Test
public void testFailAllFieldAwareSuccessOperationFailCommit() {
@Entity
@Include(rootLevel = false)
@UpdatePermission(expression = "Prefab.Role.None")
class Model {
@Id
public Long id;
@UpdatePermission(expression = "Prefab.Role.All AND FailOp")
public String field = "some data";
}
PersistentResource resource = newResource(new Model(), Model.class, true);
RequestScope requestScope = resource.getRequestScope();
assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource));
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testReadFieldAwareSuccessAny.
@Test
public void testReadFieldAwareSuccessAny() {
SampleBean sampleBean = new SampleBean();
sampleBean.id = 1L;
PersistentResource resource = newResource(sampleBean, SampleBean.class, false);
RequestScope requestScope = resource.getRequestScope();
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, new ChangeSpec(null, null, null, null), ReadPermission.class, "mayFailInCommit"));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testCache.
@Test
public void testCache() {
PersistentResource resource = newResource(AnnotationOnlyRecord.class, false);
RequestScope requestScope = resource.getRequestScope();
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource));
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource));
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testUserCheckOnFieldFailure.
@Test
public void testUserCheckOnFieldFailure() {
PersistentResource resource = newResource(SampleBean.class, false);
RequestScope requestScope = resource.getRequestScope();
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().checkUserPermissions(ClassType.of(SampleBean.class), ReadPermission.class, "cannotSeeMe"));
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testPassAnyFieldAwareFailOperationSuccessCommit.
@Test
public void testPassAnyFieldAwareFailOperationSuccessCommit() {
@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().checkPermission(UpdatePermission.class, resource));
requestScope.getPermissionExecutor().executeCommitChecks();
}
Aggregations