Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,11 @@ public void testSchemaAuthorizationForRole()
// make sure role-grants only work on existing roles
assertQueryFails(admin, "ALTER SCHEMA test_schema_authorization_role SET AUTHORIZATION ROLE nonexisting_role", ".*?Role 'nonexisting_role' does not exist in catalog 'hive'");

assertUpdate(admin, "CREATE ROLE authorized_users IN hive");
assertUpdate(admin, "GRANT authorized_users TO user IN hive");
String role = "authorized_users" + randomNameSuffix();
assertUpdate(admin, "CREATE ROLE " + role + " IN hive");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't have to be random.
it's enough that it's not reused between this test and testCreateSchemaWithAuthorizationForRole

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but random suffix is safer to reduce copy-paste mistake.

assertUpdate(admin, "GRANT " + role + " TO user IN hive");

assertUpdate(admin, "ALTER SCHEMA test_schema_authorization_role SET AUTHORIZATION ROLE authorized_users");
assertUpdate(admin, "ALTER SCHEMA test_schema_authorization_role SET AUTHORIZATION ROLE " + role);

Session user = testSessionBuilder()
.setCatalog(getSession().getCatalog())
Expand Down Expand Up @@ -825,7 +826,7 @@ public void testSchemaAuthorizationForRole()
assertUpdate(user, "DROP TABLE test_schema_authorization_role.test");
assertUpdate(user, "DROP SCHEMA test_schema_authorization_role");

assertUpdate(admin, "DROP ROLE authorized_users IN hive");
assertUpdate(admin, "DROP ROLE " + role + " IN hive");
}

@Test
Expand Down Expand Up @@ -908,11 +909,12 @@ public void testCreateSchemaWithAuthorizationForRole()
.build())
.build();

assertUpdate(admin, "CREATE ROLE authorized_users IN hive");
assertUpdate(admin, "GRANT authorized_users TO user IN hive");
String role = "authorized_users" + randomNameSuffix();
assertUpdate(admin, "CREATE ROLE " + role + " IN hive");
assertUpdate(admin, "GRANT " + role + " TO user IN hive");

assertQueryFails(admin, "CREATE SCHEMA test_createschema_authorization_role AUTHORIZATION ROLE nonexisting_role", ".*?Role 'nonexisting_role' does not exist in catalog 'hive'");
assertUpdate(admin, "CREATE SCHEMA test_createschema_authorization_role AUTHORIZATION ROLE authorized_users");
assertUpdate(admin, "CREATE SCHEMA test_createschema_authorization_role AUTHORIZATION ROLE " + role);
assertUpdate(user, "CREATE TABLE test_createschema_authorization_role.test (x bigint)");

// "user" without the role enabled cannot create new tables
Expand All @@ -926,7 +928,7 @@ public void testCreateSchemaWithAuthorizationForRole()
assertUpdate(user, "DROP TABLE test_createschema_authorization_role.test");
assertUpdate(user, "DROP SCHEMA test_createschema_authorization_role");

assertUpdate(admin, "DROP ROLE authorized_users IN hive");
assertUpdate(admin, "DROP ROLE " + role + " IN hive");
}

@Test
Expand Down