Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
cc32fa73
Unverified
Commit
cc32fa73
authored
4 years ago
by
Patrick Cloke
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Ensure the body is a string before comparing push rules. (#7701)
parent
2b234465
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/7701.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/7701.bugfix
synapse/push/push_rule_evaluator.py
+2
-2
2 additions, 2 deletions
synapse/push/push_rule_evaluator.py
tests/push/test_push_rule_evaluator.py
+30
-9
30 additions, 9 deletions
tests/push/test_push_rule_evaluator.py
with
33 additions
and
11 deletions
changelog.d/7701.bugfix
0 → 100644
+
1
−
0
View file @
cc32fa73
Do not break push rule evaluation when receiving an event with a non-string body. This is a long-standing bug.
This diff is collapsed.
Click to expand it.
synapse/push/push_rule_evaluator.py
+
2
−
2
View file @
cc32fa73
...
...
@@ -131,7 +131,7 @@ class PushRuleEvaluatorForEvent(object):
# XXX: optimisation: cache our pattern regexps
if
condition
[
"
key
"
]
==
"
content.body
"
:
body
=
self
.
_event
.
content
.
get
(
"
body
"
,
None
)
if
not
body
:
if
not
body
or
not
isinstance
(
body
,
str
)
:
return
False
return
_glob_matches
(
pattern
,
body
,
word_boundary
=
True
)
...
...
@@ -147,7 +147,7 @@ class PushRuleEvaluatorForEvent(object):
return
False
body
=
self
.
_event
.
content
.
get
(
"
body
"
,
None
)
if
not
body
:
if
not
body
or
not
isinstance
(
body
,
str
)
:
return
False
# Similar to _glob_matches, but do not treat display_name as a glob.
...
...
This diff is collapsed.
Click to expand it.
tests/push/test_push_rule_evaluator.py
+
30
−
9
View file @
cc32fa73
...
...
@@ -21,7 +21,7 @@ from tests import unittest
class
PushRuleEvaluatorTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
_get_evaluator
(
self
,
content
):
event
=
FrozenEvent
(
{
"
event_id
"
:
"
$event_id
"
,
...
...
@@ -29,37 +29,58 @@ class PushRuleEvaluatorTestCase(unittest.TestCase):
"
sender
"
:
"
@user:test
"
,
"
state_key
"
:
""
,
"
room_id
"
:
"
@room:test
"
,
"
content
"
:
{
"
body
"
:
"
foo bar baz
"
}
,
"
content
"
:
content
,
},
RoomVersions
.
V1
,
)
room_member_count
=
0
sender_power_level
=
0
power_levels
=
{}
self
.
evaluator
=
PushRuleEvaluatorForEvent
(
return
PushRuleEvaluatorForEvent
(
event
,
room_member_count
,
sender_power_level
,
power_levels
)
def
test_display_name
(
self
):
"""
Check for a matching display name in the body of the event.
"""
evaluator
=
self
.
_get_evaluator
({
"
body
"
:
"
foo bar baz
"
})
condition
=
{
"
kind
"
:
"
contains_display_name
"
,
}
# Blank names are skipped.
self
.
assertFalse
(
self
.
evaluator
.
matches
(
condition
,
"
@user:test
"
,
""
))
self
.
assertFalse
(
evaluator
.
matches
(
condition
,
"
@user:test
"
,
""
))
# Check a display name that doesn't match.
self
.
assertFalse
(
self
.
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
not found
"
))
self
.
assertFalse
(
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
not found
"
))
# Check a display name which matches.
self
.
assertTrue
(
self
.
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
foo
"
))
self
.
assertTrue
(
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
foo
"
))
# A display name that matches, but not a full word does not result in a match.
self
.
assertFalse
(
self
.
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
ba
"
))
self
.
assertFalse
(
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
ba
"
))
# A display name should not be interpreted as a regular expression.
self
.
assertFalse
(
self
.
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
ba[rz]
"
))
self
.
assertFalse
(
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
ba[rz]
"
))
# A display name with spaces should work fine.
self
.
assertTrue
(
self
.
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
foo bar
"
))
self
.
assertTrue
(
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
foo bar
"
))
def
test_no_body
(
self
):
"""
Not having a body shouldn
'
t break the evaluator.
"""
evaluator
=
self
.
_get_evaluator
({})
condition
=
{
"
kind
"
:
"
contains_display_name
"
,
}
self
.
assertFalse
(
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
foo
"
))
def
test_invalid_body
(
self
):
"""
A non-string body should not break the evaluator.
"""
condition
=
{
"
kind
"
:
"
contains_display_name
"
,
}
for
body
in
(
1
,
True
,
{
"
foo
"
:
"
bar
"
}):
evaluator
=
self
.
_get_evaluator
({
"
body
"
:
body
})
self
.
assertFalse
(
evaluator
.
matches
(
condition
,
"
@user:test
"
,
"
foo
"
))
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