1
0

Compare commits

...

9 Commits

Author SHA1 Message Date
Neil Johnson
c61bcae886 rename 2019-03-19 11:23:18 +00:00
Neil Johnson
195c2b6d39 delete 2019-03-19 10:51:50 +00:00
Neil Johnson
6e54268bb1 add a . 2019-03-19 10:50:20 +00:00
Neil Johnson
c7238134df add a . 2019-03-19 10:47:39 +00:00
Neil Johnson
97bd4669a1 put it in the right directory ... 2019-03-19 10:44:16 +00:00
Neil Johnson
7480fd3c37 use the correct PR no. 2019-03-19 10:41:32 +00:00
Neil Johnson
4bacb07a45 remove redundant code and improve comments 2019-03-19 10:38:33 +00:00
Neil Johnson
9ad68163bd fix test_auto_create_auto_join_where_no_consent 2019-03-19 10:19:53 +00:00
Richard van der Hoff
0a5382062c broken registration test, for neil to look at 2019-03-18 18:30:07 +00:00
5 changed files with 39 additions and 5 deletions

1
changelog.d/4886.bugfix Normal file
View File

@@ -0,0 +1 @@
fix test_auto_create_auto_join_where_no_consent.

1
changelog.d/4886.misc Normal file
View File

@@ -0,0 +1 @@
fix test_auto_create_auto_join_where_no_consent.

View File

@@ -243,7 +243,14 @@ class EventCreationHandler(object):
self.spam_checker = hs.get_spam_checker()
if self.config.block_events_without_consent_error is not None:
self._block_events_without_consent_error = (
self.config.block_events_without_consent_error
)
# we need to construct a ConsentURIBuilder here, as it checks that the necessary
# config options, but *only* if we have a configuration for which we are
# going to need it.
if self._block_events_without_consent_error:
self._consent_uri_builder = ConsentURIBuilder(self.config)
@defer.inlineCallbacks
@@ -378,7 +385,7 @@ class EventCreationHandler(object):
Raises:
ConsentNotGivenError: if the user has not given consent yet
"""
if self.config.block_events_without_consent_error is None:
if self._block_events_without_consent_error is None:
return
# exempt AS users from needing consent
@@ -405,7 +412,7 @@ class EventCreationHandler(object):
consent_uri = self._consent_uri_builder.build_user_consent_uri(
requester.user.localpart,
)
msg = self.config.block_events_without_consent_error % {
msg = self._block_events_without_consent_error % {
'consent_uri': consent_uri,
}
raise ConsentNotGivenError(

View File

@@ -23,6 +23,7 @@ from synapse.api.constants import LoginType
from synapse.api.errors import (
AuthError,
Codes,
ConsentNotGivenError,
InvalidCaptchaError,
LimitExceededError,
RegistrationError,
@@ -311,6 +312,10 @@ class RegistrationHandler(BaseHandler):
)
else:
yield self._join_user_to_room(fake_requester, r)
except ConsentNotGivenError as e:
# Technically not necessary to pull out this error though
# moving away from bare excepts is a good thing to do.
logger.error("Failed to join new user to %r: %r", r, e)
except Exception as e:
logger.error("Failed to join new user to %r: %r", r, e)

View File

@@ -187,12 +187,32 @@ class RegistrationTestCase(unittest.TestCase):
@defer.inlineCallbacks
def test_auto_create_auto_join_where_no_consent(self):
self.hs.config.user_consent_at_registration = True
self.hs.config.block_events_without_consent_error = "Error"
"""Test to ensure that the first user is not auto-joined to a room if
they have not given general consent.
"""
# Given:-
# * a user must give consent,
# * they have not given that consent
# * The server is configured to auto-join to a room
# (and autocreate if necessary)
event_creation_handler = self.hs.get_event_creation_handler()
# (Messing with the internals of event_creation_handler is fragile
# but can't see a better way to do this. One option could be to subclass
# the test with custom config.)
event_creation_handler._block_events_without_consent_error = ("Error")
event_creation_handler._consent_uri_builder = Mock()
room_alias_str = "#room:test"
self.hs.config.auto_join_rooms = [room_alias_str]
# When:-
# * the user is registered and post consent actions are called
res = yield self.handler.register(localpart='jeff')
yield self.handler.post_consent_actions(res[0])
# Then:-
# * Ensure that they have not been joined to the room
rooms = yield self.store.get_rooms_for_user(res[0])
self.assertEqual(len(rooms), 0)