use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class LifeCycleTest method testPreSecurityLifecycleHookException.
@Test
public void testPreSecurityLifecycleHookException() {
DataStoreTransaction tx = mock(DataStoreTransaction.class);
FieldTestModel testModel = mock(FieldTestModel.class);
doThrow(IllegalStateException.class).when(testModel).attributeCallback(eq(UPDATE), eq(PRESECURITY), any(ChangeSpec.class));
RequestScope scope = buildRequestScope(dictionary, tx);
PersistentResource resource = new PersistentResource(testModel, "1", scope);
assertThrows(IllegalStateException.class, () -> resource.updateAttribute("field", "New value"));
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testSuccessfulRunAtCommitCheck.
@Test
public void testSuccessfulRunAtCommitCheck() throws Exception {
@Entity
@Include(rootLevel = false)
@UpdatePermission(expression = "sampleCommit")
class Model implements SampleOperationModel {
}
PersistentResource resource = newResource(new Model(), Model.class, false);
RequestScope requestScope = resource.getRequestScope();
// Because the check is runAtCommit, 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 testReadFieldAwareSuccessAllAnyField.
@Test
public void testReadFieldAwareSuccessAllAnyField() {
SampleBean sampleBean = new SampleBean();
sampleBean.id = 1L;
PersistentResource resource = newResource(sampleBean, SampleBean.class, false);
RequestScope requestScope = resource.getRequestScope();
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource, ALL_FIELDS));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testSpecificFieldOveriddenOperationCheckSucceed.
@Test
public void testSpecificFieldOveriddenOperationCheckSucceed() {
PersistentResource resource = newResource(CheckedEntity.class, true);
RequestScope requestScope = resource.getRequestScope();
// Should succeed in operation check despite the commit check failure
assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, null, UpdatePermission.class, "hello"));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class PermissionExecutorTest method testReadFieldAwareSuccessAll.
@Test
public void testReadFieldAwareSuccessAll() {
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, "allVisible"));
requestScope.getPermissionExecutor().executeCommitChecks();
}
Aggregations