Skip to content

Commit

Permalink
fixes more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Oct 1, 2024
1 parent d31a8fb commit 37b41d4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ uvicorn==0.18.2
Werkzeug==2.0.3
wrapt==1.13.3
zipp==3.7.0
pyotp==2.9.0
12 changes: 6 additions & 6 deletions supertokens_python/auth_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,19 +452,19 @@ class OkFirstFactorResponse:


class OkSecondFactorLinkedResponse:
status: Literal["OK"]
is_first_factor: Literal[False]
input_user_already_linked_to_session_user: Literal[True]
status: Literal["OK"] = "OK"
is_first_factor: Literal[False] = False
input_user_already_linked_to_session_user: Literal[True] = True
session_user: User

def __init__(self, session_user: User):
self.session_user = session_user


class OkSecondFactorNotLinkedResponse:
status: Literal["OK"]
is_first_factor: Literal[False]
input_user_already_linked_to_session_user: Literal[False]
status: Literal["OK"] = "OK"
is_first_factor: Literal[False] = False
input_user_already_linked_to_session_user: Literal[False] = False
session_user: User
linking_to_session_user_requires_verification: bool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ def remove_from_payload_by_merge_(
def get_value_from_payload(
self, payload: JSONObject, user_context: Optional[Dict[str, Any]] = None
) -> Optional[MFAClaimValue]:
return payload.get(self.key)
value = payload.get(self.key)
if value is None:
return None
return MFAClaimValue(c=value["c"], v=value["v"])


MultiFactorAuthClaim = MultiFactorAuthClaimClass()
3 changes: 2 additions & 1 deletion supertokens_python/recipe/totp/recipe_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ async def create_device(

data = {
"userId": user_id,
"deviceName": device_name,
"skew": skew if skew is not None else self.config.default_skew,
"period": period if period is not None else self.config.default_period,
}
if device_name is not None:
data["deviceName"] = device_name
response = await self.querier.send_post_request(
NormalisedURLPath("/recipe/totp/device"),
data,
Expand Down
29 changes: 28 additions & 1 deletion tests/auth-react/flask-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get_website_domain():

os.environ.setdefault("SUPERTOKENS_ENV", "testing")

latest_url_with_token = None
latest_url_with_token = ""

code_store: Dict[str, List[Dict[str, Any]]] = {}
accountlinking_config: Dict[str, Any] = {}
Expand Down Expand Up @@ -1286,6 +1286,8 @@ def before_each():
global enabled_providers
global enabled_recipes
global mfa_info
global latest_url_with_token
latest_url_with_token = ""
code_store = dict()
accountlinking_config = {}
enabled_providers = None
Expand Down Expand Up @@ -1319,6 +1321,16 @@ def test_set_account_linking_config():
return "", 200


@app.route("/setMFAInfo", methods=["POST"]) # type: ignore
def set_mfa_info():
global mfa_info
body = request.get_json()
if body is None:
return jsonify({"error": "Invalid request body"}), 400
mfa_info = body
return jsonify({"status": "OK"})


@app.route("/test/setEnabledRecipes", methods=["POST"]) # type: ignore
def test_set_enabled_recipes():
global enabled_recipes
Expand All @@ -1332,6 +1344,21 @@ def test_set_enabled_recipes():
return "", 200


@app.route("/test/getTOTPCode", methods=["POST"]) # type: ignore
def test_get_totp_code():
from pyotp import TOTP

body = request.get_json()
if body is None or "secret" not in body:
return jsonify({"error": "Invalid request body"}), 400

secret = body["secret"]
totp = TOTP(secret, digits=6, interval=1)
code = totp.now()

return jsonify({"totp": code})


@app.get("/test/getDevice") # type: ignore
def test_get_device():
global code_store
Expand Down

0 comments on commit 37b41d4

Please sign in to comment.