2019-04-04 12:25:47 -04:00
|
|
|
#
|
2023-11-21 15:29:58 -05:00
|
|
|
# This file is licensed under the Affero General Public License (AGPL) version 3.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2023 New Vector, Ltd
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# See the GNU Affero General Public License for more details:
|
|
|
|
# <https://www.gnu.org/licenses/agpl-3.0.html>.
|
|
|
|
#
|
|
|
|
# Originally licensed under the Apache License, Version 2.0:
|
|
|
|
# <http://www.apache.org/licenses/LICENSE-2.0>.
|
|
|
|
#
|
|
|
|
# [This file includes modifications made by New Vector Limited]
|
2019-04-04 12:25:47 -04:00
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2022-02-24 13:56:38 -05:00
|
|
|
from http import HTTPStatus
|
|
|
|
|
|
|
|
from twisted.test.proto_helpers import MemoryReactor
|
2019-04-04 12:25:47 -04:00
|
|
|
|
2019-05-01 10:32:38 -04:00
|
|
|
import synapse.rest.admin
|
2021-08-17 07:57:58 -04:00
|
|
|
from synapse.rest.client import login, room
|
2022-02-24 13:56:38 -05:00
|
|
|
from synapse.server import HomeServer
|
|
|
|
from synapse.util import Clock
|
2019-04-04 12:25:47 -04:00
|
|
|
|
|
|
|
from tests import unittest
|
|
|
|
|
|
|
|
|
|
|
|
class IdentityTestCase(unittest.HomeserverTestCase):
|
|
|
|
servlets = [
|
2019-05-02 06:59:16 -04:00
|
|
|
synapse.rest.admin.register_servlets_for_client_rest_resource,
|
2019-04-04 12:25:47 -04:00
|
|
|
room.register_servlets,
|
|
|
|
login.register_servlets,
|
|
|
|
]
|
|
|
|
|
2022-02-24 13:56:38 -05:00
|
|
|
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
|
2019-04-04 12:25:47 -04:00
|
|
|
config = self.default_config()
|
2019-05-13 16:01:14 -04:00
|
|
|
config["enable_3pid_lookup"] = False
|
2019-04-04 12:25:47 -04:00
|
|
|
self.hs = self.setup_test_homeserver(config=config)
|
|
|
|
|
|
|
|
return self.hs
|
|
|
|
|
2022-02-24 13:56:38 -05:00
|
|
|
def test_3pid_lookup_disabled(self) -> None:
|
2021-10-04 07:18:54 -04:00
|
|
|
self.hs.config.registration.enable_3pid_lookup = False
|
2019-04-04 12:25:47 -04:00
|
|
|
|
|
|
|
self.register_user("kermit", "monkey")
|
|
|
|
tok = self.login("kermit", "monkey")
|
|
|
|
|
2020-12-15 09:44:04 -05:00
|
|
|
channel = self.make_request(b"POST", "/createRoom", b"{}", access_token=tok)
|
2022-02-24 13:56:38 -05:00
|
|
|
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
2019-04-04 12:25:47 -04:00
|
|
|
room_id = channel.json_body["room_id"]
|
|
|
|
|
2022-07-17 17:28:45 -04:00
|
|
|
request_data = {
|
2019-04-04 12:25:47 -04:00
|
|
|
"id_server": "testis",
|
|
|
|
"medium": "email",
|
|
|
|
"address": "test@example.com",
|
2022-08-31 08:10:25 -04:00
|
|
|
"id_access_token": tok,
|
2019-04-04 12:25:47 -04:00
|
|
|
}
|
2019-05-10 01:12:11 -04:00
|
|
|
request_url = ("/rooms/%s/invite" % (room_id)).encode("ascii")
|
2020-12-15 09:44:04 -05:00
|
|
|
channel = self.make_request(
|
2019-05-10 01:12:11 -04:00
|
|
|
b"POST", request_url, request_data, access_token=tok
|
2019-04-04 12:25:47 -04:00
|
|
|
)
|
2022-02-24 13:56:38 -05:00
|
|
|
self.assertEqual(channel.code, HTTPStatus.FORBIDDEN, channel.result)
|