Skip to content

Commit 239cb59

Browse files
eastandwestwindthabofletcher
authored andcommitted
Fix failing cypress tests on main (#6534)
1 parent 792b5cd commit 239cb59

File tree

2 files changed

+5
-51
lines changed

2 files changed

+5
-51
lines changed

src/fides/config/security_settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,13 @@ def assemble_root_access_token(
222222
def validate_rate_limit_client_ip_header(
223223
cls,
224224
v: str,
225-
) -> str:
225+
) -> Optional[str]:
226226
"""Validate supported `rate_limit_client_ip_header`"""
227227
insecure_headers = ["x-forwarded-for"]
228228

229+
if not v:
230+
return None
231+
229232
if v.lower() in insecure_headers:
230233
raise ValueError(
231234
"The rate_limit_client_ip_header cannot be set to a header that is not secure."

tests/ops/api/test_ratelimit.py

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,6 @@
1-
from typing import Generator
2-
31
import pytest
4-
from fastapi.testclient import TestClient
5-
from slowapi.extension import Limiter
6-
from slowapi.util import get_remote_address
7-
8-
from fides.api.main import app
9-
from fides.common.api.v1.urn_registry import HEALTH
10-
from fides.config import CONFIG, SecuritySettings
11-
12-
LIMIT = 2
13-
14-
15-
@pytest.fixture(scope="function")
16-
def api_client_for_rate_limiting() -> Generator:
17-
"""
18-
Return a client used to make API requests ratelimited at 2/minute.
19-
"""
20-
app.state.limiter = Limiter(
21-
default_limits=[f"{LIMIT}/minute"],
22-
headers_enabled=True,
23-
key_prefix=CONFIG.security.rate_limit_prefix,
24-
key_func=get_remote_address,
25-
retry_after="http-date",
26-
)
27-
with TestClient(app) as c:
28-
yield c
29-
app.state.limiter = Limiter(
30-
default_limits=[CONFIG.security.request_rate_limit],
31-
headers_enabled=True,
32-
key_prefix=CONFIG.security.rate_limit_prefix,
33-
key_func=get_remote_address,
34-
retry_after="http-date",
35-
)
36-
37-
38-
def test_requests_rate_limited(api_client_for_rate_limiting):
39-
"""
40-
Asserts that incremental HTTP requests above the ratelimit threshold are
41-
rebuffed from the API with a 429 response.
42-
43-
A theoretical failure condition exists in this test should the container
44-
running it not be able to execute 100 requests against the client in a
45-
one minute period.
46-
"""
47-
for _ in range(0, LIMIT):
48-
response = api_client_for_rate_limiting.get(HEALTH)
49-
assert response.status_code == 200
502

51-
response = api_client_for_rate_limiting.get(HEALTH)
52-
assert response.status_code == 429
3+
from fides.config import SecuritySettings
534

545

556
def test_rate_limit_validation():

0 commit comments

Comments
 (0)