Search in sources :

Example 1 with CatalogManager

use of io.trino.metadata.CatalogManager in project trino by trinodb.

the class TestAccessControlManager method testAllowExecuteFunction.

@Test
public void testAllowExecuteFunction() {
    CatalogManager catalogManager = new CatalogManager();
    TransactionManager transactionManager = createTestTransactionManager(catalogManager);
    AccessControlManager accessControlManager = createAccessControlManager(transactionManager);
    accessControlManager.setSystemAccessControl("allow-all", ImmutableMap.of());
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanExecuteFunction(context(transactionId), "executed_function");
        accessControlManager.checkCanGrantExecuteFunctionPrivilege(context(transactionId), "executed_function", Identity.ofUser("bob"), true);
    });
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) CatalogManager(io.trino.metadata.CatalogManager) Test(org.testng.annotations.Test)

Example 2 with CatalogManager

use of io.trino.metadata.CatalogManager in project trino by trinodb.

the class TestStartTransactionTask method testStartTransactionIdleExpiration.

@Test
public void testStartTransactionIdleExpiration() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig().setIdleTimeout(// Fast idle timeout
    new Duration(1, TimeUnit.MICROSECONDS)).setIdleCheckInterval(new Duration(10, TimeUnit.MILLISECONDS)), scheduledExecutor, new CatalogManager(), executor);
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    getFutureValue(new StartTransactionTask(transactionManager).execute(new StartTransaction(ImmutableList.of()), stateMachine, emptyList(), WarningCollector.NOOP));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    long start = System.nanoTime();
    while (!transactionManager.getAllTransactionInfos().isEmpty()) {
        if (Duration.nanosSince(start).toMillis() > 10_000) {
            fail("Transaction did not expire in the allotted time");
        }
        TimeUnit.MILLISECONDS.sleep(10);
    }
}
Also used : TransactionManagerConfig(io.trino.transaction.TransactionManagerConfig) TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(io.trino.transaction.InMemoryTransactionManager) Duration(io.airlift.units.Duration) CatalogManager(io.trino.metadata.CatalogManager) StartTransaction(io.trino.sql.tree.StartTransaction) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 3 with CatalogManager

use of io.trino.metadata.CatalogManager in project trino by trinodb.

the class TestAccessControlManager method testDenyExecuteProcedureBySystem.

@Test
public void testDenyExecuteProcedureBySystem() {
    CatalogManager catalogManager = new CatalogManager();
    TransactionManager transactionManager = createTestTransactionManager(catalogManager);
    AccessControlManager accessControlManager = createAccessControlManager(transactionManager);
    TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("deny-all");
    accessControlManager.addSystemAccessControlFactory(accessControlFactory);
    accessControlManager.setSystemAccessControl("deny-all", ImmutableMap.of());
    assertDenyExecuteProcedure(transactionManager, accessControlManager, "Access Denied: Cannot execute procedure connector.schema.procedure");
}
Also used : TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) CatalogManager(io.trino.metadata.CatalogManager) Test(org.testng.annotations.Test)

Example 4 with CatalogManager

use of io.trino.metadata.CatalogManager in project trino by trinodb.

the class TestAccessControlManager method testDenyExecuteFunctionBySystemAccessControl.

@Test
public void testDenyExecuteFunctionBySystemAccessControl() {
    CatalogManager catalogManager = new CatalogManager();
    TransactionManager transactionManager = createTestTransactionManager(catalogManager);
    AccessControlManager accessControlManager = createAccessControlManager(transactionManager);
    TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("deny-all");
    accessControlManager.addSystemAccessControlFactory(accessControlFactory);
    accessControlManager.setSystemAccessControl("deny-all", ImmutableMap.of());
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        assertThatThrownBy(() -> accessControlManager.checkCanExecuteFunction(context(transactionId), "executed_function")).isInstanceOf(AccessDeniedException.class).hasMessage("Access Denied: Cannot execute function executed_function");
        assertThatThrownBy(() -> accessControlManager.checkCanGrantExecuteFunctionPrivilege(context(transactionId), "executed_function", Identity.ofUser("bob"), true)).isInstanceOf(AccessDeniedException.class).hasMessage("Access Denied: 'user_name' cannot grant 'executed_function' execution to user 'bob'");
    });
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) CatalogManager(io.trino.metadata.CatalogManager) Test(org.testng.annotations.Test)

Example 5 with CatalogManager

use of io.trino.metadata.CatalogManager in project trino by trinodb.

the class TestTransactionManager method testExpiration.

@Test
public void testExpiration() {
    try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
        TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig().setIdleTimeout(new Duration(1, TimeUnit.MILLISECONDS)).setIdleCheckInterval(new Duration(5, TimeUnit.MILLISECONDS)), executor.getExecutor(), new CatalogManager(), finishingExecutor);
        TransactionId transactionId = transactionManager.beginTransaction(false);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertFalse(transactionInfo.isAutoCommitContext());
        assertTrue(transactionInfo.getCatalogNames().isEmpty());
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        transactionManager.trySetInactive(transactionId);
        assertEventually(new Duration(10, SECONDS), () -> assertTrue(transactionManager.getAllTransactionInfos().isEmpty()));
    }
}
Also used : Duration(io.airlift.units.Duration) CatalogManager(io.trino.metadata.CatalogManager) Test(org.testng.annotations.Test)

Aggregations

CatalogManager (io.trino.metadata.CatalogManager)5 Test (org.testng.annotations.Test)5 InMemoryTransactionManager.createTestTransactionManager (io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager)4 TransactionManager (io.trino.transaction.TransactionManager)4 Duration (io.airlift.units.Duration)2 Session (io.trino.Session)1 AccessDeniedException (io.trino.spi.security.AccessDeniedException)1 StartTransaction (io.trino.sql.tree.StartTransaction)1 InMemoryTransactionManager (io.trino.transaction.InMemoryTransactionManager)1 TransactionManagerConfig (io.trino.transaction.TransactionManagerConfig)1