This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that we require validated email for email pushers (#9496)
- Loading branch information
1 parent
1e62d9e
commit 2566dc5
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test that we require validated email for email pushers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
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 @@ def prepare(self, reactor, clock, hs): | |
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", "[email protected]", 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 @@ def prepare(self, reactor, clock, hs): | |
) | ||
) | ||
|
||
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="[email protected]", | ||
pushkey="[email protected]", | ||
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) | ||
|