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
acafcf1c
Commit
acafcf1c
authored
8 years ago
by
pik
Browse files
Options
Downloads
Patches
Plain Diff
Add valid filter tests, flake8, fix typo
Signed-off-by:
pik
<
alexander.maznev@gmail.com
>
parent
e56c79c1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/api/filtering.py
+6
-5
6 additions, 5 deletions
synapse/api/filtering.py
tests/api/test_filtering.py
+49
-5
49 additions, 5 deletions
tests/api/test_filtering.py
with
55 additions
and
10 deletions
synapse/api/filtering.py
+
6
−
5
View file @
acafcf1c
...
...
@@ -78,7 +78,7 @@ ROOM_FILTER_SCHEMA = {
"
timeline
"
:
{
"
$ref
"
:
"
#/definitions/room_event_filter
"
},
"
acc
p
ount_data
"
:
{
"
account_data
"
:
{
"
$ref
"
:
"
#/definitions/room_event_filter
"
},
}
...
...
@@ -131,7 +131,7 @@ USER_ID_ARRAY_SCHEMA = {
"
type
"
:
"
array
"
,
"
items
"
:
{
"
type
"
:
"
string
"
,
"
pattern
"
:
"
^[A-Za-z0-9_]+:[A-Za-z0-9_-\.]+$
"
"
pattern
"
:
"
^
@
[A-Za-z0-9_]+:[A-Za-z0-9_
\
-\.]+$
"
}
}
...
...
@@ -155,9 +155,10 @@ USER_FILTER_SCHEMA = {
"
room
"
:
{
"
$ref
"
:
"
#/definitions/room_filter
"
},
# "event_format": {
# "type": { "enum": [ "client", "federation" ] }
# },
"
event_format
"
:
{
"
type
"
:
"
string
"
,
"
enum
"
:
[
"
client
"
,
"
federation
"
]
},
"
event_fields
"
:
{
"
type
"
:
"
array
"
,
"
items
"
:
{
...
...
This diff is collapsed.
Click to expand it.
tests/api/test_filtering.py
+
49
−
5
View file @
acafcf1c
...
...
@@ -35,6 +35,7 @@ def MockEvent(**kwargs):
kwargs
[
"
type
"
]
=
"
fake_type
"
return
FrozenEvent
(
kwargs
)
class
FilteringTestCase
(
unittest
.
TestCase
):
@defer.inlineCallbacks
...
...
@@ -56,18 +57,61 @@ class FilteringTestCase(unittest.TestCase):
def
test_errors_on_invalid_filters
(
self
):
invalid_filters
=
[
{
"
boom
"
:
{}
},
{
"
account_data
"
:
"
Hello World
"
},
{
"
event_fields
"
:
[
"
\\
foo
"
]
},
{
"
room
"
:
{
"
timeline
"
:
{
"
limit
"
:
0
},
"
state
"
:
{
"
not_bars
"
:
[
"
*
"
]}
}
},
{
"
boom
"
:
{}},
{
"
account_data
"
:
"
Hello World
"
},
{
"
event_fields
"
:
[
"
\\
foo
"
]},
{
"
room
"
:
{
"
timeline
"
:
{
"
limit
"
:
0
},
"
state
"
:
{
"
not_bars
"
:
[
"
*
"
]}}},
{
"
event_format
"
:
"
other
"
}
]
for
filter
in
invalid_filters
:
with
self
.
assertRaises
(
SynapseError
)
as
check_filter_error
:
self
.
filtering
.
check_valid_filter
(
filter
)
self
.
assertIsInstance
(
check_filter_error
.
exception
,
SynapseError
)
def
test_valid_filters
(
self
):
valid_filters
=
[
{
"
room
"
:
{
"
timeline
"
:
{
"
limit
"
:
20
},
"
state
"
:
{
"
not_types
"
:
[
"
m.room.member
"
]},
"
ephemeral
"
:
{
"
limit
"
:
0
,
"
not_types
"
:
[
"
*
"
]},
"
include_leave
"
:
False
,
"
rooms
"
:
[
"
#dee:pik-test
"
],
"
not_rooms
"
:
[
"
#gee:pik-test
"
],
"
account_data
"
:
{
"
limit
"
:
0
,
"
types
"
:
[
"
*
"
]}
}
},
{
"
room
"
:
{
"
state
"
:
{
"
types
"
:
[
"
m.room.*
"
],
"
not_rooms
"
:
[
"
!726s6s6q:example.com
"
]
},
"
timeline
"
:
{
"
limit
"
:
10
,
"
types
"
:
[
"
m.room.message
"
],
"
not_rooms
"
:
[
"
!726s6s6q:example.com
"
],
"
not_senders
"
:
[
"
@spam:example.com
"
]
},
"
ephemeral
"
:
{
"
types
"
:
[
"
m.receipt
"
,
"
m.typing
"
],
"
not_rooms
"
:
[
"
!726s6s6q:example.com
"
],
"
not_senders
"
:
[
"
@spam:example.com
"
]
}
},
"
presence
"
:
{
"
types
"
:
[
"
m.presence
"
],
"
not_senders
"
:
[
"
@alice:example.com
"
]
},
"
event_format
"
:
"
client
"
,
"
event_fields
"
:
[
"
type
"
,
"
content
"
,
"
sender
"
]
}
]
for
filter
in
valid_filters
:
self
.
filtering
.
check_valid_filter
(
filter
)
def
test_limits_are_applied
(
self
):
#TODO
#
TODO
pass
def
test_definition_types_works_with_literals
(
self
):
...
...
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