use of org.apache.hadoop.hive.ql.ddl.DDLWork in project hive by apache.
the class TestHiveAuthorizationTaskFactory method testGrantUserTable.
/**
* GRANT ... ON TABLE ... TO USER ...
*/
@Test
public void testGrantUserTable() throws Exception {
DDLWork work = analyze("GRANT " + SELECT + " ON TABLE " + TABLE + " TO USER " + USER);
GrantDesc grantDesc = (GrantDesc) work.getDDLDesc();
Assert.assertNotNull("Grant should not be null", grantDesc);
for (PrincipalDesc principal : ListSizeMatcher.inList(grantDesc.getPrincipals()).ofSize(1)) {
Assert.assertEquals(PrincipalType.USER, principal.getType());
Assert.assertEquals(USER, principal.getName());
}
for (PrivilegeDesc privilege : ListSizeMatcher.inList(grantDesc.getPrivileges()).ofSize(1)) {
Assert.assertEquals(Privilege.SELECT, privilege.getPrivilege());
}
Assert.assertTrue("Expected table", grantDesc.getPrivilegeSubject().getTable());
Assert.assertEquals(TABLE_QNAME, grantDesc.getPrivilegeSubject().getObject());
}
use of org.apache.hadoop.hive.ql.ddl.DDLWork in project hive by apache.
the class TestHiveAuthorizationTaskFactory method testRevokeRoleTable.
/**
* REVOKE ... ON TABLE ... FROM ROLE ...
*/
@Test
public void testRevokeRoleTable() throws Exception {
DDLWork work = analyze("REVOKE " + SELECT + " ON TABLE " + TABLE + " FROM ROLE " + ROLE);
RevokeDesc grantDesc = (RevokeDesc) work.getDDLDesc();
Assert.assertNotNull("Revoke should not be null", grantDesc);
for (PrincipalDesc principal : ListSizeMatcher.inList(grantDesc.getPrincipals()).ofSize(1)) {
Assert.assertEquals(PrincipalType.ROLE, principal.getType());
Assert.assertEquals(ROLE, principal.getName());
}
for (PrivilegeDesc privilege : ListSizeMatcher.inList(grantDesc.getPrivileges()).ofSize(1)) {
Assert.assertEquals(Privilege.SELECT, privilege.getPrivilege());
}
Assert.assertTrue("Expected table", grantDesc.getPrivilegeSubject().getTable());
Assert.assertEquals(TABLE_QNAME, grantDesc.getPrivilegeSubject().getObject());
}
use of org.apache.hadoop.hive.ql.ddl.DDLWork in project hive by apache.
the class TestHiveAuthorizationTaskFactory method testShowGrantUserOnTable.
/**
* SHOW GRANT USER ... ON TABLE ...
*/
@Test
public void testShowGrantUserOnTable() throws Exception {
DDLWork work = analyze("SHOW GRANT USER " + USER + " ON TABLE " + TABLE);
ShowGrantDesc grantDesc = (ShowGrantDesc) work.getDDLDesc();
Assert.assertNotNull("Show grant should not be null", grantDesc);
Assert.assertEquals(PrincipalType.USER, grantDesc.getPrincipalDesc().getType());
Assert.assertEquals(USER, grantDesc.getPrincipalDesc().getName());
Assert.assertTrue("Expected table", grantDesc.getHiveObj().getTable());
Assert.assertEquals(TABLE_QNAME, grantDesc.getHiveObj().getObject());
Assert.assertTrue("Expected table", grantDesc.getHiveObj().getTable());
}
use of org.apache.hadoop.hive.ql.ddl.DDLWork in project hive by apache.
the class TestHiveAuthorizationTaskFactory method testGrantRoleUser.
/**
* GRANT ROLE ... TO USER ...
*/
@Test
public void testGrantRoleUser() throws Exception {
DDLWork work = analyze("GRANT ROLE " + ROLE + " TO USER " + USER);
GrantRoleDesc grantDesc = (GrantRoleDesc) work.getDDLDesc();
Assert.assertNotNull("Grant should not be null", grantDesc);
Assert.assertFalse("With admin option is not specified", grantDesc.isGrantOption());
Assert.assertEquals(currentUser, grantDesc.getGrantor());
for (String role : ListSizeMatcher.inList(grantDesc.getRoles()).ofSize(1)) {
Assert.assertEquals(ROLE, role);
}
for (PrincipalDesc principal : ListSizeMatcher.inList(grantDesc.getPrincipals()).ofSize(1)) {
Assert.assertEquals(PrincipalType.USER, principal.getType());
Assert.assertEquals(USER, principal.getName());
}
}
use of org.apache.hadoop.hive.ql.ddl.DDLWork in project hive by apache.
the class TestHiveAuthorizationTaskFactory method testGrantRoleTable.
/**
* GRANT ... ON TABLE ... TO ROLE ...
*/
@Test
public void testGrantRoleTable() throws Exception {
DDLWork work = analyze("GRANT " + SELECT + " ON TABLE " + TABLE + " TO ROLE " + ROLE);
GrantDesc grantDesc = (GrantDesc) work.getDDLDesc();
Assert.assertNotNull("Grant should not be null", grantDesc);
for (PrincipalDesc principal : ListSizeMatcher.inList(grantDesc.getPrincipals()).ofSize(1)) {
Assert.assertEquals(PrincipalType.ROLE, principal.getType());
Assert.assertEquals(ROLE, principal.getName());
}
for (PrivilegeDesc privilege : ListSizeMatcher.inList(grantDesc.getPrivileges()).ofSize(1)) {
Assert.assertEquals(Privilege.SELECT, privilege.getPrivilege());
}
Assert.assertTrue("Expected table", grantDesc.getPrivilegeSubject().getTable());
Assert.assertEquals(TABLE_QNAME, grantDesc.getPrivilegeSubject().getObject());
}
Aggregations