Skip to content

Commit bd91b74

Browse files
Merge pull request #396 from supertokens/fix/multitenancy-recipe-tests
fix: Multitenancy tests for all the recipes
2 parents 6083a1b + 3acd4e7 commit bd91b74

23 files changed

+130
-65
lines changed

supertokens_python/recipe/emailpassword/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def default_validator(_: str, __: str) -> Union[str, None]:
4242
return None
4343

4444

45-
async def default_password_validator(_: str, value: str) -> Union[str, None]:
45+
async def default_password_validator(value: str, _tenant_id: str) -> Union[str, None]:
4646
# length >= 8 && < 100
4747
# must have a number and a character
4848
# as per
@@ -62,7 +62,7 @@ async def default_password_validator(_: str, value: str) -> Union[str, None]:
6262
return None
6363

6464

65-
async def default_email_validator(_: str, value: Any) -> Union[str, None]:
65+
async def default_email_validator(value: Any, _tenant_id: str) -> Union[str, None]:
6666
# We check if the email syntax is correct
6767
# As per https://github.com/supertokens/supertokens-auth-react/issues/5#issuecomment-709512438
6868
# Regex from https://stackoverflow.com/a/46181/3867175

supertokens_python/recipe/passwordless/recipe_implementation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ async def get_user_by_phone_number(
206206
) -> Union[User, None]:
207207
param = {"phoneNumber": phone_number}
208208
result = await self.querier.send_get_request(
209-
NormalisedURLPath("{tenant_id}/recipe/user"), param
209+
NormalisedURLPath(f"{tenant_id}/recipe/user"), param
210210
)
211211
if result["status"] == "OK":
212212
email_resp = None

supertokens_python/recipe/thirdparty/api/implementation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
from __future__ import annotations
15+
from supertokens_python.utils import utf_base64decode
1516
from base64 import b64decode
1617
import json
1718

