fixes
This commit is contained in:
@@ -9,8 +9,8 @@ from jose import jwt
|
||||
from pydantic import ValidationError
|
||||
|
||||
from src.models.configs_read.env import env_settings
|
||||
from src.service.auth.auth import CurrentUser
|
||||
from src.service.auth.jwt import Hashes, Jwt
|
||||
from src.service.auth.auth import CurrentUserService
|
||||
from src.service.auth.jwt import HashService, JwtService
|
||||
|
||||
|
||||
@pytest.mark.integra
|
||||
@@ -19,7 +19,7 @@ class TestAuth:
|
||||
@pytest.mark.parametrize("user_data",[
|
||||
pytest.param(SimpleNamespace(first_name="test",last_name="test",middle_name="test",email="d@d.d",direct_permissions=[],group=[],status=True), id="correct_data")
|
||||
])
|
||||
def test_get_current_user_positive(self,current_user_service:CurrentUser, jwt_service:Jwt, monkeypatch, user_data:SimpleNamespace)->None:
|
||||
def test_get_current_user_positive(self,current_user_service:CurrentUserService, jwt_service:JwtService, monkeypatch, user_data:SimpleNamespace)->None:
|
||||
|
||||
with allure.step("create token"):
|
||||
|
||||
@@ -46,7 +46,7 @@ class TestAuth:
|
||||
pytest.param(SimpleNamespace(first_name="test",last_name="test",middle_name="test",email="d@d.d",direct_permissions=[],group=[],status=True),1234, HTTPException, id="wrong_id"),
|
||||
pytest.param(SimpleNamespace(status=True),uuid4(), ValidationError,id="empty_model_data")
|
||||
])
|
||||
def test_get_current_user_negative(self,current_user_service:CurrentUser, jwt_service:Jwt, monkeypatch, user_data:SimpleNamespace, expected_exception, uuid)->None:
|
||||
def test_get_current_user_negative(self,current_user_service:CurrentUserService, jwt_service:JwtService, monkeypatch, user_data:SimpleNamespace, expected_exception, uuid)->None:
|
||||
|
||||
with allure.step("create token"):
|
||||
|
||||
@@ -64,7 +64,7 @@ class TestAuth:
|
||||
@pytest.mark.parametrize("user_data, form_data_email,form_data_password",[
|
||||
pytest.param(SimpleNamespace(id=uuid4(),hashed_password="1234", first_name="test",last_name="test",middle_name="test",email="d@d.d",direct_permissions=[],group=[],status=True), "d@d.d", "1234", id="correct_data"),
|
||||
])
|
||||
def test_login_positive(self, jwt_service:Jwt,current_user_service:CurrentUser, monkeypatch, user_data:SimpleNamespace, hash_service:Hashes, form_data_email:str, form_data_password:str, requests)->None:
|
||||
def test_login_positive(self, jwt_service:JwtService,current_user_service:CurrentUserService, monkeypatch, user_data:SimpleNamespace, hash_service:HashService, form_data_email:str, form_data_password:str, requests)->None:
|
||||
|
||||
with allure.step("patching db call functions"):
|
||||
|
||||
@@ -90,7 +90,7 @@ class TestAuth:
|
||||
pytest.param(SimpleNamespace(id=uuid4(),hashed_password="1234", first_name="test",last_name="test",middle_name="test",email="d@d.d",direct_permissions=[],group=[],status=False), "d@d.d", "1234",HTTPException, id="false_status"),
|
||||
pytest.param(SimpleNamespace(id=1234,hashed_password="1234", first_name="test",last_name="test",middle_name="test",email="d@d.d",direct_permissions=[],group=[],status=True), "d@d.d", "1234",ValidationError, id="wrong_id"),
|
||||
])
|
||||
def test_login_negative(self, current_user_service:CurrentUser, user_data:SimpleNamespace, jwt_service:Jwt, monkeypatch, requests, hash_service:Hashes, form_data_email:str, form_data_password:str, expected_exception):
|
||||
def test_login_negative(self, current_user_service:CurrentUserService, user_data:SimpleNamespace, jwt_service:JwtService, monkeypatch, requests, hash_service:HashService, form_data_email:str, form_data_password:str, expected_exception):
|
||||
|
||||
with allure.step("patching db call functions"):
|
||||
|
||||
@@ -107,7 +107,7 @@ class TestAuth:
|
||||
|
||||
|
||||
|
||||
def test_logout_positive(self, jwt_service:Jwt, monkeypatch, current_user_service:CurrentUser)->None:
|
||||
def test_logout_positive(self, jwt_service:JwtService, monkeypatch, current_user_service:CurrentUserService)->None:
|
||||
|
||||
with allure.step("create fake refresh token"):
|
||||
|
||||
@@ -115,7 +115,6 @@ class TestAuth:
|
||||
|
||||
with allure.step("patching db call functions"):
|
||||
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions, "get_token_by_id", lambda jti: "test")
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions, "logout", lambda jti: True )
|
||||
|
||||
with allure.step("test logout with fake data"):
|
||||
@@ -126,14 +125,13 @@ class TestAuth:
|
||||
@pytest.mark.parametrize("jti,db_result, expected_exception",[
|
||||
pytest.param(None, True, HTTPException, id="jti_none"),
|
||||
pytest.param(1234, True, HTTPException, id="jti_int"),
|
||||
pytest.param(str(uuid4()), None, HTTPException, id="db_result_none"),
|
||||
pytest.param(str(uuid4()), False, HTTPException, id="db_result_none"),
|
||||
])
|
||||
def test_logout_negative(self, jwt_service:Jwt, monkeypatch, current_user_service:CurrentUser, expected_exception, jti, db_result)->None:
|
||||
def test_logout_negative(self, jwt_service:JwtService, monkeypatch, current_user_service:CurrentUserService, expected_exception, jti, db_result)->None:
|
||||
|
||||
with allure.step("patching db call functions"):
|
||||
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions, "get_token_by_id", lambda jti: db_result)
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions, "logout", lambda jti: True )
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions, "logout", lambda jti: db_result )
|
||||
|
||||
def fake_create_refresh_token(data:dict)->str:
|
||||
return jwt.encode(data, env_settings.SECRET_KEY, env_settings.ALGORITHM)
|
||||
@@ -153,7 +151,7 @@ class TestAuth:
|
||||
@pytest.mark.parametrize("db_result_token, user_data_result_db", [
|
||||
pytest.param(SimpleNamespace(is_revoked=False, expires_at=datetime.now(UTC)+timedelta(days=15)),SimpleNamespace(status=True), id="correct_data")
|
||||
])
|
||||
def test_refresh_token_positive(self, monkeypatch, current_user_service:CurrentUser, db_result_token, requests:Request, jwt_service:Jwt,user_data_result_db )->None:
|
||||
def test_refresh_token_positive(self, monkeypatch, current_user_service:CurrentUserService, db_result_token, requests:Request, jwt_service:JwtService,user_data_result_db )->None:
|
||||
|
||||
with allure.step("patching db call functions"):
|
||||
|
||||
@@ -194,13 +192,12 @@ class TestAuth:
|
||||
pytest.param(SimpleNamespace(is_revoked=False, user_id="123",expires_at=datetime.now(UTC)+timedelta(days=15)),None,{"sub":str(uuid4()), "jti":str(uuid4()), "token_type":"refresh", "exp":datetime.now(UTC)+timedelta(days=45)}, HTTPException,id="user_missing"),
|
||||
pytest.param(SimpleNamespace(is_revoked=False,user_id="123", expires_at=datetime.now(UTC)-timedelta(days=15)),SimpleNamespace(status=True),{"sub":str(uuid4()), "jti":str(uuid4()), "token_type":"refresh", "exp":datetime.now(UTC)+timedelta(days=45)}, HTTPException,id="wrong_exp")
|
||||
])
|
||||
def test_refresh_token_negative(self, monkeypatch, current_user_service:CurrentUser, db_result_token, requests, jwt_service:Jwt,user_data_result_db, expected_exception, fake_token_data)->None:
|
||||
def test_refresh_token_negative(self, monkeypatch, current_user_service:CurrentUserService, db_result_token, requests, jwt_service:JwtService,user_data_result_db, expected_exception, fake_token_data)->None:
|
||||
with allure.step("patching db call functions"):
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions,"get_token_by_id", lambda jti: db_result_token)
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions, "revoke_all", lambda user_id:True)
|
||||
monkeypatch.setattr(current_user_service.crud_db_actions, "get_user_by_id", lambda user:user_data_result_db)
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions, "create_token", lambda new_token_record:True)
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions,"update_token", lambda old_jti, new_jti: True )
|
||||
monkeypatch.setattr(current_user_service.jwt_db_actions, "create_and_update_token", lambda old_jti, new_jti, new_token_record:True)
|
||||
|
||||
fake_request = requests
|
||||
|
||||
|
||||
Reference in New Issue
Block a user