use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class NonEntityQueryTest method testInMemoryAndSeveralConstraints.
@Test
public void testInMemoryAndSeveralConstraints() throws Exception {
ConfigStorageService configStorageService = AppBeans.get(ConfigStorageService.class);
configStorageService.setDbProperty("cuba.disableLoadValuesIfConstraints", "false");
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");
List<KeyValueEntity> list = dataManager.secure().loadValues(context);
assertEquals(1, list.size());
context = ValueLoadContext.create();
context.setQueryString("select s.name, sn.viewXml from sys$Server s, sys$EntitySnapshot sn");
context.addProperty("name");
context.addProperty("viewXml");
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 DataManagerCommitConstraintTest method testDeleteConstraintNotPassed.
@Test
public void testDeleteConstraintNotPassed() throws LoginException {
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
DataManager dataManager = AppBeans.get(DataManager.NAME);
UserSession userSession = lw.login("constraintuserupdate", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
dataManager = dataManager.secure();
User user = dataManager.load(new LoadContext<>(User.class).setId(testUserDelete1.getId()).setView(View.LOCAL));
dataManager.remove(user);
fail();
} catch (RowLevelSecurityException e) {
User user = dataManager.load(new LoadContext<>(User.class).setId(testUserDelete1.getId()).setView(View.LOCAL));
assertNotNull(user);
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class DataManagerCommitConstraintTest method testCreateConstraintNotPassed.
@Test
public void testCreateConstraintNotPassed() throws LoginException {
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
DataManager dataManager = AppBeans.get(DataManager.NAME);
UserSession userSession = lw.login("constraintusercreate", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
dataManager = dataManager.secure();
User user = dataManager.load(new LoadContext<>(User.class).setId(testUserUpdate1.getId()).setView(View.LOCAL));
Role loadedRole = dataManager.load(new LoadContext<>(Role.class).setId(role.getId()).setView(View.MINIMAL));
UserRole userRole = new UserRole();
userRole.setUser(user);
userRole.setRole(loadedRole);
dataManager.commit(userRole);
fail();
} catch (RowLevelSecurityException e) {
// Do nothing
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class DataManagerSecurityTest method test.
@Test
public void test() throws Exception {
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
UserSession userSession = lw.login(USER_NAME, passwordEncryption.getPlainHash(USER_PASSW), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
DataManager dm = AppBeans.get(DataManager.NAME);
LoadContext<Server> loadContext = LoadContext.create(Server.class).setQuery(new LoadContext.Query("select s from sys$Server s"));
List<Server> list = dm.loadList(loadContext);
assertFalse("Permission took effect when calling DataManager inside middleware", list.isEmpty());
DataService ds = AppBeans.get(DataService.NAME);
loadContext = LoadContext.create(Server.class).setQuery(new LoadContext.Query("select s from sys$Server s"));
list = ds.loadList(loadContext);
assertTrue("Permission did not take effect when calling DataService", list.isEmpty());
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.
the class InMemoryConstraintTest method testConstraintsOnEnd.
@Test
public void testConstraintsOnEnd() throws LoginException {
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
UserSession userSession = lw.login("constraintUser2", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
DataManager dataManager = AppBeans.get(DataManager.NAME);
dataManager = dataManager.secure();
LoadContext loadContext = new LoadContext(User.class).setView(View.LOCAL);
loadContext.setQuery(new LoadContext.Query("select u from sec$User u where (u.login like 'user%' or u.login like 'constraintUser%') order by u.login desc"));
loadContext.getQuery().setMaxResults(30);
loadContext.getQuery().setFirstResult(0);
List resultList = dataManager.loadList(loadContext);
assertEquals(9, resultList.size());
assertEquals(9, dataManager.getCount(loadContext));
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
Aggregations