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);
});
}
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);
}
}
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");
}
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'");
});
}
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()));
}
}
Aggregations