From 89fad505290727e21e0582388e0bfb51e3678acc Mon Sep 17 00:00:00 2001 From: MrMeeb Date: Tue, 4 Mar 2025 12:00:09 +0000 Subject: [PATCH] 4.66.1 --- app/pyproject.toml | 4 ++-- app/tests/api/test_new_custom_alias.py | 6 ++---- app/tests/api/test_new_random_alias.py | 6 +++--- app/tests/dashboard/test_custom_alias.py | 11 ++++++++--- app/tests/dashboard/test_index.py | 6 +++--- app/tests/test_extensions.py | 8 +------- app/tests/utils.py | 8 ++++++++ app/uv.lock | 16 ++++++++-------- 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/app/pyproject.toml b/app/pyproject.toml index cbd3141..abbe718 100644 --- a/app/pyproject.toml +++ b/app/pyproject.toml @@ -58,7 +58,7 @@ dependencies = [ #"pyspf @ git+https://github.com/sdgathman/pyspf.git@665a6df079485a9824be0829e7d71088453db7f6", "pyspf ~= 2.0.14", - "Flask-Limiter == 1.4", + "Flask-Limiter == 1.5", "memory_profiler ~= 0.57.0", "gevent ~= 24.11.1", "email-validator ~= 2.2.0", @@ -75,7 +75,7 @@ dependencies = [ "MarkupSafe~=1.1.1", "cryptography ~= 37.0.1", "SQLAlchemy ~= 1.3.24", - "redis==4.6.0", + "redis==5.2.1", "newrelic-telemetry-sdk ~= 0.5.0", "aiospamc == 0.10", "itsdangerous ~= 1.1.0", diff --git a/app/tests/api/test_new_custom_alias.py b/app/tests/api/test_new_custom_alias.py index b2842a3..7b2e482 100644 --- a/app/tests/api/test_new_custom_alias.py +++ b/app/tests/api/test_new_custom_alias.py @@ -1,5 +1,3 @@ -from flask import g - from app import config from app.alias_suffix import signer from app.alias_utils import delete_alias @@ -7,7 +5,7 @@ from app.config import EMAIL_DOMAIN, MAX_NB_EMAIL_FREE_PLAN from app.db import Session from app.models import Alias, CustomDomain, Mailbox, AliasUsedOn from app.utils import random_word -from tests.utils import login, random_domain, random_token +from tests.utils import fix_rate_limit_after_request, login, random_domain, random_token def test_v2(flask_client): @@ -276,7 +274,7 @@ def test_too_many_requests(flask_client): # to make flask-limiter work with unit test # https://github.com/alisaifee/flask-limiter/issues/147#issuecomment-642683820 - g._rate_limiting_complete = False + fix_rate_limit_after_request() else: # last request assert r.status_code == 429 diff --git a/app/tests/api/test_new_random_alias.py b/app/tests/api/test_new_random_alias.py index a2d687f..30dec7a 100644 --- a/app/tests/api/test_new_random_alias.py +++ b/app/tests/api/test_new_random_alias.py @@ -1,12 +1,12 @@ import uuid -from flask import url_for, g +from flask import url_for from app import config from app.config import EMAIL_DOMAIN, MAX_NB_EMAIL_FREE_PLAN from app.db import Session from app.models import Alias, CustomDomain, AliasUsedOn -from tests.utils import login, random_domain +from tests.utils import fix_rate_limit_after_request, login, random_domain def test_with_hostname(flask_client): @@ -133,7 +133,7 @@ def test_too_many_requests(flask_client): ) # to make flask-limiter work with unit test # https://github.com/alisaifee/flask-limiter/issues/147#issuecomment-642683820 - g._rate_limiting_complete = False + fix_rate_limit_after_request() else: # last request assert r.status_code == 429 diff --git a/app/tests/dashboard/test_custom_alias.py b/app/tests/dashboard/test_custom_alias.py index 636e609..73b405a 100644 --- a/app/tests/dashboard/test_custom_alias.py +++ b/app/tests/dashboard/test_custom_alias.py @@ -1,6 +1,6 @@ from random import random -from flask import url_for, g +from flask import url_for from app import config from app.alias_suffix import ( @@ -22,7 +22,12 @@ from app.models import ( DailyMetric, ) from app.utils import random_word -from tests.utils import login, random_domain, create_new_user +from tests.utils import ( + fix_rate_limit_after_request, + login, + random_domain, + create_new_user, +) def test_add_alias_success(flask_client): @@ -388,7 +393,7 @@ def test_too_many_requests(flask_client): # to make flask-limiter work with unit test # https://github.com/alisaifee/flask-limiter/issues/147#issuecomment-642683820 - g._rate_limiting_complete = False + fix_rate_limit_after_request() else: # last request assert r.status_code == 429 diff --git a/app/tests/dashboard/test_index.py b/app/tests/dashboard/test_index.py index 7f20156..58197fc 100644 --- a/app/tests/dashboard/test_index.py +++ b/app/tests/dashboard/test_index.py @@ -1,10 +1,10 @@ -from flask import url_for, g +from flask import url_for from app import config from app.models import ( Alias, ) -from tests.utils import login +from tests.utils import fix_rate_limit_after_request, login def test_create_random_alias_success(flask_client): @@ -34,7 +34,7 @@ def test_too_many_requests(flask_client): # to make flask-limiter work with unit test # https://github.com/alisaifee/flask-limiter/issues/147#issuecomment-642683820 - g._rate_limiting_complete = False + fix_rate_limit_after_request() else: # last request assert r.status_code == 429 diff --git a/app/tests/test_extensions.py b/app/tests/test_extensions.py index e494301..1c89e34 100644 --- a/app/tests/test_extensions.py +++ b/app/tests/test_extensions.py @@ -1,12 +1,10 @@ from http import HTTPStatus from random import Random -from flask import g - from app import config from app.extensions import limiter from tests.conftest import app as test_app -from tests.utils import login +from tests.utils import fix_rate_limit_after_request, login # IMPORTANT NOTICE # ---------------- @@ -34,10 +32,6 @@ def random_ip() -> str: return ".".join(octets) -def fix_rate_limit_after_request(): - g._rate_limiting_complete = False - - def request_headers(source_ip: str) -> dict: return {"X-Forwarded-For": source_ip} diff --git a/app/tests/utils.py b/app/tests/utils.py index d0a6594..d997cfd 100644 --- a/app/tests/utils.py +++ b/app/tests/utils.py @@ -89,3 +89,11 @@ def load_eml_file( def random_email() -> str: return "{rand}@{rand}.com".format(rand=random_string(20)) + + +def fix_rate_limit_after_request(): + from flask import g + from app.extensions import limiter + + g._rate_limiting_complete = False + setattr(g, "%s_rate_limiting_complete" % limiter._key_prefix, False) diff --git a/app/uv.lock b/app/uv.lock index 6b7e20f..d953542 100644 --- a/app/uv.lock +++ b/app/uv.lock @@ -649,16 +649,16 @@ wheels = [ [[package]] name = "flask-limiter" -version = "1.4" +version = "1.5" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "flask" }, { name = "limits" }, { name = "six" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/5e/ad/44302ae83d88091df2001eb9243df615d064736d45c13c867f1d892159fa/Flask-Limiter-1.4.tar.gz", hash = "sha256:021279c905a1e24f181377ab3be711be7541734b494f4e6db2b8edeba7601e48", size = 95593 } +sdist = { url = "https://files.pythonhosted.org/packages/c1/a0/fd3203cb6186a58a275f2ad01ca715bc42a65876a128cc9931b0ba0f46ed/Flask-Limiter-1.5.tar.gz", hash = "sha256:f5816ebd606d41df39479b4f6f9b770d98d47a0801c8a513198aa436bb4139e7", size = 94964 } wheels = [ - { url = "https://files.pythonhosted.org/packages/1c/66/1bc848a3d37bed2a4c6cea7b7e39b830b2cd848dc7dde759926bb896f8e8/Flask_Limiter-1.4-py3-none-any.whl", hash = "sha256:f8a65a7874f48ff8df2ea5e86d5b85b48fcbae065ebeb5271b317fe68fcfa979", size = 15500 }, + { url = "https://files.pythonhosted.org/packages/e4/ff/f2f922af0058561243f68c47fe90a34532883d29101543c518df5f7f79c8/Flask_Limiter-1.5-py3-none-any.whl", hash = "sha256:7cb3b4350874b2da8d3ff440413d16c4bfd1a26aedf3ad9ea68a1669945ae515", size = 15630 }, ] [[package]] @@ -1719,11 +1719,11 @@ wheels = [ [[package]] name = "redis" -version = "4.6.0" +version = "5.2.1" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/73/88/63d802c2b18dd9eaa5b846cbf18917c6b2882f20efda398cc16a7500b02c/redis-4.6.0.tar.gz", hash = "sha256:585dc516b9eb042a619ef0a39c3d7d55fe81bdb4df09a52c9cdde0d07bf1aa7d", size = 4561721 } +sdist = { url = "https://files.pythonhosted.org/packages/47/da/d283a37303a995cd36f8b92db85135153dc4f7a8e4441aa827721b442cfb/redis-5.2.1.tar.gz", hash = "sha256:16f2e22dff21d5125e8481515e386711a34cbec50f0e44413dd7d9c060a54e0f", size = 4608355 } wheels = [ - { url = "https://files.pythonhosted.org/packages/20/2e/409703d645363352a20c944f5d119bdae3eb3034051a53724a7c5fee12b8/redis-4.6.0-py3-none-any.whl", hash = "sha256:e2b03db868160ee4591de3cb90d40ebb50a90dd302138775937f6a42b7ed183c", size = 241149 }, + { url = "https://files.pythonhosted.org/packages/3c/5f/fa26b9b2672cbe30e07d9a5bdf39cf16e3b80b42916757c5f92bca88e4ba/redis-5.2.1-py3-none-any.whl", hash = "sha256:ee7e1056b9aea0f04c6c2ed59452947f34c4940ee025f5dd83e6a6418b6989e4", size = 261502 }, ] [[package]] @@ -1979,7 +1979,7 @@ requires-dist = [ { name = "flask-cors", specifier = "~=3.0.9" }, { name = "flask-debugtoolbar", specifier = "~=0.11.0" }, { name = "flask-debugtoolbar-sqlalchemy", specifier = "~=0.2.0" }, - { name = "flask-limiter", specifier = "==1.4" }, + { name = "flask-limiter", specifier = "==1.5" }, { name = "flask-login", specifier = "~=0.5.0" }, { name = "flask-migrate", specifier = "~=2.5.3" }, { name = "flask-profiler", specifier = "~=1.8.1" }, @@ -2006,7 +2006,7 @@ requires-dist = [ { name = "pyspf", specifier = "~=2.0.14" }, { name = "python-dotenv", specifier = "~=0.14.0" }, { name = "python-gnupg", specifier = "~=0.4.6" }, - { name = "redis", specifier = "==4.6.0" }, + { name = "redis", specifier = "==5.2.1" }, { name = "requests", specifier = "~=2.25.1" }, { name = "requests-oauthlib", specifier = "~=1.3.0" }, { name = "sentry-sdk", specifier = "~=2.20.0" },