use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestRevokeOnSchema method initClass.
@BeforeClass
public void initClass() throws Exception {
queryRunner = DistributedQueryRunner.builder(userWithAllPrivileges).build();
Grants<String> schemaGrants = new MutableGrants<>();
schemaGrants.grant(new TrinoPrincipal(USER, admin.getUser()), "default", EnumSet.allOf(Privilege.class), true);
schemaGrants.grant(new TrinoPrincipal(USER, userWithAllPrivileges.getUser()), "default", EnumSet.allOf(Privilege.class), true);
schemaGrants.grant(new TrinoPrincipal(USER, userWithSelect.getUser()), "default", ImmutableSet.of(Privilege.SELECT), true);
MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListSchemaNames(session -> ImmutableList.of("information_schema", "default")).withSchemaGrants(schemaGrants).build();
queryRunner.installPlugin(new MockConnectorPlugin(connectorFactory));
queryRunner.createCatalog("local", "mock");
assertions = new QueryAssertions(queryRunner);
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestingSystemSecurityMetadata method getRoleGrantsRecursively.
private Set<RoleGrant> getRoleGrantsRecursively(TrinoPrincipal principal) {
Queue<RoleGrant> pending = new ArrayDeque<>(getRoleGrants(principal));
Set<RoleGrant> seen = new HashSet<>();
while (!pending.isEmpty()) {
RoleGrant current = pending.remove();
if (!seen.add(current)) {
continue;
}
pending.addAll(getRoleGrants(new TrinoPrincipal(ROLE, current.getRoleName())));
}
return ImmutableSet.copyOf(seen);
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestMemoryMetadata method testCreatedViewShouldBeListedAsTable.
@Test
public void testCreatedViewShouldBeListedAsTable() {
String schemaName = "test";
SchemaTableName viewName = new SchemaTableName(schemaName, "test_view");
metadata.createSchema(SESSION, schemaName, ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
metadata.createView(SESSION, viewName, testingViewDefinition("aaa"), true);
assertThat(metadata.listTables(SESSION, Optional.of(schemaName))).contains(viewName);
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestMemoryMetadata method testCreateViewWithReplace.
@Test
public void testCreateViewWithReplace() {
SchemaTableName test = new SchemaTableName("test", "test_view");
metadata.createSchema(SESSION, "test", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
metadata.createView(SESSION, test, testingViewDefinition("aaa"), true);
metadata.createView(SESSION, test, testingViewDefinition("bbb"), true);
assertThat(metadata.getView(SESSION, test)).map(ConnectorViewDefinition::getOriginalSql).hasValue("bbb");
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestMemoryMetadata method testViews.
@Test
public void testViews() {
SchemaTableName test1 = new SchemaTableName("test", "test_view1");
SchemaTableName test2 = new SchemaTableName("test", "test_view2");
SchemaTableName test3 = new SchemaTableName("test", "test_view3");
// create schema
metadata.createSchema(SESSION, "test", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
// create views
metadata.createView(SESSION, test1, testingViewDefinition("test1"), false);
metadata.createView(SESSION, test2, testingViewDefinition("test2"), false);
// verify listing
List<SchemaTableName> list = metadata.listViews(SESSION, Optional.of("test"));
assertEqualsIgnoreOrder(list, ImmutableList.of(test1, test2));
// verify getting data
Map<SchemaTableName, ConnectorViewDefinition> views = metadata.getViews(SESSION, Optional.of("test"));
assertEquals(views.keySet(), ImmutableSet.of(test1, test2));
assertEquals(views.get(test1).getOriginalSql(), "test1");
assertEquals(views.get(test2).getOriginalSql(), "test2");
// all schemas
assertThat(metadata.getViews(SESSION, Optional.empty())).containsOnlyKeys(test1, test2);
// exact match on one schema and table
assertThat(metadata.getView(SESSION, new SchemaTableName("test", "test_view1"))).map(ConnectorViewDefinition::getOriginalSql).contains("test1");
// non-existent table
assertThat(metadata.getView(SESSION, new SchemaTableName("test", "nonexistenttable"))).isEmpty();
// non-existent schema
assertThat(metadata.getViews(SESSION, Optional.of("nonexistentschema"))).isEmpty();
// drop first view
metadata.dropView(SESSION, test1);
assertThat(metadata.getViews(SESSION, Optional.of("test"))).containsOnlyKeys(test2);
// rename second view
metadata.renameView(SESSION, test2, test3);
assertThat(metadata.getViews(SESSION, Optional.of("test"))).containsOnlyKeys(test3);
// drop second view
metadata.dropView(SESSION, test3);
assertThat(metadata.getViews(SESSION, Optional.of("test"))).isEmpty();
// verify listing everything
assertThat(metadata.getViews(SESSION, Optional.empty())).isEmpty();
}
Aggregations