Skip to content

fix: normalise connection_uri in the dashboard recipe #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.18.7] - 2024-01-17

- Fixes `connection_uri` normalisation in the dashboard recipe.

## [0.18.6] - 2024-01-12

- Relax constraints on `httpx` dependency version.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

setup(
name="supertokens_python",
version="0.18.6",
version="0.18.7",
author="SuperTokens",
license="Apache 2.0",
author_email="[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion supertokens_python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from __future__ import annotations

SUPPORTED_CDI_VERSIONS = ["3.0"]
VERSION = "0.18.6"
VERSION = "0.18.7"
TELEMETRY = "/telemetry"
USER_COUNT = "/users/count"
USER_DELETE = "/user/remove"
Expand Down
4 changes: 3 additions & 1 deletion supertokens_python/recipe/dashboard/api/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ async def dashboard_get(
connection_uri = ""
super_tokens_instance = Supertokens.get_instance()
auth_mode = options.config.auth_mode
connection_uri = super_tokens_instance.supertokens_config.connection_uri
connection_uri = NormalisedURLDomain(
super_tokens_instance.supertokens_config.connection_uri.split(";")[0]
).get_as_string_dangerous()

dashboard_path = options.app_info.api_base_path.append(
NormalisedURLPath(DASHBOARD_API)
Expand Down
70 changes: 70 additions & 0 deletions tests/dashboard/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,73 @@ async def should_allow_access(
assert body["users"][0]["user"]["firstName"] == "User2"
assert body["users"][1]["user"]["lastName"] == "Foo"
assert body["users"][1]["user"]["firstName"] == "User1"


async def test_connection_uri_has_http_prefix_if_localhost(app: TestClient):
connection_uri = start_st()
connection_uri_without_protocol = connection_uri.replace("http://", "")

st_args = get_st_init_args(
[
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
dashboard.init(api_key="someKey"),
]
)

st_config = st_args.get("supertokens_config")
if st_config:
st_config.connection_uri = connection_uri_without_protocol

init(**st_args)

res = app.get(url="/auth/dashboard")
assert res.status_code == 200
assert f'window.connectionURI = "{connection_uri}"' in str(res.text)


async def test_connection_uri_has_https_prefix_if_not_localhost(app: TestClient):
start_st()
connection_uri = "https://try.supertokens.com"
connection_uri_without_protocol = connection_uri.replace("https://", "")

st_args = get_st_init_args(
[
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
dashboard.init(api_key="someKey"),
]
)

st_config = st_args.get("supertokens_config")
if st_config:
st_config.connection_uri = connection_uri_without_protocol

init(**st_args)

res = app.get(url="/auth/dashboard")
assert res.status_code == 200
assert f'window.connectionURI = "{connection_uri}"' in str(res.text)


async def test_that_first_connection_uri_is_selected_among_multiple_uris(
app: TestClient,
):
first_connection_uri = start_st()
second_connection_uri = "https://try.supertokens.com"
multiple_connection_uris = f"{first_connection_uri};{second_connection_uri}"

st_args = get_st_init_args(
[
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
dashboard.init(api_key="someKey"),
]
)

st_config = st_args.get("supertokens_config")
if st_config:
st_config.connection_uri = multiple_connection_uris

init(**st_args)

res = app.get(url="/auth/dashboard")
assert res.status_code == 200
assert f'window.connectionURI = "{first_connection_uri}"' in str(res.text)
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def start_st(host: str = "localhost", port: str = "3567"):
sleep(0.5)
if len(pid_after) == len(pid_before):
raise Exception("could not start ST process")
return f"http://{host}:{port}"


def setup_multitenancy_feature(host: str = "localhost", port: str = "3567"):
Expand Down