From c3f79c53f048a2c0c2fa6de8174ce49f615b1be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sta=C5=9Bczak?= Date: Fri, 22 Dec 2023 18:28:57 +0100 Subject: [PATCH] Fix regression after renaming `*algorithm` variables Fixes #75. * * * After 6592be266def74276550ed63894f102536cecf1b (https://github.com/apptension/onetimepass/pull/68) , if URI contains the `algorithm` optional parameter, e.g. ``` otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30 ``` the application will raise an error: ``` [2023-12-21 09:42:02,769] DEBUG:otp:352: 1 validation error for Uri schema_ -> TOTPUriSchema -> parameters -> algorithm extra fields not permitted (type=value_error.extra) ``` --- onetimepass/otpauth/schemas.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/onetimepass/otpauth/schemas.py b/onetimepass/otpauth/schemas.py index 302424d..df808d4 100644 --- a/onetimepass/otpauth/schemas.py +++ b/onetimepass/otpauth/schemas.py @@ -5,6 +5,7 @@ from pydantic import BaseModel from pydantic import constr from pydantic import Extra +from pydantic import Field from pydantic import validator from .errors import IllegalColon @@ -15,7 +16,9 @@ class BaseUriParameters(BaseModel, extra=Extra.forbid): secret: str issuer: str | None - hash_algorithm: Literal["SHA1", "SHA256", "SHA512"] = "SHA1" + hash_algorithm: Literal["SHA1", "SHA256", "SHA512"] = Field( + "SHA1", alias="algorithm" + ) digits: int @validator("issuer")