use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class ExecutionsTest method testExceptionOnUserSession.
@Test
public void testExceptionOnUserSession() {
Executions executions = AppBeans.get(Executions.NAME);
executions.startExecution("key", "group");
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
try {
((TestUserSessionSource) userSessionSource).setExceptionOnGetUserSession(true);
} finally {
try {
executions.endExecution();
} catch (Exception e) {
// Do nothing
}
}
assertNull(ExecutionContextHolder.getCurrentContext());
((TestUserSessionSource) userSessionSource).setExceptionOnGetUserSession(false);
executions.startExecution("key", "group");
try {
executions.endExecution();
} catch (Exception e) {
// Do nothing
}
assertNull(ExecutionContextHolder.getCurrentContext());
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class NonEntityQueryTest method testConstraints.
@Test
public void testConstraints() throws Exception {
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
UserSession userSession = lw.login(USER_NAME_2, passwordEncryption.getPlainHash(USER_PASSWORD), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
ValueLoadContext context = ValueLoadContext.create();
context.setQueryString("select s.name from sys$Server s");
context.addProperty("name");
List<KeyValueEntity> list = dataManager.secure().loadValues(context);
assertEquals(0, list.size());
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class NonEntityQueryTest method testInMemoryAndSeveralConstraintsWithError.
@Test
public void testInMemoryAndSeveralConstraintsWithError() throws Exception {
ConfigStorageService configStorageService = AppBeans.get(ConfigStorageService.class);
configStorageService.setDbProperty("cuba.disableLoadValuesIfConstraints", "true");
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
UserSession userSession = lw.login(USER_NAME_2, passwordEncryption.getPlainHash(USER_PASSWORD), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
ValueLoadContext context = ValueLoadContext.create();
context.setQueryString("select s.viewXml from sys$EntitySnapshot s");
context.addProperty("viewXml");
try {
dataManager.secure().loadValues(context);
fail();
} catch (RowLevelSecurityException e) {
}
context = ValueLoadContext.create();
context.setQueryString("select s.name, sn.viewXml from sys$Server s, sys$EntitySnapshot sn");
context.addProperty("name");
context.addProperty("viewXml");
try {
dataManager.secure().loadValues(context);
fail();
} catch (RowLevelSecurityException e) {
}
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class NonEntityQueryTest method testIncorrectPathInWhere.
@Test
public void testIncorrectPathInWhere() throws Exception {
ConfigStorageService configStorageService = AppBeans.get(ConfigStorageService.class);
configStorageService.setDbProperty("cuba.disableLoadValuesIfConstraints", "true");
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
UserSession userSession = lw.login(USER_NAME_1, passwordEncryption.getPlainHash(USER_PASSWORD), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
ValueLoadContext context = ValueLoadContext.create();
context.setQueryString("select s.viewXml from sys$EntitySnapshot s where s.name1 = '1'");
context.addProperty("viewXml");
dataManager.secure().loadValues(context);
} catch (NullPointerException e) {
fail("Handling property path error");
} catch (IllegalStateException e) {
if (!"query path 's.name1' is unresolved".equals(e.getMessage())) {
throw e;
}
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class NonEntityQueryTest method testDeniedAttribute.
@Test
public void testDeniedAttribute() throws Exception {
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
UserSession userSession = lw.login(USER_NAME_1, passwordEncryption.getPlainHash(USER_PASSWORD), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
ValueLoadContext context = ValueLoadContext.create();
context.setQueryString("select s.name from sys$Server s");
context.addProperty("name");
List<KeyValueEntity> list = dataManager.secure().loadValues(context);
assertEquals(1, list.size());
KeyValueEntity e = list.get(0);
assertNull(e.getValue("name"));
context = ValueLoadContext.create();
context.setQueryString("select count(s.id) from sys$Server s where s.name = 'someServer'");
context.addProperty("count");
try {
dataManager.secure().loadValues(context);
fail();
} catch (AccessDeniedException e1) {
}
context = ValueLoadContext.create();
context.setQueryString("select s.name, count(s.id) from sys$Server s group by s.name");
context.addProperty("name");
context.addProperty("count");
try {
dataManager.secure().loadValues(context);
fail();
} catch (AccessDeniedException e1) {
}
context = ValueLoadContext.create();
context.setQueryString("select count(s.id) from sys$Server s join sec$User u on u.login = s.name");
context.addProperty("count");
try {
dataManager.secure().loadValues(context);
fail();
} catch (AccessDeniedException e1) {
}
context = ValueLoadContext.create();
context.setQueryString("select count(sn) from sys$Server s, sys$EntitySnapshot sn");
context.addProperty("count");
list = dataManager.secure().loadValues(context);
assertEquals(0, list.size());
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
Aggregations