supertokens_python/recipe/thirdparty/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def __init__(
226226
force_pkce: bool = False,
227227
additional_config: Optional[Dict[str, Any]] = None,
228228
# CommonProviderConfig:
229+
third_party_id: str = "temp",
229230
name: Optional[str] = None,
230231
authorization_endpoint: Optional[str] = None,
231232
authorization_endpoint_query_params: Optional[
@@ -261,7 +262,7 @@ def __init__(
261262
)
262263
CommonProviderConfig.__init__(
263264
self,
264-
"temp",
265+
third_party_id,
265266
name,
266267
authorization_endpoint,
267268
authorization_endpoint_query_params,

supertokens_python/recipe/thirdparty/providers/config_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def merge_providers_from_core_and_static(
166166
merged_provider_input.override = provider_input_from_static.override
167167
break
168168

169+
merged_providers.append(merged_provider_input)
170+
169171
return merged_providers
170172

171173

supertokens_python/recipe/thirdparty/providers/custom.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def get_provider_config_for_client(
4343
force_pkce=client_config.force_pkce,
4444
additional_config=client_config.additional_config,
4545
# CommonProviderConfig
46+
third_party_id=config.third_party_id,
4647
name=config.name,
4748
authorization_endpoint=config.authorization_endpoint,
4849
authorization_endpoint_query_params=config.authorization_endpoint_query_params,
@@ -179,7 +180,8 @@ def __init__(self, provider_config: ProviderConfig):
179180
self.input_config = input_config = self._normalize_input(provider_config)
180181

181182
provider_config_for_client = ProviderConfigForClient(
182-
# Will automatically get replaced by correct value
183+
# Will automatically get replaced with correct value
184+
# in get_provider_config_for_client
183185
# when fetch_and_set_config function runs
184186
client_id="temp",
185187
client_secret=None,

supertokens_python/recipe/thirdparty/recipe_implementation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async def get_users_by_email(
7777
user["id"],
7878
user["email"],
7979
user["timeJoined"],
80-
response["user"]["tenantIds"],
80+
user["tenantIds"],
8181
ThirdPartyInfo(
8282
user["thirdParty"]["userId"], user["thirdParty"]["id"]
8383
),

supertokens_python/recipe/userroles/recipe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ async def fetch_value(
152152
recipe = UserRolesRecipe.get_instance()
153153

154154
user_roles = await recipe.recipe_implementation.get_roles_for_user(
155-
tenant_id, user_id, user_context
155+
user_id, tenant_id, user_context
156156
)
157157

158158
user_permissions: Set[str] = set()
@@ -186,7 +186,7 @@ async def fetch_value(
186186
) -> List[str]:
187187
recipe = UserRolesRecipe.get_instance()
188188
res = await recipe.recipe_implementation.get_roles_for_user(
189-
tenant_id, user_id, user_context
189+
user_id, tenant_id, user_context
190190
)
191191
return res.roles
192192

tests/Django/test_django.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from urllib.parse import urlencode
1717
from datetime import datetime
1818
from inspect import isawaitable
19+
from base64 import b64encode
1920
from typing import Any, Dict, Union
2021

2122
from django.http import HttpRequest, HttpResponse, JsonResponse
@@ -455,10 +456,10 @@ async def test_thirdparty_parsing_works(self):
455456

456457
start_st()
457458

458-
data = {
459-
"state": "afc596274293e1587315c",
460-
"code": "c7685e261f98e4b3b94e34b3a69ff9cf4.0.rvxt.eE8rO__6hGoqaX1B7ODPmA",
461-
}
459+
state = b64encode(json.dumps({"redirectURI": "http://localhost:3000/redirect" }).encode()).decode()
460+
code = "testing"
461+
462+
data = { "state": state, "code": code}
462463

463464
request = self.factory.post(
464465
"/auth/callback/apple",
@@ -470,11 +471,9 @@ async def test_thirdparty_parsing_works(self):
470471
raise Exception("Should never come here")
471472
response = await temp
472473

473-
self.assertEqual(response.status_code, 200)
474-
self.assertEqual(
475-
response.content,
476-
b'<html><head><script>window.location.replace("http://supertokens.io/auth/callback/apple?state=afc596274293e1587315c&code=c7685e261f98e4b3b94e34b3a69ff9cf4.0.rvxt.eE8rO__6hGoqaX1B7ODPmA");</script></head></html>',
477-
)
474+
self.assertEqual(response.status_code, 303)
475+
self.assertEqual(response.content, b'')
476+
self.assertEqual(response.headers['location'], f"http://localhost:3000/redirect?state={state.replace('=', '%3D')}&code={code}")
478477

479478
@pytest.mark.asyncio
480479
async def test_search_with_multiple_emails(self):

tests/Flask/test_flask.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import json
1616
from typing import Any, Dict, Union
17+
from base64 import b64encode
1718

1819
import pytest
1920
from _pytest.fixtures import fixture
@@ -477,17 +478,15 @@ def test_thirdparty_parsing_works(driver_config_app: Any):
477478
start_st()
478479

479480
test_client = driver_config_app.test_client()
480-
data = {
481-
"state": "afc596274293e1587315c",
482-
"code": "c7685e261f98e4b3b94e34b3a69ff9cf4.0.rvxt.eE8rO__6hGoqaX1B7ODPmA",
483-
}
484-
response = test_client.post("/auth/callback/apple", data=data)
481+
state = b64encode(json.dumps({"redirectURI": "http://localhost:3000/redirect" }).encode()).decode()
482+
code = "testing"
485483

486-
assert response.status_code == 200
487-
assert (
488-
response.data
489-
== b'<html><head><script>window.location.replace("http://supertokens.io/auth/callback/apple?state=afc596274293e1587315c&code=c7685e261f98e4b3b94e34b3a69ff9cf4.0.rvxt.eE8rO__6hGoqaX1B7ODPmA");</script></head></html>'
490-
)
484+
data = { "state": state, "code": code}
485+
res = test_client.post("/auth/callback/apple", data=data)
486+
487+
assert res.status_code == 303
488+
assert res.data == b''
489+
assert res.headers["location"] == f"http://localhost:3000/redirect?state={state.replace('=', '%3D')}&code={code}"
491490

492491

493492
from flask.wrappers import Response

0 commit comments

Comments
 (0)