未验证 提交 511f9706 编写于 作者: M Maxim Zhiltsov 提交者: GitHub

Allow trailing slashes in SDK client url (#5057)

上级 b029bc9d
......@@ -37,6 +37,8 @@ non-ascii paths while adding files from "Connected file share" (issue #4428)
- Fixed cvat-core ESlint problems (<https://github.com/opencv/cvat/pull/5027>)
- Fixed task creation with non-local files via the SDK/CLI
(<https://github.com/opencv/cvat/issues/4962>)
- A trailing slash in hostname does't allow SDK to send some requests
(<https://github.com/opencv/cvat/pull/5057>)
### Security
- TDB
......
......@@ -98,6 +98,8 @@ class Client:
schema = ""
base_url = url
base_url = base_url.rstrip("/")
if schema and schema not in cls.ALLOWED_SCHEMAS:
raise InvalidHostException(
f"Invalid url schema '{schema}', expected "
......@@ -279,7 +281,7 @@ class CVAT_API_V2:
"""Build parameterized API URLs"""
def __init__(self, host: str):
self.host = host
self.host = host.rstrip("/")
self.base = self.host + "/api/"
self.git = self.host + "/git/repository/"
......@@ -308,7 +310,7 @@ class CVAT_API_V2:
def make_client(
host: str, *, port: Optional[int] = None, credentials: Optional[Tuple[int, int]] = None
) -> Client:
url = host
url = host.rstrip("/")
if port:
url = f"{url}:{port}"
......
......@@ -58,6 +58,19 @@ class TestClientUsecases:
assert (version.major, version.minor) >= (2, 0)
def test_can_strip_trailing_slash_in_hostname_in_make_client(admin_user: str):
host, port = BASE_URL.split("://", maxsplit=1)[1].rsplit(":", maxsplit=1)
with make_client(host=host + "/", port=port, credentials=(admin_user, USER_PASS)) as client:
assert client.api_map.host == BASE_URL
def test_can_strip_trailing_slash_in_hostname_in_client_ctor(admin_user: str):
with Client(url=BASE_URL + "/") as client:
client.login((admin_user, USER_PASS))
assert client.api_map.host == BASE_URL
def test_can_detect_server_schema_if_not_provided():
host, port = BASE_URL.split("://", maxsplit=1)[1].rsplit(":", maxsplit=1)
client = make_client(host=host, port=int(port))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册