test: update rba test cases 2 (#44954)

Signed-off-by: nico <cheng.yuan@zilliz.com>
This commit is contained in:
nico 2025-10-20 16:32:03 +08:00 committed by GitHub
parent ac82bad0b3
commit a4935d2eaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 94 additions and 7 deletions

View File

@ -358,9 +358,10 @@ class TestMilvusClientDatabaseInvalid(TestMilvusClientV2Base):
client = self._client()
error = {ct.err_code: 800, ct.err_msg: f"database not found[database={db_name}]"}
self.use_database(client, db_name,
check_task=CheckTasks.err_res, check_items=error)
check_task=CheckTasks.err_res, check_items=error)
self.using_database(client, db_name,
check_task=CheckTasks.err_res, check_items=error)
check_task=CheckTasks.err_res, check_items=error)
class TestMilvusClientDatabaseValid(TestMilvusClientV2Base):
""" Test case of database interface """
@ -579,4 +580,4 @@ class TestMilvusClientDatabaseValid(TestMilvusClientV2Base):
self.drop_collection(client, collection_name)
self.drop_database(client, db_name)
self.use_database(client, "default")
self.drop_collection(client, collection_name_default_db)
self.drop_collection(client, collection_name_default_db)

View File

@ -132,11 +132,13 @@ class TestMilvusClientRbacBase(TestMilvusClientV2Base):
self.create_user(client, user_name=user_name, password=password)
new_password = cf.gen_str_by_length()
self.update_password(client, user_name=user_name, old_password=password, new_password=new_password)
self.close(client)
# check
uri = f"http://{host}:{port}"
client, _ = self.init_milvus_client(uri=uri, user=user_name, password=new_password)
res = self.list_databases(client)[0]
assert res == []
self.close(client)
self.init_milvus_client(uri=uri, user=user_name, password=password,
check_task=CheckTasks.check_auth_failure)
@ -662,6 +664,82 @@ class TestMilvusClientRbacInvalid(TestMilvusClientV2Base):
# cleanup
self.drop_role(client, role_name=role_name)
def test_milvus_client_add_privilege_into_not_exist_privilege_group(self, host, port):
"""
target: test milvus client api add privilege into not exist privilege group
method: add privilege into not exist privilege group
expected: raise exception
"""
client = self._client()
role_name = cf.gen_unique_str(role_pre)
self.create_role(client, role_name=role_name)
privilege_group_name = "privilege_group_not_exist"
error_msg = f"there is no privilege group name [{privilege_group_name}] defined in system"
self.add_privileges_to_group(client, privilege_group=privilege_group_name, privileges=["Insert"],
check_task=CheckTasks.err_res,
check_items={ct.err_code: 1100, ct.err_msg: error_msg})
# cleanup
self.drop_role(client, role_name=role_name)
@pytest.mark.parametrize("name", [1, 1.0, "n%$#@!", "test-role", "ff ff", "invalid_privilege"])
def test_milvus_client_add_privileges_to_group_with_privilege_invalid(self, name, host, port):
"""
target: test milvus client api add privilege group with invalid privilege type
method: add privilege group with invalid privilege type
expected: raise exception
"""
client = self._client()
role_name = cf.gen_unique_str(role_pre)
self.create_role(client, role_name=role_name)
error_msg = f"`privileges` value {name} is illegal"
self.add_privileges_to_group(client, privilege_group="privilege_group_1", privileges=name,
check_task=CheckTasks.err_res,
check_items={ct.err_code: 1, ct.err_msg: error_msg})
# cleanup
self.drop_role(client, role_name=role_name)
@pytest.mark.parametrize("name", [1, 1.0, "n%$#@!", "test-role", "ff ff"])
def test_milvus_client_remove_privileges_to_group_with_privilege_group_name_invalid(self, name, host, port):
"""
target: test milvus client api remove privilege group with invalid name
method: remove privilege group with invalid name
expected: raise exception
"""
client = self._client()
role_name = cf.gen_unique_str(role_pre)
self.create_role(client, role_name=role_name)
error_msg = f"{name}"
self.remove_privileges_from_group(client, privilege_group=name, privileges=["Insert"],
check_task=CheckTasks.err_res,
check_items={ct.err_code: 1, ct.err_msg: error_msg})
# cleanup
self.drop_role(client, role_name=role_name)
@pytest.mark.parametrize("name", [1, 1.0, "n%$#@!", "test-role", "ff ff", "invalid_privilege"])
def test_milvus_client_remove_privileges_to_group_with_privilege_invalid(self, name, host, port):
"""
target: test milvus client api remove privilege group with invalid privilege type
method: remove privilege group with invalid privilege type
expected: raise exception
"""
client = self._client()
role_name = cf.gen_unique_str(role_pre)
self.create_role(client, role_name=role_name)
error_msg = f"`privileges` value {name} is illegal"
self.remove_privileges_from_group(client, privilege_group="privilege_group_1", privileges=name,
check_task=CheckTasks.err_res,
check_items={ct.err_code: 1, ct.err_msg: error_msg})
# cleanup
self.drop_role(client, role_name=role_name)
@pytest.mark.tags(CaseLabel.RBAC)
class TestMilvusClientRbacAdvance(TestMilvusClientV2Base):
@ -1382,3 +1460,5 @@ class TestMilvusClientRbacAdvance(TestMilvusClientV2Base):

