Skip to content

Commit 6add7d3

Browse files
Merge pull request #471 from supertokens/fix/domain-normalisation
fix: normalise connection_uri in the dashboard recipe
2 parents 9656c04 + 5ec12a6 commit 6add7d3

File tree

6 files changed

+80
-3
lines changed

6 files changed

+80
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [unreleased]
1010

11+
## [0.18.7] - 2024-01-17
12+
13+
- Fixes `connection_uri` normalisation in the dashboard recipe.
14+
1115
## [0.18.6] - 2024-01-12
1216

1317
- Relax constraints on `httpx` dependency version.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
setup(
7272
name="supertokens_python",
73-
version="0.18.6",
73+
version="0.18.7",
7474
author="SuperTokens",
7575
license="Apache 2.0",
7676
author_email="[email protected]",

supertokens_python/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import annotations
1515

1616
SUPPORTED_CDI_VERSIONS = ["3.0"]
17-
VERSION = "0.18.6"
17+
VERSION = "0.18.7"
1818
TELEMETRY = "/telemetry"
1919
USER_COUNT = "/users/count"
2020
USER_DELETE = "/user/remove"

supertokens_python/recipe/dashboard/api/implementation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ async def dashboard_get(
5050
connection_uri = ""
5151
super_tokens_instance = Supertokens.get_instance()
5252
auth_mode = options.config.auth_mode
53-
connection_uri = super_tokens_instance.supertokens_config.connection_uri
53+
connection_uri = NormalisedURLDomain(
54+
super_tokens_instance.supertokens_config.connection_uri.split(";")[0]
55+
).get_as_string_dangerous()
5456

5557
dashboard_path = options.app_info.api_base_path.append(
5658
NormalisedURLPath(DASHBOARD_API)

tests/dashboard/test_dashboard.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,73 @@ async def should_allow_access(
127127
assert body["users"][0]["user"]["firstName"] == "User2"
128128
assert body["users"][1]["user"]["lastName"] == "Foo"
129129
assert body["users"][1]["user"]["firstName"] == "User1"
130+
131+
132+
async def test_connection_uri_has_http_prefix_if_localhost(app: TestClient):
133+
connection_uri = start_st()
134+
connection_uri_without_protocol = connection_uri.replace("http://", "")
135+
136+
st_args = get_st_init_args(
137+
[
138+
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
139+
dashboard.init(api_key="someKey"),
140+
]
141+
)
142+
143+
st_config = st_args.get("supertokens_config")
144+
if st_config:
145+
st_config.connection_uri = connection_uri_without_protocol
146+
147+
init(**st_args)
148+
149+
res = app.get(url="/auth/dashboard")
150+
assert res.status_code == 200
151+
assert f'window.connectionURI = "{connection_uri}"' in str(res.text)
152+
153+
154+
async def test_connection_uri_has_https_prefix_if_not_localhost(app: TestClient):
155+
start_st()
156+
connection_uri = "https://try.supertokens.com"
157+
connection_uri_without_protocol = connection_uri.replace("https://", "")
158+
159+
st_args = get_st_init_args(
160+
[
161+
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
162+
dashboard.init(api_key="someKey"),
163+
]
164+
)
165+
166+
st_config = st_args.get("supertokens_config")
167+
if st_config:
168+
st_config.connection_uri = connection_uri_without_protocol
169+
170+
init(**st_args)
171+
172+
res = app.get(url="/auth/dashboard")
173+
assert res.status_code == 200
174+
assert f'window.connectionURI = "{connection_uri}"' in str(res.text)
175+
176+
177+
async def test_that_first_connection_uri_is_selected_among_multiple_uris(
178+
app: TestClient,
179+
):
180+
first_connection_uri = start_st()
181+
second_connection_uri = "https://try.supertokens.com"
182+
multiple_connection_uris = f"{first_connection_uri};{second_connection_uri}"
183+
184+
st_args = get_st_init_args(
185+
[
186+
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
187+
dashboard.init(api_key="someKey"),
188+
]
189+
)
190+
191+
st_config = st_args.get("supertokens_config")
192+
if st_config:
193+
st_config.connection_uri = multiple_connection_uris
194+
195+
init(**st_args)
196+
197+
res = app.get(url="/auth/dashboard")
198+
assert res.status_code == 200
199+
assert f'window.connectionURI = "{first_connection_uri}"' in str(res.text)

tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def start_st(host: str = "localhost", port: str = "3567"):
150150
sleep(0.5)
151151
if len(pid_after) == len(pid_before):
152152
raise Exception("could not start ST process")
153+
return f"http://{host}:{port}"
153154

154155

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

0 commit comments

Comments
 (0)