-
Notifications
You must be signed in to change notification settings - Fork 203
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
forward requester id to check username for spam callbacks #17916
base: develop
Are you sure you want to change the base?
forward requester id to check username for spam callbacks #17916
Conversation
@@ -735,7 +738,9 @@ async def check_username_for_spam(self, user_profile: UserProfile) -> bool: | |||
with Measure(self.clock, f"{callback.__module__}.{callback.__qualname__}"): | |||
# Make a copy of the user profile object to ensure the spam checker cannot | |||
# modify it. | |||
res = await delay_cancellation(callback(user_profile.copy())) |
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.
I think we need to not break current checkers that do not yet have requester_id
in their signature.
Something like (untested and some stuffs are missing but it's so you get the idea) :
checker_args = inspect.signature(callback)
if len(checker_args.parameters) == 2:
callback(user_profile.copy(), requester_id)
else:
callback(user_profile.copy())
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.
Added unit tests to ensure backwards compat
Thanks for that!
|
… of https://github.com/WilsonLe/synapse into feature/add_reader_to_check_username_for_spam_callback
async def allow_all_expects_requester_id( | ||
user_profile: UserProfile, requester_id: str | ||
) -> bool: | ||
# Allow all users. |
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.
Please add something like assert requester_id is not None
to test that requester_id is correctly passed here.
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.
Added assert is instance of string checks
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.
Can we not do self.assertEqual(requester_id, u1)
?
|
||
# Configure a spam checker that filters all users. | ||
async def block_all_expects_requester_id( | ||
user_profile: UserProfile, requester_id: str |
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.
let's remove requester_id: str
param here so we do test backward compatibility, and add a comment about it.
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.
I kept the old tests that does not have requester_id
. I simply added more tests with requester_id
.
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.
I'll add comments for backwards compatibility for these functions.
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.
Added
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.
I kept the old tests that does not have requester_id. I simply added more tests with requester_id.
Oh good point I haven't noticed, thanks for the comments.
… add comments on old tests on why keeping them is important
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.
LGTM, we now need someone from the core team to trigger the CI :)
Co-authored-by: Patrick Cloke <[email protected]>
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.
Otherwise, LGTM thanks!
@@ -245,7 +245,7 @@ this callback. | |||
_First introduced in Synapse v1.37.0_ | |||
|
|||
```python | |||
async def check_username_for_spam(user_profile: synapse.module_api.UserProfile) -> bool | |||
async def check_username_for_spam(user_profile: synapse.module_api.UserProfile, requester_id: str) -> bool |
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.
Can you add a sentence or two for what requester_id
is please, something like:
The
requester_id
parameter is the ID of the user that called the user directory API.
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.
Added.
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.
@erikjohnston Hi I couldn't reply to your comment on using self.assertEqual(requester_id, u1)
directly but I've added the checks.
async def allow_all_expects_requester_id( | ||
user_profile: UserProfile, requester_id: str | ||
) -> bool: | ||
# Allow all users. |
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.
Can we not do self.assertEqual(requester_id, u1)
?
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.(run the linters)