Skip to content

Commit 32f20f2

Browse files
feat(infra): Add WAF implementation (#5213) (#5217)
* feat(infra): Add WAF implementation * Addressing greptile comments * Additional removal of unnecessary code
1 parent 3dd2709 commit 32f20f2

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

backend/onyx/auth/users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def verify_email_domain(email: str) -> None:
241241
status_code=status.HTTP_400_BAD_REQUEST,
242242
detail="Email is not valid",
243243
)
244-
domain = email.split("@")[-1]
244+
domain = email.split("@")[-1].lower()
245245
if domain not in VALID_EMAIL_DOMAINS:
246246
raise HTTPException(
247247
status_code=status.HTTP_400_BAD_REQUEST,

backend/onyx/configs/app_configs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@
108108
os.environ.get("VALID_EMAIL_DOMAINS", "") or _VALID_EMAIL_DOMAIN
109109
)
110110
VALID_EMAIL_DOMAINS = (
111-
[domain.strip() for domain in _VALID_EMAIL_DOMAINS_STR.split(",")]
111+
[
112+
domain.strip().lower()
113+
for domain in _VALID_EMAIL_DOMAINS_STR.split(",")
114+
if domain.strip()
115+
]
112116
if _VALID_EMAIL_DOMAINS_STR
113117
else []
114118
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
from fastapi import HTTPException
3+
4+
import onyx.auth.users as users
5+
from onyx.auth.users import verify_email_domain
6+
7+
8+
def test_verify_email_domain_allows_case_insensitive_match(
9+
monkeypatch: pytest.MonkeyPatch,
10+
) -> None:
11+
# Configure whitelist to lowercase while email has uppercase domain
12+
monkeypatch.setattr(users, "VALID_EMAIL_DOMAINS", ["example.com"], raising=False)
13+
14+
# Should not raise
15+
verify_email_domain("User@EXAMPLE.COM")
16+
17+
18+
def test_verify_email_domain_rejects_non_whitelisted_domain(
19+
monkeypatch: pytest.MonkeyPatch,
20+
) -> None:
21+
monkeypatch.setattr(users, "VALID_EMAIL_DOMAINS", ["example.com"], raising=False)
22+
23+
with pytest.raises(HTTPException) as exc:
24+
verify_email_domain("user@another.com")
25+
assert exc.value.status_code == 400
26+
assert "Email domain is not valid" in exc.value.detail
27+
28+
29+
def test_verify_email_domain_invalid_email_format(
30+
monkeypatch: pytest.MonkeyPatch,
31+
) -> None:
32+
monkeypatch.setattr(users, "VALID_EMAIL_DOMAINS", ["example.com"], raising=False)
33+
34+
with pytest.raises(HTTPException) as exc:
35+
verify_email_domain("userexample.com") # missing '@'
36+
assert exc.value.status_code == 400
37+
assert "Email is not valid" in exc.value.detail

0 commit comments

Comments
 (0)