mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-19 09:31:35 +03:00
fix test_auto_create_auto_join_where_no_consent
This commit is contained in:
parent
0a5382062c
commit
9ad68163bd
2 changed files with 24 additions and 6 deletions
|
@ -23,11 +23,13 @@ from synapse.api.constants import LoginType
|
||||||
from synapse.api.errors import (
|
from synapse.api.errors import (
|
||||||
AuthError,
|
AuthError,
|
||||||
Codes,
|
Codes,
|
||||||
|
ConsentNotGivenError,
|
||||||
InvalidCaptchaError,
|
InvalidCaptchaError,
|
||||||
LimitExceededError,
|
LimitExceededError,
|
||||||
RegistrationError,
|
RegistrationError,
|
||||||
SynapseError,
|
SynapseError,
|
||||||
)
|
)
|
||||||
|
|
||||||
from synapse.config.server import is_threepid_reserved
|
from synapse.config.server import is_threepid_reserved
|
||||||
from synapse.http.client import CaptchaServerHttpClient
|
from synapse.http.client import CaptchaServerHttpClient
|
||||||
from synapse.http.servlet import assert_params_in_dict
|
from synapse.http.servlet import assert_params_in_dict
|
||||||
|
@ -311,6 +313,10 @@ class RegistrationHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
yield self._join_user_to_room(fake_requester, r)
|
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:
|
except Exception as e:
|
||||||
logger.error("Failed to join new user to %r: %r", r, e)
|
logger.error("Failed to join new user to %r: %r", r, e)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ from synapse.api.constants import UserTypes
|
||||||
from synapse.api.errors import ResourceLimitError, SynapseError
|
from synapse.api.errors import ResourceLimitError, SynapseError
|
||||||
from synapse.handlers.register import RegistrationHandler
|
from synapse.handlers.register import RegistrationHandler
|
||||||
from synapse.types import RoomAlias, UserID, create_requester
|
from synapse.types import RoomAlias, UserID, create_requester
|
||||||
|
from synapse.api.urls import ConsentURIBuilder
|
||||||
from tests.utils import setup_test_homeserver
|
from tests.utils import setup_test_homeserver
|
||||||
|
|
||||||
from .. import unittest
|
from .. import unittest
|
||||||
|
@ -187,18 +187,30 @@ class RegistrationTestCase(unittest.TestCase):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_auto_create_auto_join_where_no_consent(self):
|
def test_auto_create_auto_join_where_no_consent(self):
|
||||||
"""XXX what is this trying to test? I *think* it is trying to test
|
"""Test to ensure that the first user is not auto-joined to a room if
|
||||||
that we are not auto-joined to the server notices room if
|
they have not given general consent.
|
||||||
block_events_without_consent_error is set, but (a) that doesn't seem to be
|
|
||||||
a sensible thing to test for, and (b) it doesn't work anyway because you can't
|
|
||||||
change the config after the EventCreationHandler has been instantiated.
|
|
||||||
"""
|
"""
|
||||||
self.hs.config.user_consent_at_registration = True
|
self.hs.config.user_consent_at_registration = True
|
||||||
self.hs.config.block_events_without_consent_error = "Error"
|
self.hs.config.block_events_without_consent_error = "Error"
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
event_creation_handler._block_events_without_consent_error = (
|
||||||
|
self.hs.config.block_events_without_consent_error
|
||||||
|
)
|
||||||
|
event_creation_handler._consent_uri_builder = Mock()
|
||||||
room_alias_str = "#room:test"
|
room_alias_str = "#room:test"
|
||||||
self.hs.config.auto_join_rooms = [room_alias_str]
|
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')
|
res = yield self.handler.register(localpart='jeff')
|
||||||
yield self.handler.post_consent_actions(res[0])
|
yield self.handler.post_consent_actions(res[0])
|
||||||
|
|
||||||
|
# Ensure that they have not been joined to the room
|
||||||
rooms = yield self.store.get_rooms_for_user(res[0])
|
rooms = yield self.store.get_rooms_for_user(res[0])
|
||||||
self.assertEqual(len(rooms), 0)
|
self.assertEqual(len(rooms), 0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue