Skip to content

Commit

Permalink
Make HiveQueryRunner default user have admin role
Browse files Browse the repository at this point in the history
Extracted-From: prestodb/presto#10904
  • Loading branch information
sopel39 committed Jan 29, 2019
1 parent fb230fb commit bbc0233
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.prestosql.plugin.tpch.TpchPlugin;
import io.prestosql.spi.security.Identity;
import io.prestosql.spi.security.PrincipalType;
import io.prestosql.spi.security.SelectedRole;
import io.prestosql.testing.QueryRunner;
import io.prestosql.tests.DistributedQueryRunner;
import org.intellij.lang.annotations.Language;
Expand All @@ -37,6 +38,7 @@

import static io.airlift.units.Duration.nanosSince;
import static io.prestosql.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME;
import static io.prestosql.spi.security.SelectedRole.Type.ROLE;
import static io.prestosql.testing.TestingSession.testSessionBuilder;
import static io.prestosql.tests.QueryAssertions.copyTpchTables;
import static java.lang.String.format;
Expand Down Expand Up @@ -81,7 +83,7 @@ public static DistributedQueryRunner createQueryRunner(Iterable<TpchTable<?>> ta
{
assertEquals(DateTimeZone.getDefault(), TIME_ZONE, "Timezone not configured correctly. Add -Duser.timezone=America/Bahia_Banderas to your JVM arguments");

DistributedQueryRunner queryRunner = new DistributedQueryRunner(createSession(), 4, extraProperties);
DistributedQueryRunner queryRunner = new DistributedQueryRunner(createSession(Optional.of(new SelectedRole(ROLE, Optional.of("admin")))), 4, extraProperties);

try {
queryRunner.installPlugin(new TpchPlugin());
Expand Down Expand Up @@ -116,8 +118,8 @@ public static DistributedQueryRunner createQueryRunner(Iterable<TpchTable<?>> ta
queryRunner.createCatalog(HIVE_CATALOG, HIVE_CATALOG, hiveProperties);
queryRunner.createCatalog(HIVE_BUCKETED_CATALOG, HIVE_CATALOG, hiveBucketedProperties);

copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, createSession(), tables);
copyTpchTablesBucketed(queryRunner, "tpch", TINY_SCHEMA_NAME, createBucketedSession(), tables);
copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, createSession(Optional.empty()), tables);
copyTpchTablesBucketed(queryRunner, "tpch", TINY_SCHEMA_NAME, createBucketedSession(Optional.empty()), tables);

return queryRunner;
}
Expand All @@ -136,19 +138,28 @@ private static Database createDatabaseMetastoreObject(String name)
.build();
}

public static Session createSession()
public static Session createSession(Optional<SelectedRole> role)
{
return testSessionBuilder()
.setIdentity(new Identity("hive", Optional.empty()))
.setIdentity(new Identity(
"hive",
Optional.empty(),
role.map(selectedRole -> ImmutableMap.of("hive", selectedRole))
.orElse(ImmutableMap.of())))
.setCatalog(HIVE_CATALOG)
.setSchema(TPCH_SCHEMA)
.build();
}

public static Session createBucketedSession()
public static Session createBucketedSession(Optional<SelectedRole> role)
{
return testSessionBuilder()
.setIdentity(new Identity("hive", Optional.empty()))
.setIdentity(new Identity(
"hive",
Optional.empty(),
role.map(selectedRole -> ImmutableMap.of("hive", selectedRole))
.orElse(ImmutableMap.of())))
.setCatalog(HIVE_CATALOG)
.setCatalog(HIVE_BUCKETED_CATALOG)
.setSchema(TPCH_BUCKETED_SCHEMA)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.prestosql.spi.connector.ConnectorSession;
import io.prestosql.spi.connector.Constraint;
import io.prestosql.spi.security.Identity;
import io.prestosql.spi.security.SelectedRole;
import io.prestosql.spi.type.Type;
import io.prestosql.spi.type.TypeSignature;
import io.prestosql.sql.planner.Plan;
Expand Down Expand Up @@ -92,6 +93,7 @@
import static io.prestosql.plugin.hive.HiveTestUtils.TYPE_MANAGER;
import static io.prestosql.plugin.hive.HiveUtil.columnExtraInfo;
import static io.prestosql.spi.predicate.Marker.Bound.EXACTLY;
import static io.prestosql.spi.security.SelectedRole.Type.ROLE;
import static io.prestosql.spi.type.BigintType.BIGINT;
import static io.prestosql.spi.type.CharType.createCharType;
import static io.prestosql.spi.type.DecimalType.createDecimalType;
Expand Down Expand Up @@ -132,7 +134,7 @@ public class TestHiveIntegrationSmokeTest
@SuppressWarnings("unused")
public TestHiveIntegrationSmokeTest()
{
this(() -> createQueryRunner(ORDERS, CUSTOMER), createBucketedSession(), HIVE_CATALOG, new HiveTypeTranslator());
this(() -> createQueryRunner(ORDERS, CUSTOMER), createBucketedSession(Optional.of(new SelectedRole(ROLE, Optional.of("admin")))), HIVE_CATALOG, new HiveTypeTranslator());
}

protected TestHiveIntegrationSmokeTest(QueryRunnerSupplier queryRunnerSupplier, Session bucketedSession, String catalog, TypeTranslator typeTranslator)
Expand Down

0 comments on commit bbc0233

Please sign in to comment.