feature/redis #14
+3
-1
@@ -49,7 +49,9 @@ omit = [
|
||||
"*/database/*",
|
||||
"*/errors/*",
|
||||
"__init__.py",
|
||||
"*/docker/*"
|
||||
"*/docker/*",
|
||||
"*/rate_limit.py",
|
||||
"*/logger.py"
|
||||
]
|
||||
|
||||
[tool.coverage.report]
|
||||
|
||||
Vendored
+1
-5
@@ -1,5 +1,3 @@
|
||||
from fastapi import Request
|
||||
|
||||
from src.cache.redis_client import redis_client
|
||||
from src.errors.http_errors.errors import Errors
|
||||
|
||||
@@ -23,6 +21,4 @@ class RateLimit:
|
||||
await self.rate_limit(client_ip)
|
||||
|
||||
|
||||
rate_limiter=RateLimit()
|
||||
|
||||
|
||||
rate_limiter=RateLimit()
|
||||
+39
-3
@@ -4,7 +4,7 @@ import requests_async
|
||||
from httpx import HTTPStatusError
|
||||
|
||||
|
||||
class TestAuth:
|
||||
class TestPermissions:
|
||||
|
||||
async def test_get_access_token_positive(self, target_url:str)->None:
|
||||
|
||||
@@ -15,7 +15,6 @@ class TestAuth:
|
||||
|
||||
assert exc_info.value.response.status_code != 403
|
||||
assert exc_info.value.response.status_code != 401
|
||||
assert exc_info.value.response.status_code != 429
|
||||
|
||||
async def test_get_refresh_token_positive(self, target_url:str)->None:
|
||||
|
||||
@@ -26,7 +25,7 @@ class TestAuth:
|
||||
assert exc_info.value.response.status_code != 403
|
||||
assert exc_info.value.response.status_code != 401
|
||||
|
||||
async def test_get_root_positive(self, target_url:str)->None:
|
||||
async def test_get_root_unauthorized(self, target_url:str)->None:
|
||||
|
||||
with allure.step("get_root"), pytest.raises(HTTPStatusError) as exc_info:
|
||||
|
||||
@@ -45,4 +44,41 @@ class TestAuth:
|
||||
response.raise_for_status()
|
||||
assert exc_info.value.response.status_code != 403
|
||||
assert exc_info.value.response.status_code != 401
|
||||
|
||||
|
||||
class TestRedis:
|
||||
|
||||
@pytest.mark.parametrize("wrong_user_data, expected_status",[
|
||||
pytest.param({"username":"Wrong_user", "password":"Wrong_password"},429,id="Wrong_user_creds")
|
||||
])
|
||||
async def test_rate_limit_positive(self, wrong_user_data:dict, target_url:str, expected_status:int):
|
||||
|
||||
with allure.step("logging with invalid creds"):
|
||||
|
||||
for i in range(5):
|
||||
with pytest.raises(HTTPStatusError) as exc_info:
|
||||
response = await requests_async.post(target_url + "/protected/token", data=wrong_user_data)
|
||||
response.raise_for_status()
|
||||
assert exc_info.value.response.status_code == 401, f"Attempt {i+1} should be 401"
|
||||
|
||||
with allure.step("verify rate_limit works"),pytest.raises(HTTPStatusError) as exc_info:
|
||||
response = await requests_async.post(target_url + "/protected/token", data=wrong_user_data)
|
||||
response.raise_for_status()
|
||||
assert exc_info.value.response.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_user_fixture", [([], [])], indirect=True)
|
||||
async def test_get_logout_revoke_positive(self,test_user_fixture, target_url:str)->None:
|
||||
|
||||
session=test_user_fixture[0]
|
||||
|
||||
with allure.step("logout"):
|
||||
|
||||
response = await session.get(f"{target_url}/protected/logout")
|
||||
response.raise_for_status()
|
||||
|
||||
with allure.step("verify token is revoked"), pytest.raises(HTTPStatusError) as exc_info:
|
||||
response = await session.get(f"{target_url}/protected")
|
||||
response.raise_for_status()
|
||||
assert exc_info.value.response.status_code==429
|
||||
|
||||
Reference in New Issue
Block a user