use of java.sql.SQLException in project hive by apache.
the class cbo_rp_TestJdbcDriver2 method testShowRoleGrant.
@Test
public void testShowRoleGrant() throws SQLException {
Statement stmt = con.createStatement();
// drop role. ignore error.
try {
stmt.execute("drop role role1");
} catch (Exception ex) {
LOG.warn("Ignoring error during drop role: " + ex);
}
stmt.execute("create role role1");
stmt.execute("grant role role1 to user hive_test_user");
stmt.execute("show role grant user hive_test_user");
ResultSet res = stmt.getResultSet();
assertTrue(res.next());
assertEquals("public", res.getString(1));
assertTrue(res.next());
assertEquals("role1", res.getString(1));
res.close();
}
use of java.sql.SQLException in project hive by apache.
the class cbo_rp_TestJdbcDriver2 method testExecuteQueryException.
// executeQuery should always throw a SQLException,
// when it executes a non-ResultSet query (like create)
@Test
public void testExecuteQueryException() throws Exception {
Statement stmt = con.createStatement();
try {
stmt.executeQuery("create table test_t2 (under_col int, value string)");
fail("Expecting SQLException");
} catch (SQLException e) {
System.out.println("Caught an expected SQLException: " + e.getMessage());
} finally {
stmt.close();
}
}
use of java.sql.SQLException in project hive by apache.
the class TestJdbcMetadataApiAuth method testMetaApiDisAllowed.
/**
* Call the HS2 metadata api's with authorizer disallowing those calls
* @throws Exception
*/
@Test
public void testMetaApiDisAllowed() throws Exception {
TestAuthValidator.allowActions = false;
Connection hs2Conn = getConnection("user1");
DatabaseMetaData dbmetadata = hs2Conn.getMetaData();
try {
dbmetadata.getCatalogs();
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getSchemas();
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getTypeInfo();
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getTables(null, "default", "t%", null);
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getTableTypes();
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getColumns(null, "default", "nosuchtable", null);
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getFunctions(null, null, "trim");
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
}
use of java.sql.SQLException in project hive by apache.
the class TestJdbcWithSQLAuthorization method testConfigWhiteList.
@Test
public void testConfigWhiteList() throws Exception {
// create tables as user1
Connection hs2Conn = getConnection("user1");
Statement stmt = hs2Conn.createStatement();
try {
stmt.execute("set hive.metastore.uris=x");
fail("exception expected");
} catch (SQLException e) {
String msg = "Cannot modify hive.metastore.uris at runtime. " + "It is not in list of params that are allowed to be modified at runtime";
assertTrue(e.getMessage().contains(msg));
}
stmt.execute("set hive.exec.reducers.bytes.per.reducer=10000");
//no exception should be thrown
stmt.close();
hs2Conn.close();
}
use of java.sql.SQLException in project hive by apache.
the class TestJdbcWithMiniHS2 method testUdfBlackListOverride.
/** Test UDF blacklist overrides whitelist
* @throws Exception
*/
@Test
public void testUdfBlackListOverride() throws Exception {
stopMiniHS2();
// setup whitelist
HiveConf testConf = new HiveConf();
Set<String> funcNames = FunctionRegistry.getFunctionNames();
String funcNameStr = "";
for (String funcName : funcNames) {
funcNameStr += "," + funcName;
}
// remove ',' at begining
funcNameStr = funcNameStr.substring(1);
testConf.setVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_WHITELIST, funcNameStr);
testConf.setVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_BLACKLIST, "reflect");
startMiniHS2(testConf);
Connection conn = getConnection(miniHS2.getJdbcURL(testDbName), System.getProperty("user.name"), "bar");
Statement stmt = conn.createStatement();
// verify that udf in black list fails even though it's included in whitelist
try {
stmt.executeQuery("SELECT reflect('java.lang.String', 'valueOf', 1) ");
fail("reflect() udf invocation should fail");
} catch (SQLException e) {
// expected
}
conn.close();
// Restore original state
restoreMiniHS2AndConnections();
}
Aggregations