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
5561a879
Commit
5561a879
authored
10 years ago
by
Kegan Dougal
Browse files
Options
Downloads
Patches
Plain Diff
Add more unit tests for the filter algorithm.
parent
777d9914
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
tests/api/test_filtering.py
+259
-5
259 additions, 5 deletions
tests/api/test_filtering.py
with
259 additions
and
5 deletions
tests/api/test_filtering.py
+
259
−
5
View file @
5561a879
...
@@ -56,7 +56,7 @@ class FilteringTestCase(unittest.TestCase):
...
@@ -56,7 +56,7 @@ class FilteringTestCase(unittest.TestCase):
self
.
datastore
=
hs
.
get_datastore
()
self
.
datastore
=
hs
.
get_datastore
()
def
test_definition_
include
_literal
_type
s
(
self
):
def
test_definition_
types_works_with
_literals
(
self
):
definition
=
{
definition
=
{
"
types
"
:
[
"
m.room.message
"
,
"
org.matrix.foo.bar
"
]
"
types
"
:
[
"
m.room.message
"
,
"
org.matrix.foo.bar
"
]
}
}
...
@@ -65,12 +65,11 @@ class FilteringTestCase(unittest.TestCase):
...
@@ -65,12 +65,11 @@ class FilteringTestCase(unittest.TestCase):
type
=
"
m.room.message
"
,
type
=
"
m.room.message
"
,
room_id
=
"
!foo:bar
"
room_id
=
"
!foo:bar
"
)
)
self
.
assertTrue
(
self
.
assertTrue
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
)
def
test_definition_
include
_wildcard
_type
s
(
self
):
def
test_definition_
types_works_with
_wildcards
(
self
):
definition
=
{
definition
=
{
"
types
"
:
[
"
m.*
"
,
"
org.matrix.foo.bar
"
]
"
types
"
:
[
"
m.*
"
,
"
org.matrix.foo.bar
"
]
}
}
...
@@ -79,12 +78,11 @@ class FilteringTestCase(unittest.TestCase):
...
@@ -79,12 +78,11 @@ class FilteringTestCase(unittest.TestCase):
type
=
"
m.room.message
"
,
type
=
"
m.room.message
"
,
room_id
=
"
!foo:bar
"
room_id
=
"
!foo:bar
"
)
)
self
.
assertTrue
(
self
.
assertTrue
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
)
def
test_definition_
exclude
_unknown
_type
s
(
self
):
def
test_definition_
types_works_with
_unknowns
(
self
):
definition
=
{
definition
=
{
"
types
"
:
[
"
m.room.message
"
,
"
org.matrix.foo.bar
"
]
"
types
"
:
[
"
m.room.message
"
,
"
org.matrix.foo.bar
"
]
}
}
...
@@ -93,7 +91,263 @@ class FilteringTestCase(unittest.TestCase):
...
@@ -93,7 +91,263 @@ class FilteringTestCase(unittest.TestCase):
type
=
"
now.for.something.completely.different
"
,
type
=
"
now.for.something.completely.different
"
,
room_id
=
"
!foo:bar
"
room_id
=
"
!foo:bar
"
)
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_types_works_with_literals
(
self
):
definition
=
{
"
not_types
"
:
[
"
m.room.message
"
,
"
org.matrix.foo.bar
"
]
}
event
=
MockEvent
(
sender
=
"
@foo:bar
"
,
type
=
"
m.room.message
"
,
room_id
=
"
!foo:bar
"
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_types_works_with_wildcards
(
self
):
definition
=
{
"
not_types
"
:
[
"
m.room.message
"
,
"
org.matrix.*
"
]
}
event
=
MockEvent
(
sender
=
"
@foo:bar
"
,
type
=
"
org.matrix.custom.event
"
,
room_id
=
"
!foo:bar
"
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_types_works_with_unknowns
(
self
):
definition
=
{
"
not_types
"
:
[
"
m.*
"
,
"
org.*
"
]
}
event
=
MockEvent
(
sender
=
"
@foo:bar
"
,
type
=
"
com.nom.nom.nom
"
,
room_id
=
"
!foo:bar
"
)
self
.
assertTrue
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_types_takes_priority_over_types
(
self
):
definition
=
{
"
not_types
"
:
[
"
m.*
"
,
"
org.*
"
],
"
types
"
:
[
"
m.room.message
"
,
"
m.room.topic
"
]
}
event
=
MockEvent
(
sender
=
"
@foo:bar
"
,
type
=
"
m.room.topic
"
,
room_id
=
"
!foo:bar
"
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_senders_works_with_literals
(
self
):
definition
=
{
"
senders
"
:
[
"
@flibble:wibble
"
]
}
event
=
MockEvent
(
sender
=
"
@flibble:wibble
"
,
type
=
"
com.nom.nom.nom
"
,
room_id
=
"
!foo:bar
"
)
self
.
assertTrue
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_senders_works_with_unknowns
(
self
):
definition
=
{
"
senders
"
:
[
"
@flibble:wibble
"
]
}
event
=
MockEvent
(
sender
=
"
@challenger:appears
"
,
type
=
"
com.nom.nom.nom
"
,
room_id
=
"
!foo:bar
"
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_senders_works_with_literals
(
self
):
definition
=
{
"
not_senders
"
:
[
"
@flibble:wibble
"
]
}
event
=
MockEvent
(
sender
=
"
@flibble:wibble
"
,
type
=
"
com.nom.nom.nom
"
,
room_id
=
"
!foo:bar
"
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_senders_works_with_unknowns
(
self
):
definition
=
{
"
not_senders
"
:
[
"
@flibble:wibble
"
]
}
event
=
MockEvent
(
sender
=
"
@challenger:appears
"
,
type
=
"
com.nom.nom.nom
"
,
room_id
=
"
!foo:bar
"
)
self
.
assertTrue
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_senders_takes_priority_over_senders
(
self
):
definition
=
{
"
not_senders
"
:
[
"
@misspiggy:muppets
"
],
"
senders
"
:
[
"
@kermit:muppets
"
,
"
@misspiggy:muppets
"
]
}
event
=
MockEvent
(
sender
=
"
@misspiggy:muppets
"
,
type
=
"
m.room.topic
"
,
room_id
=
"
!foo:bar
"
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_rooms_works_with_literals
(
self
):
definition
=
{
"
rooms
"
:
[
"
!secretbase:unknown
"
]
}
event
=
MockEvent
(
sender
=
"
@foo:bar
"
,
type
=
"
m.room.message
"
,
room_id
=
"
!secretbase:unknown
"
)
self
.
assertTrue
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_rooms_works_with_unknowns
(
self
):
definition
=
{
"
rooms
"
:
[
"
!secretbase:unknown
"
]
}
event
=
MockEvent
(
sender
=
"
@foo:bar
"
,
type
=
"
m.room.message
"
,
room_id
=
"
!anothersecretbase:unknown
"
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_rooms_works_with_literals
(
self
):
definition
=
{
"
not_rooms
"
:
[
"
!anothersecretbase:unknown
"
]
}
event
=
MockEvent
(
sender
=
"
@foo:bar
"
,
type
=
"
m.room.message
"
,
room_id
=
"
!anothersecretbase:unknown
"
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_rooms_works_with_unknowns
(
self
):
definition
=
{
"
not_rooms
"
:
[
"
!secretbase:unknown
"
]
}
event
=
MockEvent
(
sender
=
"
@foo:bar
"
,
type
=
"
m.room.message
"
,
room_id
=
"
!anothersecretbase:unknown
"
)
self
.
assertTrue
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_not_rooms_takes_priority_over_rooms
(
self
):
definition
=
{
"
not_rooms
"
:
[
"
!secretbase:unknown
"
],
"
rooms
"
:
[
"
!secretbase:unknown
"
]
}
event
=
MockEvent
(
sender
=
"
@foo:bar
"
,
type
=
"
m.room.message
"
,
room_id
=
"
!secretbase:unknown
"
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_combined_event
(
self
):
definition
=
{
"
not_senders
"
:
[
"
@misspiggy:muppets
"
],
"
senders
"
:
[
"
@kermit:muppets
"
],
"
rooms
"
:
[
"
!stage:unknown
"
],
"
not_rooms
"
:
[
"
!piggyshouse:muppets
"
],
"
types
"
:
[
"
m.room.message
"
,
"
muppets.kermit.*
"
],
"
not_types
"
:
[
"
muppets.misspiggy.*
"
]
}
event
=
MockEvent
(
sender
=
"
@kermit:muppets
"
,
# yup
type
=
"
m.room.message
"
,
# yup
room_id
=
"
!stage:unknown
"
# yup
)
self
.
assertTrue
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_combined_event_bad_sender
(
self
):
definition
=
{
"
not_senders
"
:
[
"
@misspiggy:muppets
"
],
"
senders
"
:
[
"
@kermit:muppets
"
],
"
rooms
"
:
[
"
!stage:unknown
"
],
"
not_rooms
"
:
[
"
!piggyshouse:muppets
"
],
"
types
"
:
[
"
m.room.message
"
,
"
muppets.kermit.*
"
],
"
not_types
"
:
[
"
muppets.misspiggy.*
"
]
}
event
=
MockEvent
(
sender
=
"
@misspiggy:muppets
"
,
# nope
type
=
"
m.room.message
"
,
# yup
room_id
=
"
!stage:unknown
"
# yup
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_combined_event_bad_room
(
self
):
definition
=
{
"
not_senders
"
:
[
"
@misspiggy:muppets
"
],
"
senders
"
:
[
"
@kermit:muppets
"
],
"
rooms
"
:
[
"
!stage:unknown
"
],
"
not_rooms
"
:
[
"
!piggyshouse:muppets
"
],
"
types
"
:
[
"
m.room.message
"
,
"
muppets.kermit.*
"
],
"
not_types
"
:
[
"
muppets.misspiggy.*
"
]
}
event
=
MockEvent
(
sender
=
"
@kermit:muppets
"
,
# yup
type
=
"
m.room.message
"
,
# yup
room_id
=
"
!piggyshouse:muppets
"
# nope
)
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
def
test_definition_combined_event_bad_type
(
self
):
definition
=
{
"
not_senders
"
:
[
"
@misspiggy:muppets
"
],
"
senders
"
:
[
"
@kermit:muppets
"
],
"
rooms
"
:
[
"
!stage:unknown
"
],
"
not_rooms
"
:
[
"
!piggyshouse:muppets
"
],
"
types
"
:
[
"
m.room.message
"
,
"
muppets.kermit.*
"
],
"
not_types
"
:
[
"
muppets.misspiggy.*
"
]
}
event
=
MockEvent
(
sender
=
"
@kermit:muppets
"
,
# yup
type
=
"
muppets.misspiggy.kisses
"
,
# nope
room_id
=
"
!stage:unknown
"
# yup
)
self
.
assertFalse
(
self
.
assertFalse
(
self
.
filtering
.
_passes_definition
(
definition
,
event
)
self
.
filtering
.
_passes_definition
(
definition
,
event
)
)
)
...
...
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