From d367f1bfc049dc5bcdafa1b19b95b1d00d1dac78 Mon Sep 17 00:00:00 2001 From: Stepan Burlakov Date: Mon, 6 Jun 2022 10:52:35 +0200 Subject: [PATCH 1/6] validate account_name in connect --- src/firebolt/async_db/connection.py | 10 ++++++++++ tests/unit/async_db/test_connection.py | 2 -- tests/unit/db/test_connection.py | 1 - 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/firebolt/async_db/connection.py b/src/firebolt/async_db/connection.py index 7a33d3ca42a..220b644c24e 100644 --- a/src/firebolt/async_db/connection.py +++ b/src/firebolt/async_db/connection.py @@ -222,6 +222,16 @@ async def connect_inner( account_name=account_name, api_endpoint=api_endpoint, ) + elif account_name: + # We need to manually validate account_name since it's not validated + # in neither of above cases + async with AsyncClient( + auth=auth, + base_url=api_endpoint, + account_name=account_name, + api_endpoint=api_endpoint, + ) as client: + await client.account_id assert engine_url is not None diff --git a/tests/unit/async_db/test_connection.py b/tests/unit/async_db/test_connection.py index b58ea120690..f68ab4bb65c 100644 --- a/tests/unit/async_db/test_connection.py +++ b/tests/unit/async_db/test_connection.py @@ -71,7 +71,6 @@ async def test_cursor_initialized( database=db_name, username="u", password="p", - account_name="a", api_endpoint=settings.server, ) ) as connection: @@ -116,7 +115,6 @@ async def test_connect_access_token( engine_url=settings.server, database=db_name, access_token=access_token, - account_name="a", api_endpoint=settings.server, ) ) as connection: diff --git a/tests/unit/db/test_connection.py b/tests/unit/db/test_connection.py index 9572ddc151a..b56cad50dbb 100644 --- a/tests/unit/db/test_connection.py +++ b/tests/unit/db/test_connection.py @@ -104,7 +104,6 @@ def test_connect_access_token( engine_url=settings.server, database=db_name, access_token=access_token, - account_name="a", api_endpoint=settings.server, ) ) as connection: From 58a0d563d7a63be456984098976cdf16001b44c5 Mon Sep 17 00:00:00 2001 From: Stepan Burlakov Date: Mon, 6 Jun 2022 11:09:04 +0200 Subject: [PATCH 2/6] add unit tests --- tests/unit/async_db/test_connection.py | 37 ++++++++++++++- tests/unit/conftest.py | 64 ++++++++++++++++++-------- tests/unit/db/test_connection.py | 41 ++++++++++++++++- 3 files changed, 119 insertions(+), 23 deletions(-) diff --git a/tests/unit/async_db/test_connection.py b/tests/unit/async_db/test_connection.py index f68ab4bb65c..d4c5c362517 100644 --- a/tests/unit/async_db/test_connection.py +++ b/tests/unit/async_db/test_connection.py @@ -7,9 +7,10 @@ from firebolt.async_db import Connection, connect from firebolt.async_db._types import ColType -from firebolt.client.auth import Token, UsernamePassword +from firebolt.client.auth import Auth, Token, UsernamePassword from firebolt.common.settings import Settings from firebolt.utils.exception import ( + AccountNotFoundError, ConfigurationError, ConnectionClosedError, FireboltEngineError, @@ -351,3 +352,37 @@ async def test_connect_with_auth( api_endpoint=settings.server, ) as connection: await connection.cursor().execute("select*") + + +@mark.asyncio +async def test_connect_account_name( + httpx_mock: HTTPXMock, + auth: Auth, + settings: Settings, + db_name: str, + auth_url: str, + check_credentials_callback: Callable, + account_id_url: str, + account_id_callback: Callable, +): + httpx_mock.add_callback(check_credentials_callback, url=auth_url) + httpx_mock.add_callback(account_id_callback, url=account_id_url) + + with raises(AccountNotFoundError): + async with await connect( + auth=auth, + database=db_name, + engine_url=settings.server, + account_name="invalid", + api_endpoint=settings.server, + ): + pass + + async with await connect( + auth=auth, + database=db_name, + engine_url=settings.server, + account_name=settings.account_name, + api_endpoint=settings.server, + ): + pass diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 2bba104ed58..3f5e58f3bf9 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -1,16 +1,19 @@ from json import loads +from re import compile from typing import Callable, List import httpx -from httpx import Response +from httpx import Request, Response from pydantic import SecretStr from pyfakefs.fake_filesystem_unittest import Patcher from pytest import fixture +from firebolt.client.auth import Auth, UsernamePassword from firebolt.common.settings import Settings from firebolt.model.provider import Provider from firebolt.model.region import Region, RegionKey from firebolt.utils.exception import ( + AccountNotFoundError, DatabaseError, DataError, Error, @@ -51,6 +54,16 @@ def global_fake_fs(request) -> None: yield +@fixture +def username() -> str: + return "email@domain.com" + + +@fixture +def password() -> str: + return "*****" + + @fixture def server() -> str: return "api.mock.firebolt.io" @@ -107,16 +120,21 @@ def mock_regions(region_1, region_2) -> List[Region]: @fixture -def settings(server, region_1) -> Settings: +def settings(server: str, region_1: str, username: str, password: str) -> Settings: return Settings( server=server, - user="email@domain.com", - password=SecretStr("*****"), + user=username, + password=SecretStr(password), default_region=region_1.name, account_name=None, ) +@fixture +def auth(username: str, password: str) -> Auth: + return UsernamePassword(username, password) + + @fixture def auth_callback(auth_url: str) -> Callable: def do_mock( @@ -147,31 +165,37 @@ def db_description() -> str: return "database description" +@fixture +def default_account_id_url(settings: Settings) -> str: + return f"https://{settings.server}{ACCOUNT_URL}" + + @fixture def account_id_url(settings: Settings) -> str: - if not settings.account_name: # if None or '' - return f"https://{settings.server}{ACCOUNT_URL}" - else: - return ( - f"https://{settings.server}{ACCOUNT_BY_NAME_URL}" - f"?account_name={settings.account_name}" - ) + base = f"https://{settings.server}{ACCOUNT_BY_NAME_URL}?account_name=" + default_base = f"https://{settings.server}{ACCOUNT_URL}" + base = base.replace("/", "\\/").replace("?", "\\?") + default_base = default_base.replace("/", "\\/").replace("?", "\\?") + return compile(f"(?:{base}.*|{default_base})") @fixture def account_id_callback( - account_id: str, account_id_url: str, settings: Settings + account_id: str, + account_id_url: str, + settings: Settings, ) -> Callable: def do_mock( - request: httpx.Request = None, + request: Request, **kwargs, ) -> Response: - assert request.url == account_id_url - if account_id_url.endswith(ACCOUNT_URL): # account_name shouldn't be specified. + if "account_name" not in request.url.params: return Response( status_code=httpx.codes.OK, json={"account": {"id": account_id}} ) # In this case, an account_name *should* be specified. + if request.url.params["account_name"] != settings.account_name: + raise AccountNotFoundError(request.url.params["account_name"]) return Response(status_code=httpx.codes.OK, json={"account_id": account_id}) return do_mock @@ -194,7 +218,7 @@ def get_engine_callback( get_engine_url: str, engine_id: str, settings: Settings ) -> Callable: def do_mock( - request: httpx.Request = None, + request: Request = None, **kwargs, ) -> Response: assert request.url == get_engine_url @@ -230,7 +254,7 @@ def get_providers_url(settings: Settings, account_id: str, engine_id: str) -> st @fixture def get_providers_callback(get_providers_url: str, provider: Provider) -> Callable: def do_mock( - request: httpx.Request = None, + request: Request = None, **kwargs, ) -> Response: assert request.url == get_providers_url @@ -269,7 +293,7 @@ def database_by_name_url(settings: Settings, account_id: str, db_name: str) -> s @fixture def database_by_name_callback(account_id: str, database_id: str) -> str: def do_mock( - request: httpx.Request = None, + request: Request = None, **kwargs, ) -> Response: return Response( @@ -312,7 +336,7 @@ def db_api_exceptions(): @fixture def check_token_callback(access_token: str) -> Callable: - def check_token(request: httpx.Request = None, **kwargs) -> Response: + def check_token(request: Request = None, **kwargs) -> Response: prefix = "Bearer " assert request, "empty request" assert "authorization" in request.headers, "missing authorization header" @@ -329,7 +353,7 @@ def check_token(request: httpx.Request = None, **kwargs) -> Response: @fixture def check_credentials_callback(settings: Settings, access_token: str) -> Callable: def check_credentials( - request: httpx.Request = None, + request: Request = None, **kwargs, ) -> Response: assert request, "empty request" diff --git a/tests/unit/db/test_connection.py b/tests/unit/db/test_connection.py index b56cad50dbb..c39c00c3635 100644 --- a/tests/unit/db/test_connection.py +++ b/tests/unit/db/test_connection.py @@ -6,10 +6,14 @@ from pytest_httpx import HTTPXMock from firebolt.async_db._types import ColType -from firebolt.client.auth import Token, UsernamePassword +from firebolt.client.auth import Auth, Token, UsernamePassword from firebolt.common.settings import Settings from firebolt.db import Connection, connect -from firebolt.utils.exception import ConfigurationError, ConnectionClosedError +from firebolt.utils.exception import ( + AccountNotFoundError, + ConfigurationError, + ConnectionClosedError, +) from firebolt.utils.token_storage import TokenSecureStorage from firebolt.utils.urls import ACCOUNT_ENGINE_BY_NAME_URL @@ -322,3 +326,36 @@ def test_connect_with_auth( api_endpoint=settings.server, ) as connection: connection.cursor().execute("select*") + + +def test_connect_account_name( + httpx_mock: HTTPXMock, + auth: Auth, + settings: Settings, + db_name: str, + auth_url: str, + check_credentials_callback: Callable, + account_id_url: str, + account_id_callback: Callable, +): + httpx_mock.add_callback(check_credentials_callback, url=auth_url) + httpx_mock.add_callback(account_id_callback, url=account_id_url) + + with raises(AccountNotFoundError): + with connect( + auth=auth, + database=db_name, + engine_url=settings.server, + account_name="invalid", + api_endpoint=settings.server, + ): + pass + + with connect( + auth=auth, + database=db_name, + engine_url=settings.server, + account_name=settings.account_name, + api_endpoint=settings.server, + ): + pass From d22353531c38a4b8f29d441c43a263c280fe7a94 Mon Sep 17 00:00:00 2001 From: Stepan Burlakov Date: Mon, 6 Jun 2022 11:17:49 +0200 Subject: [PATCH 3/6] add test for resource manager invalid account name --- tests/unit/service/test_resource_manager.py | 29 +++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/unit/service/test_resource_manager.py b/tests/unit/service/test_resource_manager.py index 9c5e8e585e8..29595791a2d 100644 --- a/tests/unit/service/test_resource_manager.py +++ b/tests/unit/service/test_resource_manager.py @@ -1,12 +1,13 @@ from typing import Callable from pyfakefs.fake_filesystem_unittest import Patcher -from pytest import mark +from pytest import mark, raises from pytest_httpx import HTTPXMock -from firebolt.client.auth import Token, UsernamePassword +from firebolt.client.auth import Auth, Token, UsernamePassword from firebolt.common.settings import Settings from firebolt.service.manager import ResourceManager +from firebolt.utils.exception import AccountNotFoundError from firebolt.utils.token_storage import TokenSecureStorage @@ -112,3 +113,27 @@ def test_rm_token_cache( assert ( ts.get_cached_token() is None ), "Token is cached even though caching is disabled" + + +def test_rm_invalid_account_name( + httpx_mock: HTTPXMock, + auth: Auth, + settings: Settings, + check_credentials_callback: Callable, + auth_url: str, + account_id_url: str, + account_id_callback: Callable, +) -> None: + """Resource manager raises an error on invalid account name.""" + httpx_mock.add_callback(check_credentials_callback, url=auth_url) + httpx_mock.add_callback(account_id_callback, url=account_id_url) + + local_settings = Settings( + auth=auth, + account_name="invalid", + server=settings.server, + default_region=settings.default_region, + ) + + with raises(AccountNotFoundError): + ResourceManager(local_settings) From 4320c98736f1c8178617c753be9e6dcbef4c5bd9 Mon Sep 17 00:00:00 2001 From: Stepan Burlakov Date: Mon, 6 Jun 2022 15:24:53 +0200 Subject: [PATCH 4/6] resolve comments --- tests/unit/async_db/test_connection.py | 7 ++++--- tests/unit/client/test_client.py | 3 ++- tests/unit/client/test_client_async.py | 3 ++- tests/unit/conftest.py | 10 ++-------- tests/unit/db/test_connection.py | 7 ++++--- tests/unit/service/test_database.py | 12 ++++++------ tests/unit/service/test_engine.py | 21 +++++++++++---------- tests/unit/service/test_instance_type.py | 3 ++- tests/unit/service/test_region.py | 3 ++- tests/unit/service/test_resource_manager.py | 7 ++++--- 10 files changed, 39 insertions(+), 37 deletions(-) diff --git a/tests/unit/async_db/test_connection.py b/tests/unit/async_db/test_connection.py index d4c5c362517..f56803201b3 100644 --- a/tests/unit/async_db/test_connection.py +++ b/tests/unit/async_db/test_connection.py @@ -1,3 +1,4 @@ +from re import Pattern from typing import Callable, List from httpx import codes @@ -146,7 +147,7 @@ async def test_connect_engine_name( auth_url: str, query_callback: Callable, query_url: str, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, engine_id: str, get_engine_url: str, @@ -222,7 +223,7 @@ async def test_connect_default_engine( auth_url: str, query_callback: Callable, query_url: str, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, engine_id: str, get_engine_url: str, @@ -362,7 +363,7 @@ async def test_connect_account_name( db_name: str, auth_url: str, check_credentials_callback: Callable, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, ): httpx_mock.add_callback(check_credentials_callback, url=auth_url) diff --git a/tests/unit/client/test_client.py b/tests/unit/client/test_client.py index 7bd30c98f8b..bbf403450f8 100644 --- a/tests/unit/client/test_client.py +++ b/tests/unit/client/test_client.py @@ -1,3 +1,4 @@ +from re import Pattern from typing import Callable from httpx import codes @@ -93,7 +94,7 @@ def test_client_account_id( test_username: str, test_password: str, account_id: str, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, auth_url: str, auth_callback: Callable, diff --git a/tests/unit/client/test_client_async.py b/tests/unit/client/test_client_async.py index 1cc02dc4449..727fd614a6c 100644 --- a/tests/unit/client/test_client_async.py +++ b/tests/unit/client/test_client_async.py @@ -1,3 +1,4 @@ +from re import Pattern from typing import Callable from httpx import codes @@ -104,7 +105,7 @@ async def test_client_account_id( test_username: str, test_password: str, account_id: str, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, auth_url: str, auth_callback: Callable, diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 3f5e58f3bf9..b9b2ae7f996 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -1,5 +1,5 @@ from json import loads -from re import compile +from re import Pattern, compile from typing import Callable, List import httpx @@ -166,12 +166,7 @@ def db_description() -> str: @fixture -def default_account_id_url(settings: Settings) -> str: - return f"https://{settings.server}{ACCOUNT_URL}" - - -@fixture -def account_id_url(settings: Settings) -> str: +def account_id_url(settings: Settings) -> Pattern: base = f"https://{settings.server}{ACCOUNT_BY_NAME_URL}?account_name=" default_base = f"https://{settings.server}{ACCOUNT_URL}" base = base.replace("/", "\\/").replace("?", "\\?") @@ -182,7 +177,6 @@ def account_id_url(settings: Settings) -> str: @fixture def account_id_callback( account_id: str, - account_id_url: str, settings: Settings, ) -> Callable: def do_mock( diff --git a/tests/unit/db/test_connection.py b/tests/unit/db/test_connection.py index c39c00c3635..5d44a26e799 100644 --- a/tests/unit/db/test_connection.py +++ b/tests/unit/db/test_connection.py @@ -1,3 +1,4 @@ +from re import Pattern from typing import Callable, List from httpx import codes @@ -137,7 +138,7 @@ def test_connect_engine_name( auth_url: str, query_callback: Callable, query_url: str, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, engine_id: str, get_engine_url: str, @@ -193,7 +194,7 @@ def test_connect_default_engine( auth_url: str, query_callback: Callable, query_url: str, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, engine_id: str, get_engine_url: str, @@ -335,7 +336,7 @@ def test_connect_account_name( db_name: str, auth_url: str, check_credentials_callback: Callable, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, ): httpx_mock.add_callback(check_credentials_callback, url=auth_url) diff --git a/tests/unit/service/test_database.py b/tests/unit/service/test_database.py index 1b5bb1ea726..35dec331ad6 100644 --- a/tests/unit/service/test_database.py +++ b/tests/unit/service/test_database.py @@ -1,4 +1,4 @@ -import re +from re import Pattern, compile from typing import Callable from pytest_httpx import HTTPXMock @@ -18,7 +18,7 @@ def test_database_create( region_url: str, settings: Settings, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, create_databases_callback: Callable, databases_url: str, db_name: str, @@ -46,7 +46,7 @@ def test_database_get_by_name( provider_url: str, settings: Settings, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, database_get_by_name_callback: Callable, database_get_by_name_url: str, database_get_callback: Callable, @@ -75,7 +75,7 @@ def test_database_get_many( provider_url: str, settings: Settings, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, database_get_by_name_callback: Callable, database_get_by_name_url: str, databases_get_callback: Callable, @@ -89,7 +89,7 @@ def test_database_get_many( httpx_mock.add_callback(auth_callback, url=auth_url) httpx_mock.add_callback( databases_get_callback, - url=re.compile(databases_url + "?[a-zA-Z0-9=&]*"), + url=compile(databases_url + "?[a-zA-Z0-9=&]*"), method="GET", ) @@ -112,7 +112,7 @@ def test_database_update( provider_url: str, settings: Settings, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, database_update_callback: Callable, database_url: str, mock_database: Database, diff --git a/tests/unit/service/test_engine.py b/tests/unit/service/test_engine.py index 50bea0cb3bd..18b93af5c44 100644 --- a/tests/unit/service/test_engine.py +++ b/tests/unit/service/test_engine.py @@ -1,3 +1,4 @@ +from re import Pattern from typing import Callable, List from pydantic import ValidationError @@ -29,7 +30,7 @@ def test_engine_create( mock_engine: Engine, engine_name: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, engine_callback: Callable, engine_url: str, ): @@ -63,7 +64,7 @@ def test_engine_create_with_kwargs( mock_engine: Engine, engine_name: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, engine_callback: Callable, engine_url: str, account_id: str, @@ -121,7 +122,7 @@ def test_engine_create_with_kwargs_fail( settings: Settings, engine_name: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, ): httpx_mock.add_callback(auth_callback, url=auth_url) httpx_mock.add_callback(provider_callback, url=provider_url) @@ -158,7 +159,7 @@ def test_engine_create_no_available_types( mock_instance_types: List[InstanceType], engine_name: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, engine_url: str, region_2: Region, ): @@ -192,7 +193,7 @@ def test_engine_no_attached_database( mock_engine: Engine, engine_name: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, engine_callback: Callable, engine_url: str, account_engine_callback: Callable, @@ -236,7 +237,7 @@ def test_engine_start_binding_to_missing_database( mock_engine: Engine, engine_name: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, engine_callback: Callable, engine_url: str, database_not_found_callback: Callable, @@ -279,7 +280,7 @@ def test_get_connection( mock_engine: Engine, engine_name: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, engine_callback: Callable, engine_url: str, db_name: str, @@ -320,7 +321,7 @@ def test_attach_to_database( instance_type_region_1_url: str, settings: Settings, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, create_databases_callback: Callable, databases_url: str, database_get_callback: Callable, @@ -382,7 +383,7 @@ def test_engine_update( mock_engine: Engine, engine_name: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, engine_callback: Callable, engine_url: str, account_engine_url: str, @@ -418,7 +419,7 @@ def test_engine_restart( settings: Settings, mock_engine: Engine, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, engine_callback: Callable, account_engine_url: str, bindings_callback: Callable, diff --git a/tests/unit/service/test_instance_type.py b/tests/unit/service/test_instance_type.py index d1e9510e35e..dce917c1f42 100644 --- a/tests/unit/service/test_instance_type.py +++ b/tests/unit/service/test_instance_type.py @@ -1,3 +1,4 @@ +from re import Pattern from typing import Callable, List from pytest_httpx import HTTPXMock @@ -21,7 +22,7 @@ def test_instance_type( instance_type_region_1_url: str, instance_type_region_2_url: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, settings: Settings, mock_instance_types: List[InstanceType], cheapest_instance: InstanceType, diff --git a/tests/unit/service/test_region.py b/tests/unit/service/test_region.py index 121e09bdc9e..939238f6bfe 100644 --- a/tests/unit/service/test_region.py +++ b/tests/unit/service/test_region.py @@ -1,3 +1,4 @@ +from re import Pattern from typing import Callable, List from pytest_httpx import HTTPXMock @@ -16,7 +17,7 @@ def test_region( region_callback: Callable, region_url: str, account_id_callback: Callable, - account_id_url: str, + account_id_url: Pattern, settings: Settings, mock_regions: List[Region], ): diff --git a/tests/unit/service/test_resource_manager.py b/tests/unit/service/test_resource_manager.py index 29595791a2d..778025cca7a 100644 --- a/tests/unit/service/test_resource_manager.py +++ b/tests/unit/service/test_resource_manager.py @@ -1,3 +1,4 @@ +from re import Pattern from typing import Callable from pyfakefs.fake_filesystem_unittest import Patcher @@ -17,7 +18,7 @@ def test_rm_credentials( check_credentials_callback: Callable, settings: Settings, auth_url: str, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, provider_callback: Callable, provider_url: str, @@ -69,7 +70,7 @@ def test_rm_token_cache( check_credentials_callback: Callable, settings: Settings, auth_url: str, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, provider_callback: Callable, provider_url: str, @@ -121,7 +122,7 @@ def test_rm_invalid_account_name( settings: Settings, check_credentials_callback: Callable, auth_url: str, - account_id_url: str, + account_id_url: Pattern, account_id_callback: Callable, ) -> None: """Resource manager raises an error on invalid account name.""" From 4cd950ef290e4e2499e997447738f5f0f792f87c Mon Sep 17 00:00:00 2001 From: Stepan Burlakov Date: Mon, 6 Jun 2022 15:27:11 +0200 Subject: [PATCH 5/6] extend comment --- src/firebolt/async_db/connection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/firebolt/async_db/connection.py b/src/firebolt/async_db/connection.py index 220b644c24e..76114f7a745 100644 --- a/src/firebolt/async_db/connection.py +++ b/src/firebolt/async_db/connection.py @@ -223,8 +223,10 @@ async def connect_inner( api_endpoint=api_endpoint, ) elif account_name: + # In above if branches account name is validated since it's used to + # resolve or get an engine url. # We need to manually validate account_name since it's not validated - # in neither of above cases + # in neither of above cases. async with AsyncClient( auth=auth, base_url=api_endpoint, From 15d8b89c0957451793857076c941e3fc2eeeae49 Mon Sep 17 00:00:00 2001 From: Stepan Burlakov Date: Mon, 6 Jun 2022 16:34:47 +0200 Subject: [PATCH 6/6] improve comment --- src/firebolt/async_db/connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/firebolt/async_db/connection.py b/src/firebolt/async_db/connection.py index 76114f7a745..85d73e9010a 100644 --- a/src/firebolt/async_db/connection.py +++ b/src/firebolt/async_db/connection.py @@ -225,8 +225,8 @@ async def connect_inner( elif account_name: # In above if branches account name is validated since it's used to # resolve or get an engine url. - # We need to manually validate account_name since it's not validated - # in neither of above cases. + # We need to manually validate account_name if none of the above + # cases are triggered. async with AsyncClient( auth=auth, base_url=api_endpoint,