Fix SET ROLE.

This commit is contained in:
Vitaly Baranov 2021-07-22 16:32:51 +03:00
parent 0f8b196682
commit d0412994a2
2 changed files with 30 additions and 2 deletions

View File

@ -80,7 +80,7 @@ std::vector<UUID> GrantedRoles::findGranted(const boost::container::flat_set<UUI
{
std::vector<UUID> res;
res.reserve(ids.size());
boost::range::set_difference(ids, roles, std::back_inserter(res));
boost::range::set_intersection(ids, roles, std::back_inserter(res));
return res;
}
@ -111,7 +111,7 @@ std::vector<UUID> GrantedRoles::findGrantedWithAdminOption(const boost::containe
{
std::vector<UUID> res;
res.reserve(ids.size());
boost::range::set_difference(ids, roles_with_admin_option, std::back_inserter(res));
boost::range::set_intersection(ids, roles_with_admin_option, std::back_inserter(res));
return res;
}

View File

@ -6,6 +6,13 @@ cluster = ClickHouseCluster(__file__)
instance = cluster.add_instance('instance')
session_id_counter = 0
def new_session_id():
global session_id_counter
session_id_counter += 1
return 'session #' + str(session_id_counter)
@pytest.fixture(scope="module", autouse=True)
def started_cluster():
try:
@ -138,6 +145,27 @@ def test_revoke_requires_admin_option():
assert instance.query("SHOW GRANTS FOR B") == ""
def test_set_role():
instance.query("CREATE USER A")
instance.query("CREATE ROLE R1, R2")
instance.query("GRANT R1, R2 TO A")
session_id = new_session_id()
assert instance.http_query('SHOW CURRENT ROLES', user='A', params={'session_id':session_id}) == TSV([["R1", 0, 1], ["R2", 0, 1]])
instance.http_query('SET ROLE R1', user='A', params={'session_id':session_id})
assert instance.http_query('SHOW CURRENT ROLES', user='A', params={'session_id':session_id}) == TSV([["R1", 0, 1]])
instance.http_query('SET ROLE R2', user='A', params={'session_id':session_id})
assert instance.http_query('SHOW CURRENT ROLES', user='A', params={'session_id':session_id}) == TSV([["R2", 0, 1]])
instance.http_query('SET ROLE NONE', user='A', params={'session_id':session_id})
assert instance.http_query('SHOW CURRENT ROLES', user='A', params={'session_id':session_id}) == TSV([])
instance.http_query('SET ROLE DEFAULT', user='A', params={'session_id':session_id})
assert instance.http_query('SHOW CURRENT ROLES', user='A', params={'session_id':session_id}) == TSV([["R1", 0, 1], ["R2", 0, 1]])
def test_introspection():
instance.query("CREATE USER A")
instance.query("CREATE USER B")