use of org.apache.hive.hcatalog.ExitException in project hive by apache.
the class TestPermsGrp method testCustomPerms.
public void testCustomPerms() throws Exception {
String dbName = Warehouse.DEFAULT_DATABASE_NAME;
String tblName = "simptbl";
String typeName = "Person";
try {
// Lets first test for default permissions, this is the case when user specified nothing.
Table tbl = getTable(dbName, tblName, typeName);
msc.createTable(tbl);
Database db = Hive.get(hcatConf).getDatabase(dbName);
Path dfsPath = clientWH.getDefaultTablePath(db, tblName);
cleanupTbl(dbName, tblName, typeName);
// Next user did specify perms.
try {
callHCatCli(new String[] { "-e", "create table simptbl (name string) stored as RCFILE", "-p", "rwx-wx---" });
fail();
} catch (Exception e) {
assertTrue(e instanceof ExitException);
assertEquals(((ExitException) e).getStatus(), 0);
}
dfsPath = clientWH.getDefaultTablePath(db, tblName);
assertEquals(FsPermission.valueOf("drwx-wx---"), dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath).getPermission());
cleanupTbl(dbName, tblName, typeName);
// User specified perms in invalid format.
hcatConf.set(HCatConstants.HCAT_PERMS, "rwx");
// make sure create table fails.
try {
callHCatCli(new String[] { "-e", "create table simptbl (name string) stored as RCFILE", "-p", "rwx" });
fail();
} catch (Exception me) {
assertTrue(me instanceof ExitException);
}
// No physical dir gets created.
dfsPath = clientWH.getDefaultTablePath(db, tblName);
try {
dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath);
fail();
} catch (Exception fnfe) {
assertTrue(fnfe instanceof FileNotFoundException);
}
// And no metadata gets created.
try {
msc.getTable(Warehouse.DEFAULT_DATABASE_NAME, tblName);
fail();
} catch (Exception e) {
assertTrue(e instanceof NoSuchObjectException);
assertEquals("default.simptbl table not found", e.getMessage());
}
// test for invalid group name
hcatConf.set(HCatConstants.HCAT_PERMS, "drw-rw-rw-");
hcatConf.set(HCatConstants.HCAT_GROUP, "THIS_CANNOT_BE_A_VALID_GRP_NAME_EVER");
try {
// create table must fail.
callHCatCli(new String[] { "-e", "create table simptbl (name string) stored as RCFILE", "-p", "rw-rw-rw-", "-g", "THIS_CANNOT_BE_A_VALID_GRP_NAME_EVER" });
fail();
} catch (Exception me) {
assertTrue(me instanceof SecurityException);
}
try {
// no metadata should get created.
msc.getTable(dbName, tblName);
fail();
} catch (Exception e) {
assertTrue(e instanceof NoSuchObjectException);
assertEquals("default.simptbl table not found", e.getMessage());
}
try {
// neither dir should get created.
dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath);
fail();
} catch (Exception e) {
assertTrue(e instanceof FileNotFoundException);
}
} catch (Exception e) {
LOG.error("testCustomPerms failed.", e);
throw e;
}
}
Aggregations