|
1 | 1 | from unittest.mock import patch |
2 | 2 |
|
3 | 3 | from fastapi.testclient import TestClient |
| 4 | +import jwt |
4 | 5 | from pwdlib.hashers.bcrypt import BcryptHasher |
5 | 6 | from sqlmodel import Session |
6 | 7 |
|
| 8 | +from app.core import security |
7 | 9 | from app.core.config import settings |
8 | 10 | from app.core.security import get_password_hash, verify_password |
9 | 11 | from app.crud import create_user |
@@ -126,6 +128,27 @@ def test_reset_password_invalid_token( |
126 | 128 | assert response["detail"] == "Invalid token" |
127 | 129 |
|
128 | 130 |
|
| 131 | +def test_reset_password_token_without_subject_claim( |
| 132 | + client: TestClient, superuser_token_headers: dict[str, str] |
| 133 | +) -> None: |
| 134 | + token_without_sub = jwt.encode( |
| 135 | + {"nbf": 0, "exp": 4102444800}, |
| 136 | + settings.SECRET_KEY, |
| 137 | + algorithm=security.ALGORITHM, |
| 138 | + ) |
| 139 | + data = {"new_password": "changethis", "token": token_without_sub} |
| 140 | + r = client.post( |
| 141 | + f"{settings.API_V1_STR}/reset-password/", |
| 142 | + headers=superuser_token_headers, |
| 143 | + json=data, |
| 144 | + ) |
| 145 | + response = r.json() |
| 146 | + |
| 147 | + assert "detail" in response |
| 148 | + assert r.status_code == 400 |
| 149 | + assert response["detail"] == "Invalid token" |
| 150 | + |
| 151 | + |
129 | 152 | def test_login_with_bcrypt_password_upgrades_to_argon2( |
130 | 153 | client: TestClient, db: Session |
131 | 154 | ) -> None: |
|
0 commit comments