Skip to content

Commit

Permalink
Fix static checks (#5520)
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-torres-marroquin authored Nov 20, 2024
1 parent a6e0c86 commit 0a7a2b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/fides/api/schemas/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from fides.api.schemas.oauth import AccessToken



class PrivacyRequestReviewer(FidesSchema):
"""Data we can expose via the PrivacyRequest.reviewer relation"""

Expand Down Expand Up @@ -38,13 +37,13 @@ def validate_username(cls, username: str) -> str:

@field_validator("password")
@classmethod
def validate_password(cls, password: str) -> str:
def validate_password_field(cls, password: str) -> str:
"""Add some password requirements"""
decoded_password = decode_password(password)
return UserCreate._validate_password(decoded_password)
return UserCreate.validate_password(decoded_password)

@staticmethod
def _validate_password(password: str) -> str:
def validate_password(password: str) -> str:
"""
Validate password requirements.
Raises:
Expand All @@ -54,7 +53,7 @@ def _validate_password(password: str) -> str:
"""
if len(password) < 8:
raise ValueError("Password must have at least eight characters.")
if re.search("[\d]", password) is None:
if re.search(r"[\d]", password) is None:
raise ValueError("Password must have at least one number.")
if re.search("[A-Z]", password) is None:
raise ValueError("Password must have at least one capital letter.")
Expand Down Expand Up @@ -118,7 +117,7 @@ class UserPasswordReset(FidesSchema):
def validate_new_password(cls, password: str) -> str:
"""Add some password requirements"""
decoded_password = decode_password(password)
return UserCreate._validate_password(decoded_password)
return UserCreate.validate_password(decoded_password)


class UserForcePasswordReset(FidesSchema):
Expand All @@ -131,7 +130,7 @@ class UserForcePasswordReset(FidesSchema):
def validate_new_password(cls, password: str) -> str:
"""Add some password requirements"""
decoded_password = decode_password(password)
return UserCreate._validate_password(decoded_password)
return UserCreate.validate_password(decoded_password)


class UserUpdate(FidesSchema):
Expand Down
15 changes: 12 additions & 3 deletions tests/ops/api/v1/endpoints/test_user_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,18 @@ def test_force_update_different_user_password(
[
("short", "Value error, Password must have at least eight characters."),
("longerpassword", "Value error, Password must have at least one number."),
("longer55password", "Value error, Password must have at least one capital letter."),
("LONGER55PASSWORD", "Value error, Password must have at least one lowercase letter."),
("LoNgEr55paSSworD", "Value error, Password must have at least one symbol."),
(
"longer55password",
"Value error, Password must have at least one capital letter.",
),
(
"LONGER55PASSWORD",
"Value error, Password must have at least one lowercase letter.",
),
(
"LoNgEr55paSSworD",
"Value error, Password must have at least one symbol.",
),
],
)
def test_force_update_bad_password(
Expand Down

0 comments on commit 0a7a2b2

Please sign in to comment.