From fb4dc0500ebe3099762cdac79a37f6b7d2e77003 Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 27 Nov 2024 12:20:44 -0500 Subject: [PATCH] Added a test that makes sure the slash is properly encoded. Signed-off-by: dblock --- .../test_async/test_server/test_clients.py | 13 +++++++++++++ test_opensearchpy/test_server/test_clients.py | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/test_opensearchpy/test_async/test_server/test_clients.py b/test_opensearchpy/test_async/test_server/test_clients.py index 282329c4..2ec7f0d0 100644 --- a/test_opensearchpy/test_async/test_server/test_clients.py +++ b/test_opensearchpy/test_async/test_server/test_clients.py @@ -30,9 +30,22 @@ import pytest from _pytest.mark.structures import MarkDecorator +from opensearchpy.exceptions import RequestError + pytestmark: MarkDecorator = pytest.mark.asyncio +class TestSpecialCharacters: + async def test_index_with_slash(self, async_client: Any) -> None: + index_name = "movies/shmovies" + with pytest.raises(RequestError) as e: + await async_client.indices.create(index=index_name) + assert ( + str(e.value) + == "RequestError(400, 'invalid_index_name_exception', 'Invalid index name [movies/shmovies], must not contain the following characters [ , \", *, \\\\, <, |, ,, >, /, ?]')" + ) + + class TestUnicode: async def test_indices_lifecycle_english(self, async_client: Any) -> None: index_name = "movies" diff --git a/test_opensearchpy/test_server/test_clients.py b/test_opensearchpy/test_server/test_clients.py index f43db08b..59fd8866 100644 --- a/test_opensearchpy/test_server/test_clients.py +++ b/test_opensearchpy/test_server/test_clients.py @@ -25,9 +25,24 @@ # under the License. +import pytest + +from opensearchpy.exceptions import RequestError + from . import OpenSearchTestCase +class TestSpecialCharacters(OpenSearchTestCase): + def test_index_with_slash(self) -> None: + index_name = "movies/shmovies" + with pytest.raises(RequestError) as e: + self.client.indices.create(index=index_name) + self.assertEqual( + str(e.value), + "RequestError(400, 'invalid_index_name_exception', 'Invalid index name [movies/shmovies], must not contain the following characters [ , \", *, \\\\, <, |, ,, >, /, ?]')" + ) + + class TestUnicode(OpenSearchTestCase): def test_indices_lifecycle_english(self) -> None: index_name = "movies"