Skip to content

Commit 1329c24

Browse files
Merge branch '0.10' into fix/emailpassword-handle-invalid-req
2 parents 20923e6 + a7b2198 commit 1329c24

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Bug fix
1010
- Send 400 instead of 500 on invalid request body or when user passes non-string values as email ID for `/auth/signin`
1111

12+
### Changes
13+
- Add to test to ensure that overrides are applying correctly in methods called on SessionContainer instances
14+
1215
## [0.10.2] - 2022-07-14
1316
### Bug fix
1417
- Make `user_context` optional in userroles recipe syncio functions.

tests/test_session.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
from typing import List
15+
from typing import List, Dict, Any
16+
from unittest.mock import MagicMock
1617

1718
from fastapi import FastAPI
1819
from fastapi.requests import Request
@@ -23,7 +24,7 @@
2324
from supertokens_python.framework.fastapi.fastapi_middleware import get_middleware
2425
from supertokens_python.process_state import AllowedProcessStates, ProcessState
2526
from supertokens_python.recipe import session
26-
from supertokens_python.recipe.session import SessionRecipe
27+
from supertokens_python.recipe.session import SessionRecipe, InputOverrideConfig
2728
from supertokens_python.recipe.session.asyncio import (
2829
get_all_session_handles_for_user,
2930
get_session_information,
@@ -36,15 +37,21 @@
3637
update_access_token_payload,
3738
update_session_data,
3839
)
40+
from supertokens_python.recipe.session.interfaces import RecipeInterface
3941
from supertokens_python.recipe.session.recipe_implementation import RecipeImplementation
4042
from supertokens_python.recipe.session.session_functions import (
4143
create_new_session,
4244
get_session,
4345
refresh_session,
4446
revoke_session,
4547
)
48+
from supertokens_python.recipe.session.asyncio import (
49+
create_new_session as async_create_new_session,
50+
)
4651
from tests.utils import clean_st, reset, setup_st, start_st
4752

53+
pytestmark = mark.asyncio
54+
4855

4956
def setup_function(_):
5057
reset()
@@ -57,7 +64,6 @@ def teardown_function(_):
5764
clean_st()
5865

5966

60-
@mark.asyncio
6167
async def test_that_once_the_info_is_loaded_it_doesnt_query_again():
6268
init(
6369
supertokens_config=SupertokensConfig("http://localhost:3567"),
@@ -152,7 +158,6 @@ async def test_that_once_the_info_is_loaded_it_doesnt_query_again():
152158
assert response5 is True
153159

154160

155-
@mark.asyncio
156161
async def test_creating_many_sessions_for_one_user_and_looping():
157162
init(
158163
supertokens_config=SupertokensConfig("http://localhost:3567"),
@@ -235,7 +240,6 @@ async def home(_request: Request): # type: ignore
235240
return TestClient(app)
236241

237242

238-
@mark.asyncio
239243
async def test_signout_api_works_even_if_session_is_deleted_after_creation(
240244
driver_config_client: TestClient,
241245
):
@@ -278,3 +282,50 @@ async def test_signout_api_works_even_if_session_is_deleted_after_creation(
278282
signout_response.headers["set-cookie"]
279283
== """sAccessToken=""; expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Path=/; SameSite=lax; Secure, sIdRefreshToken=""; expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Path=/; SameSite=lax; Secure, sRefreshToken=""; expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Path=/auth/session/refresh; SameSite=lax; Secure"""
280284
)
285+
286+
287+
async def test_should_use_override_functions_in_session_container_methods():
288+
def override_session_functions(oi: RecipeInterface) -> RecipeInterface:
289+
oi_get_session_information = oi.get_session_information
290+
291+
async def get_session_information(
292+
session_handle: str, user_context: Dict[str, Any]
293+
):
294+
info = await oi_get_session_information(session_handle, user_context)
295+
assert info is not None
296+
info.session_data["foo"] = "bar"
297+
return info
298+
299+
oi.get_session_information = get_session_information
300+
301+
return oi
302+
303+
init(
304+
supertokens_config=SupertokensConfig("http://localhost:3567"),
305+
app_info=InputAppInfo(
306+
app_name="SuperTokens Demo",
307+
api_domain="https://api.supertokens.io",
308+
website_domain="supertokens.io",
309+
),
310+
framework="fastapi",
311+
recipe_list=[
312+
session.init(
313+
anti_csrf="VIA_TOKEN",
314+
override=InputOverrideConfig(
315+
functions=override_session_functions,
316+
),
317+
)
318+
],
319+
)
320+
start_st()
321+
322+
s = SessionRecipe.get_instance()
323+
if not isinstance(s.recipe_implementation, RecipeImplementation):
324+
raise Exception("Should never come here")
325+
326+
mock_response = MagicMock()
327+
328+
my_session = await async_create_new_session(mock_response, "test_id")
329+
data = await my_session.get_session_data()
330+
331+
assert data == {"foo": "bar"}

0 commit comments

Comments
 (0)