diff --git a/auth_test.py b/auth_test.py index 3d1aa10c0c..2caad32673 100644 --- a/auth_test.py +++ b/auth_test.py @@ -34,6 +34,31 @@ def role_creator_permissions(self, creator, role): permissions = ('ALTER', 'DROP', 'DESCRIBE') return [(creator, role, perm) for perm in permissions] + def cluster_version_has_unmask_permission(self): + return self.cluster.version() >= LooseVersion('4.2') + + def data_resource_creator_permissions(self, creator, resource): + """ + Assemble a list of all permissions needed to create data on a given resource + @param creator User who needs permissions + @param resource The resource to grant permissions on + @return A list of permissions for creator on resource + """ + permissions = [] + for perm in 'SELECT', 'MODIFY', 'ALTER', 'DROP', 'AUTHORIZE': + permissions.append((creator, resource, perm)) + + if self.cluster_version_has_unmask_permission(): + permissions.append((creator, resource, 'UNMASK')) + + if resource.startswith("' % keyspace, perm)) + return permissions + class TestAuth(AbstractTestAuth): @@ -947,9 +972,9 @@ def test_list_permissions(self): # CASSANDRA-7216 automatically grants permissions on a role to its creator if self.cluster.cassandra_version() >= '2.2.0': - all_permissions.extend(data_resource_creator_permissions('cassandra', '')) - all_permissions.extend(data_resource_creator_permissions('cassandra', '')) - all_permissions.extend(data_resource_creator_permissions('cassandra', '
')) + all_permissions.extend(self.data_resource_creator_permissions('cassandra', '')) + all_permissions.extend(self.data_resource_creator_permissions('cassandra', '
')) + all_permissions.extend(self.data_resource_creator_permissions('cassandra', '
')) all_permissions.extend(self.role_creator_permissions('cassandra', '')) all_permissions.extend(self.role_creator_permissions('cassandra', '')) @@ -962,7 +987,7 @@ def test_list_permissions(self): expected_permissions = [('cathy', '
', 'MODIFY'), ('bob', '
', 'DROP')] if self.cluster.cassandra_version() >= '2.2.0': - expected_permissions.extend(data_resource_creator_permissions('cassandra', '
')) + expected_permissions.extend(self.data_resource_creator_permissions('cassandra', '
')) self.assertPermissionsListed(expected_permissions, cassandra, "LIST ALL PERMISSIONS ON ks.cf NORECURSIVE") expected_permissions = [('cathy', '
', 'SELECT')] @@ -1136,25 +1161,6 @@ def assertPermissionsListed(self, expected, session, query): assert sorted(expected) == sorted(perms) -def data_resource_creator_permissions(creator, resource): - """ - Assemble a list of all permissions needed to create data on a given resource - @param creator User who needs permissions - @param resource The resource to grant permissions on - @return A list of permissions for creator on resource - """ - permissions = [] - for perm in 'SELECT', 'MODIFY', 'ALTER', 'DROP', 'AUTHORIZE': - permissions.append((creator, resource, perm)) - if resource.startswith("' % keyspace, perm)) - return permissions - - @since('2.2') class TestAuthRoles(AbstractTestAuth): @@ -1385,8 +1391,8 @@ def test_creator_of_db_resource_granted_all_permissions(self): mike_permissions = [('mike', '', 'CREATE'), ('mike', '', 'CREATE')] mike_permissions.extend(self.role_creator_permissions('mike', '')) - mike_permissions.extend(data_resource_creator_permissions('mike', '')) - mike_permissions.extend(data_resource_creator_permissions('mike', '
')) + mike_permissions.extend(self.data_resource_creator_permissions('mike', '')) + mike_permissions.extend(self.data_resource_creator_permissions('mike', '
')) mike_permissions.extend(function_resource_creator_permissions('mike', '')) mike_permissions.extend(function_resource_creator_permissions('mike', '')) @@ -1671,23 +1677,29 @@ def test_filter_granted_permissions_by_resource_type(self): # GRANT ALL ON KEYSPACE grants Permission.ALL_DATA self.superuser.execute("GRANT ALL ON KEYSPACE ks TO mike") - self.assert_permissions_listed([("mike", "", "CREATE"), - ("mike", "", "ALTER"), - ("mike", "", "DROP"), - ("mike", "", "SELECT"), - ("mike", "", "MODIFY"), - ("mike", "", "AUTHORIZE")], + permissions = [("mike", "", "CREATE"), + ("mike", "", "ALTER"), + ("mike", "", "DROP"), + ("mike", "", "SELECT"), + ("mike", "", "MODIFY"), + ("mike", "", "AUTHORIZE")] + if self.cluster_version_has_unmask_permission(): + permissions.append(("mike", "", "UNMASK")) + self.assert_permissions_listed(permissions, self.superuser, "LIST ALL PERMISSIONS OF mike") self.superuser.execute("REVOKE ALL ON KEYSPACE ks FROM mike") # GRANT ALL ON TABLE does not include CREATE (because the table must already be created before the GRANT) self.superuser.execute("GRANT ALL ON ks.cf TO MIKE") - self.assert_permissions_listed([("mike", "
", "ALTER"), - ("mike", "
", "DROP"), - ("mike", "
", "SELECT"), - ("mike", "
", "MODIFY"), - ("mike", "
", "AUTHORIZE")], + permissions = [("mike", "
", "ALTER"), + ("mike", "
", "DROP"), + ("mike", "
", "SELECT"), + ("mike", "
", "MODIFY"), + ("mike", "
", "AUTHORIZE")] + if self.cluster_version_has_unmask_permission(): + permissions.append(("mike", "
", "UNMASK")) + self.assert_permissions_listed(permissions, self.superuser, "LIST ALL PERMISSIONS OF mike") self.superuser.execute("REVOKE ALL ON ks.cf FROM mike") @@ -1788,8 +1800,8 @@ def test_list_permissions(self): ("role1", "
", "SELECT"), ("role2", "
", "ALTER"), ("role2", "", "ALTER")] - expected_permissions.extend(data_resource_creator_permissions('cassandra', '')) - expected_permissions.extend(data_resource_creator_permissions('cassandra', '
')) + expected_permissions.extend(self.data_resource_creator_permissions('cassandra', '')) + expected_permissions.extend(self.data_resource_creator_permissions('cassandra', '
')) expected_permissions.extend(self.role_creator_permissions('cassandra', '')) expected_permissions.extend(self.role_creator_permissions('cassandra', '')) expected_permissions.extend(self.role_creator_permissions('cassandra', '')) diff --git a/cqlsh_tests/test_cqlsh.py b/cqlsh_tests/test_cqlsh.py index 1f5c37674d..1ea5a48487 100644 --- a/cqlsh_tests/test_cqlsh.py +++ b/cqlsh_tests/test_cqlsh.py @@ -783,7 +783,20 @@ def test_list_queries(self): (2 rows) """) - if self.cluster.version() >= LooseVersion('2.2'): + if self.cluster.version() >= LooseVersion('4.2'): + self.verify_output("LIST ALL PERMISSIONS OF user1", node1, """ + role | username | resource | permission +-------+----------+---------------+------------ + user1 | user1 |
| ALTER + user1 | user1 |
| DROP + user1 | user1 |
| SELECT + user1 | user1 |
| MODIFY + user1 | user1 |
| AUTHORIZE + user1 | user1 |
| UNMASK + +(6 rows) +""") + elif self.cluster.version() >= LooseVersion('2.2'): self.verify_output("LIST ALL PERMISSIONS OF user1", node1, """ role | username | resource | permission -------+----------+---------------+------------