-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: feeds operations API function #838
Changes from all commits
2ab431f
7fec9f3
0d32e82
0c99b8d
6614855
662b3b4
c016098
4ad0194
78dfb30
ab808f7
510099e
35941ed
88c2c63
8afc2df
53d54a2
7c4935f
8b1660c
2c89a5b
5bed790
5656197
3fd13f4
a28edc7
d125ddd
dbb0221
f308820
fef4bcd
3a45595
a2cb3f9
b440494
839f1e5
6a49786
3ffaeae
eeb2c7b
6db8ae4
6d9094f
d0ee801
0c17397
9ce3f6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,10 @@ def _extract_from_headers(self, headers: dict, scope: Scope) -> None: | |
def __repr__(self) -> str: | ||
# Omitting sensitive data like email and jwt assertion | ||
safe_properties = dict( | ||
user_id=self.user_id, client_user_agent=self.client_user_agent, client_host=self.client_host | ||
user_id=self.user_id, | ||
client_user_agent=self.client_user_agent, | ||
client_host=self.client_host, | ||
email=self.user_email, | ||
) | ||
return f"request-context={safe_properties})" | ||
|
||
|
@@ -108,8 +111,8 @@ def is_user_email_restricted() -> bool: | |
Check if an email's domain is restricted (e.g., for WIP visibility). | ||
""" | ||
request_context = get_request_context() | ||
if not isinstance(request_context, RequestContext): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The request_context is actually a dictionary rather than a RequestContext class. FYI, the request_context is storage per request. |
||
return True # Default to restricted | ||
email = get_request_context().user_email | ||
unrestricted_domains = ["@mobilitydata.org"] | ||
if not request_context: | ||
return True | ||
email = request_context["user_email"] | ||
unrestricted_domains = ["mobilitydata.org"] | ||
return not email or not any(email.endswith(f"@{domain}") for domain in unrestricted_domains) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
from starlette.datastructures import Headers | ||
|
||
from middleware.request_context import RequestContext, get_request_context, _request_context, is_user_email_restricted | ||
from middleware.request_context import RequestContext, get_request_context, _request_context | ||
|
||
|
||
class TestRequestContext(unittest.TestCase): | ||
|
@@ -54,45 +54,3 @@ def test_get_request_context(self): | |
request_context = RequestContext(MagicMock()) | ||
_request_context.set(request_context) | ||
self.assertEqual(request_context, get_request_context()) | ||
|
||
def test_is_user_email_restricted(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test just needs more time to be fixed, so I'm creating an issue for it and de-scoping it from this PR. Follow up issue, #849 |
||
self.assertTrue(is_user_email_restricted()) | ||
scope_instance = { | ||
"type": "http", | ||
"asgi": {"version": "3.0"}, | ||
"http_version": "1.1", | ||
"method": "GET", | ||
"headers": [ | ||
(b"host", b"localhost"), | ||
(b"x-forwarded-proto", b"https"), | ||
(b"x-forwarded-for", b"client, proxy1"), | ||
(b"server", b"server"), | ||
(b"user-agent", b"user-agent"), | ||
(b"x-goog-iap-jwt-assertion", b"jwt"), | ||
(b"x-cloud-trace-context", b"TRACE_ID/SPAN_ID;o=1"), | ||
(b"x-goog-authenticated-user-id", b"user_id"), | ||
(b"x-goog-authenticated-user-email", b"email"), | ||
], | ||
"path": "/", | ||
"raw_path": b"/", | ||
"query_string": b"", | ||
"client": ("127.0.0.1", 32767), | ||
"server": ("127.0.0.1", 80), | ||
} | ||
request_context = RequestContext(scope=scope_instance) | ||
_request_context.set(request_context) | ||
self.assertTrue(is_user_email_restricted()) | ||
scope_instance["headers"] = [ | ||
(b"host", b"localhost"), | ||
(b"x-forwarded-proto", b"https"), | ||
(b"x-forwarded-for", b"client, proxy1"), | ||
(b"server", b"server"), | ||
(b"user-agent", b"user-agent"), | ||
(b"x-goog-iap-jwt-assertion", b"jwt"), | ||
(b"x-cloud-trace-context", b"TRACE_ID/SPAN_ID;o=1"), | ||
(b"x-goog-authenticated-user-id", b"user_id"), | ||
(b"x-goog-authenticated-user-email", b"[email protected]"), | ||
] | ||
request_context = RequestContext(scope=scope_instance) | ||
_request_context.set(request_context) | ||
self.assertTrue(is_user_email_restricted()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic gave access to
wip
feeds torestricted
users.