View File

@ -11,7 +11,7 @@ from utils.util_log import test_log as log
prefix = "db"
@pytest.mark.tags(CaseLabel.RBAC)
@pytest.mark.skip("removed to test_milvus_client_database.py")
class TestDatabaseParams(TestcaseBase):
""" Test case of database """
@ -220,7 +220,7 @@ class TestDatabaseParams(TestcaseBase):
check_items=error)
@pytest.mark.tags(CaseLabel.RBAC)
@pytest.mark.skip("removed to test_milvus_client_database.py")
class TestDatabaseOperation(TestcaseBase):
def setup_method(self, method):
@ -624,7 +624,7 @@ class TestDatabaseOperation(TestcaseBase):
assert self.utility_wrap.list_collections()[0] == []
@pytest.mark.tags(CaseLabel.RBAC)
@pytest.mark.skip("removed to test_milvus_client_database.py")
class TestDatabaseOtherApi(TestcaseBase):
""" test other interface that has db_name params"""

View File

@ -5326,6 +5326,7 @@ class TestUtilityNegativeRbacPrivilegeGroup(TestcaseBase):
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.RBAC)
@pytest.mark.skip("removed")
@pytest.mark.parametrize("name", ["n%$#@!", "test-role", "ff ff"])
def test_add_privileges_to_group_with_privilege_group_name_invalid_value(self, name, host, port):
"""
@ -5340,6 +5341,7 @@ class TestUtilityNegativeRbacPrivilegeGroup(TestcaseBase):
self.utility_wrap.add_privileges_to_group(privilege_group=name, privileges=["Insert"], check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.RBAC)
@pytest.mark.skip("removed")
def test_add_privilege_into_not_exist_privilege_group(self, host, port):
"""
target: add privilege into not exist privilege group
@ -5375,6 +5377,7 @@ class TestUtilityNegativeRbacPrivilegeGroup(TestcaseBase):
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.RBAC)
@pytest.mark.skip("removed")
@pytest.mark.parametrize("name", [1, 1.0, "n%$#@!", "test-role", "ff ff"])
def test_add_privileges_to_group_with_privilege_invalid_type(self, name, host, port):
"""
@ -5391,6 +5394,7 @@ class TestUtilityNegativeRbacPrivilegeGroup(TestcaseBase):
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.RBAC)
@pytest.mark.skip("removed")
def test_add_privileges_to_group_with_privilege_invalid_value(self, host, port):
"""
target: add privilege group with invalid name
@ -5409,6 +5413,7 @@ class TestUtilityNegativeRbacPrivilegeGroup(TestcaseBase):
self.utility_wrap.add_privileges_to_group(privilege_group="privilege_group_1", privileges=[privilege_name], check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.RBAC)
@pytest.mark.skip("removed")
@pytest.mark.parametrize("name", [1, 1.0])
def test_remove_privileges_to_group_with_privilege_group_name_invalid_type(self, name, host, port):
"""
@ -5425,6 +5430,7 @@ class TestUtilityNegativeRbacPrivilegeGroup(TestcaseBase):
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.RBAC)
@pytest.mark.skip("removed")
@pytest.mark.parametrize("name", ["n%$#@!", "test-role", "ff ff"])
def test_remove_privileges_to_group_with_privilege_group_name_invalid_value(self, name, host, port):
"""
@ -5487,7 +5493,7 @@ class TestUtilityNegativeRbacPrivilegeGroup(TestcaseBase):
error = {"err_code": 1,
"err_msg": f"`privileges` value {name} is illegal"}
self.utility_wrap.remove_privileges_from_group(privilege_group="privilege_group_1", privileges=name,
check_task=CheckTasks.err_res, check_items=error)
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.RBAC)
def test_remove_privileges_to_group_with_privilege_invalid_value(self, host, port):