fixes
This commit is contained in:
+11
-11
@@ -6,7 +6,7 @@ from fastapi import HTTPException
|
||||
from jose import jwt
|
||||
|
||||
from src.models.configs_read.env import env_settings
|
||||
from src.service.auth.jwt import Hashes, Jwt
|
||||
from src.service.auth.jwt import HashService, JwtService
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -15,7 +15,7 @@ class TestJwt:
|
||||
@pytest.mark.parametrize("data", [
|
||||
pytest.param({"sub": "123"}, id="full_sub")
|
||||
])
|
||||
def test_access_create_positive(self, jwt_service:Jwt, data:dict)->None:
|
||||
def test_access_create_positive(self, jwt_service:JwtService, data:dict)->None:
|
||||
|
||||
with allure.step("create correct access token"):
|
||||
token = jwt_service.create_access_token(data)
|
||||
@@ -30,7 +30,7 @@ class TestJwt:
|
||||
pytest.param({"sub":""},HTTPException, id="empty_value"),
|
||||
pytest.param({"":""},HTTPException, id="empty_key_value")
|
||||
])
|
||||
def test_access_create_negative(self, jwt_service:Jwt, data:dict, expected_exception)->None:
|
||||
def test_access_create_negative(self, jwt_service:JwtService, data:dict, expected_exception)->None:
|
||||
with allure.step("create invalid access token"),pytest.raises(expected_exception):
|
||||
jwt_service.create_access_token(data)
|
||||
|
||||
@@ -39,7 +39,7 @@ class TestJwt:
|
||||
@pytest.mark.parametrize("data", [
|
||||
pytest.param({"sub": "123"}, id="full_sub")
|
||||
])
|
||||
def test_refresh_create_positive(self, jwt_service:Jwt, data:dict)->None:
|
||||
def test_refresh_create_positive(self, jwt_service:JwtService, data:dict)->None:
|
||||
|
||||
with allure.step("create correct access token"):
|
||||
token = jwt_service.create_refresh_token(data)
|
||||
@@ -54,7 +54,7 @@ class TestJwt:
|
||||
pytest.param({"sub":""},HTTPException, id="empty_value"),
|
||||
pytest.param({"":""},HTTPException, id="empty_key_value")
|
||||
])
|
||||
def test_refresh_create_negative(self, jwt_service:Jwt, data, expected_exception)->None:
|
||||
def test_refresh_create_negative(self, jwt_service:JwtService, data, expected_exception)->None:
|
||||
with allure.step("create invalid access token"), pytest.raises(expected_exception):
|
||||
jwt_service.create_refresh_token(data)
|
||||
|
||||
@@ -62,7 +62,7 @@ class TestJwt:
|
||||
@pytest.mark.parametrize("data", [
|
||||
pytest.param({"sub": "123", "exp":datetime.now(UTC)+timedelta(minutes=15), "token_type":"access"}, id="correct_data"),
|
||||
])
|
||||
def test_jwt_decode_positive(self, data:dict, monkeypatch, jwt_service:Jwt)->None:
|
||||
def test_jwt_decode_positive(self, data:dict, monkeypatch, jwt_service:JwtService)->None:
|
||||
|
||||
with allure.step("patch a create token function"):
|
||||
def fake_create_access_token(data:dict)->str:
|
||||
@@ -83,7 +83,7 @@ class TestJwt:
|
||||
pytest.param({}, HTTPException, id="empty_data"),
|
||||
pytest.param("", AttributeError, id="not_dict_data")
|
||||
])
|
||||
def test_jwt_decode_invalid(self,jwt_service:Jwt, expected_exception, data, monkeypatch)->None:
|
||||
def test_jwt_decode_invalid(self,jwt_service:JwtService, expected_exception, data, monkeypatch)->None:
|
||||
with allure.step("patch a create token function"):
|
||||
def fake_create_access_token(data:dict)->str:
|
||||
return jwt.encode(data, env_settings.SECRET_KEY, env_settings.ALGORITHM)
|
||||
@@ -115,7 +115,7 @@ class TestJwt:
|
||||
@pytest.mark.parametrize("password",[
|
||||
pytest.param("plain_password", id="correct_plain_password")
|
||||
])
|
||||
def test_hash_and_veryfy_positive(self, password:str, hash_service:Hashes)->None:
|
||||
def test_hash_and_veryfy_positive(self, password:str, hash_service:HashService)->None:
|
||||
|
||||
with allure.step("encode password"):
|
||||
encoded_password=hash_service.plain_to_hash(password)
|
||||
@@ -127,7 +127,7 @@ class TestJwt:
|
||||
|
||||
|
||||
|
||||
def test_verify_wrong_password(self, hash_service:Hashes)->None:
|
||||
def test_verify_wrong_password(self, hash_service:HashService)->None:
|
||||
|
||||
with allure.step("encode password"):
|
||||
encoded_password=hash_service.plain_to_hash("plain_password")
|
||||
@@ -136,9 +136,9 @@ class TestJwt:
|
||||
assert hash_service.verify_password("wrong_password", encoded_password) is False
|
||||
|
||||
|
||||
def test_token_to_hash_determistic(self, hash_service:Hashes)->None:
|
||||
def test_token_to_hash_determistic(self, hash_service:HashService)->None:
|
||||
assert hash_service.token_to_hash("abc")==hash_service.token_to_hash("abc")
|
||||
|
||||
def test_token_to_hash_different_input(self, hash_service:Hashes)->None:
|
||||
def test_token_to_hash_different_input(self, hash_service:HashService)->None:
|
||||
assert hash_service.token_to_hash("abc")!=hash_service.token_to_hash("xyz")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user