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
eb3beb8f
Unverified
Commit
eb3beb8f
authored
3 years ago
by
Patrick Cloke
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add type hints and comments to event auth code. (#10393)
parent
0d5b08ac
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
changelog.d/10393.misc
+1
-0
1 addition, 0 deletions
changelog.d/10393.misc
mypy.ini
+1
-0
1 addition, 0 deletions
mypy.ini
synapse/event_auth.py
+3
-0
3 additions, 0 deletions
synapse/event_auth.py
tests/test_event_auth.py
+13
-10
13 additions, 10 deletions
tests/test_event_auth.py
with
18 additions
and
10 deletions
changelog.d/10393.misc
0 → 100644
+
1
−
0
View file @
eb3beb8f
Add type hints and comments to event auth code.
This diff is collapsed.
Click to expand it.
mypy.ini
+
1
−
0
View file @
eb3beb8f
...
...
@@ -83,6 +83,7 @@ files =
synapse/util/stringutils.py,
synapse/visibility.py,
tests/replication,
tests/test_event_auth.py,
tests/test_utils,
tests/handlers/test_password_providers.py,
tests/rest/client/v1/test_login.py,
...
...
This diff is collapsed.
Click to expand it.
synapse/event_auth.py
+
3
−
0
View file @
eb3beb8f
...
...
@@ -48,6 +48,9 @@ def check(
room_version_obj: the version of the room
event: the event being checked.
auth_events: the existing room state.
do_sig_check: True if it should be verified that the sending server
signed the event.
do_size_check: True if the size of the event fields should be verified.
Raises:
AuthError if the checks fail
...
...
This diff is collapsed.
Click to expand it.
tests/test_event_auth.py
+
13
−
10
View file @
eb3beb8f
...
...
@@ -13,12 +13,13 @@
# limitations under the License.
import
unittest
from
typing
import
Optional
from
synapse
import
event_auth
from
synapse.api.errors
import
AuthError
from
synapse.api.room_versions
import
RoomVersions
from
synapse.events
import
make_event_from_dict
from
synapse.types
import
get_domain_from_id
from
synapse.events
import
EventBase
,
make_event_from_dict
from
synapse.types
import
JsonDict
,
get_domain_from_id
class
EventAuthTestCase
(
unittest
.
TestCase
):
...
...
@@ -432,7 +433,7 @@ class EventAuthTestCase(unittest.TestCase):
TEST_ROOM_ID
=
"
!test:room
"
def
_create_event
(
user_id
)
:
def
_create_event
(
user_id
:
str
)
->
EventBase
:
return
make_event_from_dict
(
{
"
room_id
"
:
TEST_ROOM_ID
,
...
...
@@ -444,7 +445,9 @@ def _create_event(user_id):
)
def
_member_event
(
user_id
,
membership
,
sender
=
None
):
def
_member_event
(
user_id
:
str
,
membership
:
str
,
sender
:
Optional
[
str
]
=
None
)
->
EventBase
:
return
make_event_from_dict
(
{
"
room_id
"
:
TEST_ROOM_ID
,
...
...
@@ -458,11 +461,11 @@ def _member_event(user_id, membership, sender=None):
)
def
_join_event
(
user_id
)
:
def
_join_event
(
user_id
:
str
)
->
EventBase
:
return
_member_event
(
user_id
,
"
join
"
)
def
_power_levels_event
(
sender
,
content
)
:
def
_power_levels_event
(
sender
:
str
,
content
:
JsonDict
)
->
EventBase
:
return
make_event_from_dict
(
{
"
room_id
"
:
TEST_ROOM_ID
,
...
...
@@ -475,7 +478,7 @@ def _power_levels_event(sender, content):
)
def
_alias_event
(
sender
,
**
kwargs
):
def
_alias_event
(
sender
:
str
,
**
kwargs
)
->
EventBase
:
data
=
{
"
room_id
"
:
TEST_ROOM_ID
,
"
event_id
"
:
_get_event_id
(),
...
...
@@ -488,7 +491,7 @@ def _alias_event(sender, **kwargs):
return
make_event_from_dict
(
data
)
def
_random_state_event
(
sender
)
:
def
_random_state_event
(
sender
:
str
)
->
EventBase
:
return
make_event_from_dict
(
{
"
room_id
"
:
TEST_ROOM_ID
,
...
...
@@ -501,7 +504,7 @@ def _random_state_event(sender):
)
def
_join_rules_event
(
sender
,
join_rule
)
:
def
_join_rules_event
(
sender
:
str
,
join_rule
:
str
)
->
EventBase
:
return
make_event_from_dict
(
{
"
room_id
"
:
TEST_ROOM_ID
,
...
...
@@ -519,7 +522,7 @@ def _join_rules_event(sender, join_rule):
event_count
=
0
def
_get_event_id
():
def
_get_event_id
()
->
str
:
global
event_count
c
=
event_count
event_count
+=
1
...
...
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