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
Container Registry
Model registry
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
Maunium
synapse
Commits
2566dc57
Unverified
Commit
2566dc57
authored
4 years ago
by
Erik Johnston
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Test that we require validated email for email pushers (#9496)
parent
1e62d9ee
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/9496.misc
+1
-0
1 addition, 0 deletions
changelog.d/9496.misc
synapse/push/pusherpool.py
+6
-0
6 additions, 0 deletions
synapse/push/pusherpool.py
tests/push/test_email.py
+32
-2
32 additions, 2 deletions
tests/push/test_email.py
with
39 additions
and
2 deletions
changelog.d/9496.misc
0 → 100644
+
1
−
0
View file @
2566dc57
Test that we require validated email for email pushers.
This diff is collapsed.
Click to expand it.
synapse/push/pusherpool.py
+
6
−
0
View file @
2566dc57
...
...
@@ -19,6 +19,7 @@ from typing import TYPE_CHECKING, Dict, Iterable, Optional
from
prometheus_client
import
Gauge
from
synapse.api.errors
import
Codes
,
SynapseError
from
synapse.metrics.background_process_metrics
import
(
run_as_background_process
,
wrap_as_background_process
,
...
...
@@ -113,6 +114,11 @@ class PusherPool:
The newly created pusher.
"""
if
kind
==
"
email
"
:
email_owner
=
await
self
.
store
.
get_user_id_by_threepid
(
"
email
"
,
pushkey
)
if
email_owner
!=
user_id
:
raise
SynapseError
(
400
,
"
Email not found
"
,
Codes
.
THREEPID_NOT_FOUND
)
time_now_msec
=
self
.
clock
.
time_msec
()
# create the pusher setting last_stream_ordering to the current maximum
...
...
This diff is collapsed.
Click to expand it.
tests/push/test_email.py
+
32
−
2
View file @
2566dc57
...
...
@@ -21,6 +21,7 @@ import pkg_resources
from
twisted.internet.defer
import
Deferred
import
synapse.rest.admin
from
synapse.api.errors
import
Codes
,
SynapseError
from
synapse.rest.client.v1
import
login
,
room
from
tests.unittest
import
HomeserverTestCase
...
...
@@ -100,12 +101,19 @@ class EmailPusherTests(HomeserverTestCase):
user_tuple
=
self
.
get_success
(
self
.
hs
.
get_datastore
().
get_user_by_access_token
(
self
.
access_token
)
)
token_id
=
user_tuple
.
token_id
self
.
token_id
=
user_tuple
.
token_id
# We need to add email to account before we can create a pusher.
self
.
get_success
(
hs
.
get_datastore
().
user_add_threepid
(
self
.
user_id
,
"
email
"
,
"
a@example.com
"
,
0
,
0
)
)
self
.
pusher
=
self
.
get_success
(
self
.
hs
.
get_pusherpool
().
add_pusher
(
user_id
=
self
.
user_id
,
access_token
=
token_id
,
access_token
=
self
.
token_id
,
kind
=
"
email
"
,
app_id
=
"
m.email
"
,
app_display_name
=
"
Email Notifications
"
,
...
...
@@ -116,6 +124,28 @@ class EmailPusherTests(HomeserverTestCase):
)
)
def
test_need_validated_email
(
self
):
"""
Test that we can only add an email pusher if the user has validated
their email.
"""
with
self
.
assertRaises
(
SynapseError
)
as
cm
:
self
.
get_success_or_raise
(
self
.
hs
.
get_pusherpool
().
add_pusher
(
user_id
=
self
.
user_id
,
access_token
=
self
.
token_id
,
kind
=
"
email
"
,
app_id
=
"
m.email
"
,
app_display_name
=
"
Email Notifications
"
,
device_display_name
=
"
b@example.com
"
,
pushkey
=
"
b@example.com
"
,
lang
=
None
,
data
=
{},
)
)
self
.
assertEqual
(
400
,
cm
.
exception
.
code
)
self
.
assertEqual
(
Codes
.
THREEPID_NOT_FOUND
,
cm
.
exception
.
errcode
)
def
test_simple_sends_email
(
self
):
# Create a simple room with two users
room
=
self
.
helper
.
create_room_as
(
self
.
user_id
,
tok
=
self
.
access_token
)
...
...
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