Updated Security Client APIs (#450)

Signed-off-by: saimedhi <[email protected]>
This commit is contained in:
Sai Medhini Reddy Maryada
2023-07-26 18:38:49 -04:00
committed by GitHub
parent 87b402c16e
commit caeaa13250
10 changed files with 311 additions and 120 deletions
@@ -46,11 +46,21 @@ class TestSecurityPlugin(TestCase):
def test_create_role(self):
# Test to create role
response = self.client.security.put_role(self.ROLE_NAME, body=self.ROLE_CONTENT)
response = self.client.security.create_role(
self.ROLE_NAME, body=self.ROLE_CONTENT
)
self.assertNotIn("errors", response)
self.assertIn(response.get("status"), ["CREATED", "OK"])
def test_create_role_with_body_param_empty(self):
try:
self.client.security.create_role(self.ROLE_NAME, body="")
except ValueError as error:
assert str(error) == "Empty value passed for a required argument."
else:
assert False
def test_get_role(self):
# Create a role
self.test_create_role()
@@ -69,7 +79,7 @@ class TestSecurityPlugin(TestCase):
role_content["cluster_permissions"] = ["cluster_all"]
# Test to update role
response = self.client.security.put_role(self.ROLE_NAME, body=role_content)
response = self.client.security.create_role(self.ROLE_NAME, body=role_content)
self.assertNotIn("errors", response)
self.assertEqual("OK", response.get("status"))
@@ -89,16 +99,26 @@ class TestSecurityPlugin(TestCase):
def test_create_user(self):
# Test to create user
response = self.client.security.put_user(self.USER_NAME, body=self.USER_CONTENT)
response = self.client.security.create_user(
self.USER_NAME, body=self.USER_CONTENT
)
self.assertNotIn("errors", response)
self.assertIn(response.get("status"), ["CREATED", "OK"])
def test_create_user_with_body_param_empty(self):
try:
self.client.security.create_user(self.USER_NAME, body="")
except ValueError as error:
assert str(error) == "Empty value passed for a required argument."
else:
assert False
def test_create_user_with_role(self):
self.test_create_role()
# Test to create user
response = self.client.security.put_user(
response = self.client.security.create_user(
self.USER_NAME,
body={
"password": "opensearchpy@123",
@@ -127,7 +147,7 @@ class TestSecurityPlugin(TestCase):
user_content["password"] = "123@opensearchpy"
# Test to update user
response = self.client.security.put_user(self.USER_NAME, body=user_content)
response = self.client.security.create_user(self.USER_NAME, body=user_content)
self.assertNotIn("errors", response)
self.assertEqual("OK", response.get("status"))