Run impersonation tests for custom ORC/RCFILE writers
@@ -15,16 +15,18 @@ package com.facebook.presto.tests;
import com.google.inject.Inject;
import com.google.inject.name.Named;
+import io.prestodb.tempto.BeforeTestWithContext;
import io.prestodb.tempto.ProductTest;
import io.prestodb.tempto.Requires;
import io.prestodb.tempto.fulfillment.table.hive.tpch.ImmutableTpchTablesRequirements.ImmutableNationTable;
import io.prestodb.tempto.hadoop.hdfs.HdfsClient;
+import io.prestodb.tempto.query.QueryExecutor;
import org.testng.annotations.Test;
import static com.facebook.presto.tests.TestGroups.HDFS_IMPERSONATION;
import static com.facebook.presto.tests.TestGroups.HDFS_NO_IMPERSONATION;
import static com.facebook.presto.tests.TestGroups.PROFILE_SPECIFIC_TESTS;
-import static io.prestodb.tempto.query.QueryExecutor.query;
+import static com.facebook.presto.tests.utils.QueryExecutors.connectToPresto;
import static java.lang.String.format;
import static org.testng.Assert.assertEquals;
@@ -32,12 +34,14 @@ import static org.testng.Assert.assertEquals;
public class ImpersonationTests
extends ProductTest
{
+ private QueryExecutor aliceExecutor;
+
@Inject
private HdfsClient hdfsClient;
@Inject
- @Named("databases.presto.jdbc_user")
- private String prestoJdbcUser;
+ @Named("databases.alice@presto.jdbc_user")
+ private String aliceJdbcUser;
// The value for configuredHdfsUser is profile dependent
// For non-Kerberos environments this variable will be equal to -DHADOOP_USER_NAME as set in jvm.config
@@ -50,18 +54,25 @@ public class ImpersonationTests
@Named("databases.hive.warehouse_directory_path")
private String warehouseDirectoryPath;
+ @BeforeTestWithContext
+ public void setup()
+ {
+ aliceExecutor = connectToPresto("alice@presto");
+ QueryExecutor.query(format("GRANT SELECT ON NATION TO %s", aliceJdbcUser));
+ }
+
@Test(groups = {HDFS_NO_IMPERSONATION, PROFILE_SPECIFIC_TESTS})
public void testHdfsImpersonationDisabled()
{
String tableName = "check_hdfs_impersonation_disabled";
- checkTableOwner(tableName, configuredHdfsUser);
+ checkTableOwner(tableName, configuredHdfsUser, aliceExecutor);
}
@Test(groups = {HDFS_IMPERSONATION, PROFILE_SPECIFIC_TESTS})
public void testHdfsImpersonationEnabled()
{
String tableName = "check_hdfs_impersonation_enabled";
- checkTableOwner(tableName, prestoJdbcUser);
+ checkTableOwner(tableName, aliceJdbcUser, aliceExecutor);
}
private String getTableLocation(String tableName)
@@ -69,13 +80,13 @@ public class ImpersonationTests
return warehouseDirectoryPath + '/' + tableName;
}
- private void checkTableOwner(String tableName, String expectedOwner)
+ private void checkTableOwner(String tableName, String expectedOwner, QueryExecutor executor)
{
- query(format("DROP TABLE IF EXISTS %s", tableName));
- query(format("CREATE TABLE %s AS SELECT * FROM NATION", tableName));
+ executor.executeQuery(format("DROP TABLE IF EXISTS %s", tableName));
+ executor.executeQuery(format("CREATE TABLE %s AS SELECT * FROM NATION", tableName));
String tableLocation = getTableLocation(tableName);
String owner = hdfsClient.getOwner(tableLocation);
assertEquals(owner, expectedOwner);
- query(format("DROP TABLE IF EXISTS %s", tableName));
+ executor.executeQuery(format("DROP TABLE IF EXISTS %s", tableName));
}
}
