Search in sources :

Example 1 with TestUserSessionSource

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());
}
Also used : Executions(com.haulmont.cuba.core.app.execution.Executions) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) Test(org.junit.Test)

Example 2 with TestUserSessionSource

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);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity) Test(org.junit.Test)

Example 3 with TestUserSessionSource

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);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) ConfigStorageService(com.haulmont.cuba.core.app.ConfigStorageService) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) Test(org.junit.Test)

Example 4 with TestUserSessionSource

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);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) ConfigStorageService(com.haulmont.cuba.core.app.ConfigStorageService) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) Test(org.junit.Test)

Example 5 with TestUserSessionSource

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);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity) Test(org.junit.Test)

Aggregations

TestUserSessionSource (com.haulmont.cuba.testsupport.TestUserSessionSource)24 LoginWorker (com.haulmont.cuba.security.app.LoginWorker)23 UserSession (com.haulmont.cuba.security.global.UserSession)23 Test (org.junit.Test)15 List (java.util.List)8 ArrayList (java.util.ArrayList)7 ConfigStorageService (com.haulmont.cuba.core.app.ConfigStorageService)4 KeyValueEntity (com.haulmont.cuba.core.entity.KeyValueEntity)3 Server (com.haulmont.cuba.core.entity.Server)2 DataService (com.haulmont.cuba.core.app.DataService)1 Executions (com.haulmont.cuba.core.app.execution.Executions)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 ConstraintData (com.haulmont.cuba.security.global.ConstraintData)1