Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Require the rel_type field.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed May 20, 2022
1 parent 5549869 commit 8851217
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
12 changes: 6 additions & 6 deletions synapse/push/push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,21 +280,21 @@ def _relation_match(self, condition: dict, user_id: str) -> bool:
Returns:
True if the condition matches the event, False otherwise.
"""
rel_type_pattern = condition.get("rel_type")
rel_type = condition.get("rel_type")
if not rel_type:
logger.warning("relation_match condition missing rel_type")
return False

sender_pattern = condition.get("sender")
if sender_pattern is None:
sender_type = condition.get("sender_type")
if sender_type == "user_id":
sender_pattern = user_id
type_pattern = condition.get("type")

if not rel_type_pattern and not sender_pattern and not type_pattern:
logger.warning("relation_match condition with nothing to match")
return False

# If any other relations matches, return True.
for relation in self._relations:
if rel_type_pattern and not _glob_matches(rel_type_pattern, relation[0]):
if rel_type != relation[0]:
continue
if sender_pattern and not _glob_matches(sender_pattern, relation[1]):
continue
Expand Down
19 changes: 13 additions & 6 deletions tests/push/test_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,25 @@ def test_relation_match(self) -> None:
}
self.assertTrue(evaluator.matches(condition, "@user:test", "foo"))

# Check just sender.
# Check just sender, this fails since rel_type is required.
condition = {
"kind": "org.matrix.msc3772.relation_match",
"sender": "@user:test",
}
self.assertTrue(evaluator.matches(condition, "@user:test", "foo"))
self.assertFalse(evaluator.matches(condition, "@user:test", "foo"))

# Check sender glob.
condition = {
"kind": "org.matrix.msc3772.relation_match",
"sender": "@other:test",
"rel_type": "m.annotation",
"sender": "@*:test",
}
self.assertFalse(evaluator.matches(condition, "@user:test", "foo"))
self.assertTrue(evaluator.matches(condition, "@user:test", "foo"))

# Check glob.
condition = {"kind": "org.matrix.msc3772.relation_match", "sender": "@*:test"}
# Check event type glob.
condition = {
"kind": "org.matrix.msc3772.relation_match",
"rel_type": "m.annotation",
"event_type": "*.reaction",
}
self.assertTrue(evaluator.matches(condition, "@user:test", "foo"))

0 comments on commit 8851217

Please sign in to comment.