Merge pull request 'bug(password-validation):fixed the regex for rejecting emoji as special character in password' (#19) from password-validation into main

Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-api/pulls/19
Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
Amit Salunke 2026-10-26 04:38:01 +00:00
commit 895342a8ba
4 changed files with 17 additions and 7 deletions

View File

@ -3,15 +3,15 @@
FastAPI Backend Platform for Acupedia Learning Content, Subscriptions, Pricing, and Payments. FastAPI Backend Platform for Acupedia Learning Content, Subscriptions, Pricing, and Payments.
<!-- START_TEST_STATUS --> <!-- START_TEST_STATUS -->
[![Tests](https://img.shields.io/badge/tests-93%20passed-brightgreen)](#test-status--coverage) [![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](#test-status--coverage) [![Tests](https://img.shields.io/badge/tests-6%20failed-red)](#test-status--coverage) [![Coverage](https://img.shields.io/badge/coverage-73%25-yellow)](#test-status--coverage)
| Metric | Status | | Metric | Status |
| :--- | :--- | | :--- | :--- |
| **Test Suite** | `PASSED` | | **Test Suite** | `FAILED` |
| **Tests Passing** | `93` | | **Tests Passing** | `92` |
| **Tests Failing** | `0` | | **Tests Failing** | `6` |
| **Core Coverage** | `100%` | | **Core Coverage** | `73%` |
| **Last Updated** | `2026-10-19 06:13:19 UTC` | | **Last Updated** | `2026-10-22 06:02:56 UTC` |
<!-- END_TEST_STATUS --> <!-- END_TEST_STATUS -->
--- ---

View File

@ -7,6 +7,7 @@ import json
import os import os
import re import re
import secrets import secrets
import string
import time import time
from typing import Any from typing import Any
@ -56,7 +57,7 @@ def validate_password_strength(password: str) -> None:
raise WeakPasswordError( raise WeakPasswordError(
"Password must contain at least one number." "Password must contain at least one number."
) )
if not any(not c.isalnum() and not c.isspace() for c in password): if not any(c in string.punctuation for c in password):
raise WeakPasswordError( raise WeakPasswordError(
"Password must contain at least one special character." "Password must contain at least one special character."
) )

View File

@ -28,6 +28,11 @@ class TestPasswordValidation(unittest.TestCase):
validate_password_strength("NoSpecial123") validate_password_strength("NoSpecial123")
self.assertIn("special character", str(ctx.exception)) self.assertIn("special character", str(ctx.exception))
def test_emoji_instead_of_special_char_fails(self):
with self.assertRaises(WeakPasswordError) as ctx:
validate_password_strength("NoSpecial123😀")
self.assertIn("special character", str(ctx.exception))
def test_valid_passwords_pass(self): def test_valid_passwords_pass(self):
# Must not raise any exceptions # Must not raise any exceptions
validate_password_strength("Siraj@12345") validate_password_strength("Siraj@12345")

View File

@ -68,6 +68,10 @@ class TestPasswordValidationAndHashing:
with pytest.raises(WeakPasswordError, match="special character"): with pytest.raises(WeakPasswordError, match="special character"):
validate_password_strength("Password 12345") validate_password_strength("Password 12345")
def test_password_strength_emoji_instead_of_special_char_fails(self) -> None:
with pytest.raises(WeakPasswordError, match="special character"):
validate_password_strength("Password😀12345")
def test_hash_and_verify_password_lifecycle(self) -> None: def test_hash_and_verify_password_lifecycle(self) -> None:
raw_pw = "SuperSecure#2026" raw_pw = "SuperSecure#2026"
hashed = hash_password(raw_pw) hashed = hash_password(raw_pw)