Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
52423607
Commit
52423607
authored
6 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
Clarify interface for event_auth
stop pretending that it returns a boolean, which just almost gave me a heart attack.
parent
557b686e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/event_auth.py
+16
-18
16 additions, 18 deletions
synapse/event_auth.py
with
16 additions
and
18 deletions
synapse/event_auth.py
+
16
−
18
View file @
52423607
...
...
@@ -34,9 +34,11 @@ def check(event, auth_events, do_sig_check=True, do_size_check=True):
event: the event being checked.
auth_events (dict: event-key -> event): the existing room state.
Raises:
AuthError if the checks fail
Returns:
True
if the auth checks pass.
if the auth checks pass.
"""
if
do_size_check
:
_check_size_limits
(
event
)
...
...
@@ -71,7 +73,7 @@ def check(event, auth_events, do_sig_check=True, do_size_check=True):
# Oh, we don't know what the state of the room was, so we
# are trusting that this is allowed (at least for now)
logger
.
warn
(
"
Trusting event: %s
"
,
event
.
event_id
)
return
True
return
if
event
.
type
==
EventTypes
.
Create
:
room_id_domain
=
get_domain_from_id
(
event
.
room_id
)
...
...
@@ -81,7 +83,8 @@ def check(event, auth_events, do_sig_check=True, do_size_check=True):
"
Creation event
'
s room_id domain does not match sender
'
s
"
)
# FIXME
return
True
logger
.
debug
(
"
Allowing! %s
"
,
event
)
return
creation_event
=
auth_events
.
get
((
EventTypes
.
Create
,
""
),
None
)
...
...
@@ -118,7 +121,8 @@ def check(event, auth_events, do_sig_check=True, do_size_check=True):
403
,
"
Alias event
'
s state_key does not match sender
'
s domain
"
)
return
True
logger
.
debug
(
"
Allowing! %s
"
,
event
)
return
if
logger
.
isEnabledFor
(
logging
.
DEBUG
):
logger
.
debug
(
...
...
@@ -127,14 +131,9 @@ def check(event, auth_events, do_sig_check=True, do_size_check=True):
)
if
event
.
type
==
EventTypes
.
Member
:
allowed
=
_is_membership_change_allowed
(
event
,
auth_events
)
if
allowed
:
logger
.
debug
(
"
Allowing! %s
"
,
event
)
else
:
logger
.
debug
(
"
Denying! %s
"
,
event
)
return
allowed
_is_membership_change_allowed
(
event
,
auth_events
)
logger
.
debug
(
"
Allowing! %s
"
,
event
)
return
_check_event_sender_in_room
(
event
,
auth_events
)
...
...
@@ -153,7 +152,8 @@ def check(event, auth_events, do_sig_check=True, do_size_check=True):
)
)
else
:
return
True
logger
.
debug
(
"
Allowing! %s
"
,
event
)
return
_can_send_event
(
event
,
auth_events
)
...
...
@@ -200,7 +200,7 @@ def _is_membership_change_allowed(event, auth_events):
create
=
auth_events
.
get
(
key
)
if
create
and
event
.
prev_events
[
0
][
0
]
==
create
.
event_id
:
if
create
.
content
[
"
creator
"
]
==
event
.
state_key
:
return
True
return
target_user_id
=
event
.
state_key
...
...
@@ -265,13 +265,13 @@ def _is_membership_change_allowed(event, auth_events):
raise
AuthError
(
403
,
"
%s is banned from the room
"
%
(
target_user_id
,)
)
return
True
return
if
Membership
.
JOIN
!=
membership
:
if
(
caller_invited
and
Membership
.
LEAVE
==
membership
and
target_user_id
==
event
.
user_id
):
return
True
return
if
not
caller_in_room
:
# caller isn't joined
raise
AuthError
(
...
...
@@ -334,8 +334,6 @@ def _is_membership_change_allowed(event, auth_events):
else
:
raise
AuthError
(
500
,
"
Unknown membership %s
"
%
membership
)
return
True
def
_check_event_sender_in_room
(
event
,
auth_events
):
key
=
(
EventTypes
.
Member
,
event
.
user_id
,
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment