mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Use a regular HomeServerConfig object for unit tests
Rather than using a Mock for the homeserver config, use a genuine HomeServerConfig object. This makes for a more realistic test, and means that we don't have to keep remembering to add things to the mock config every time we add a new config setting.
This commit is contained in:
parent
053c50bcb3
commit
13bc1e0746
@ -405,7 +405,10 @@ class Config(object):
|
|||||||
self.invoke_all("generate_files", config)
|
self.invoke_all("generate_files", config)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.invoke_all("read_config", config)
|
self.parse_config_dict(config)
|
||||||
|
|
||||||
|
def parse_config_dict(self, config_dict):
|
||||||
|
self.invoke_all("read_config", config_dict)
|
||||||
|
|
||||||
|
|
||||||
def find_config_files(search_paths):
|
def find_config_files(search_paths):
|
||||||
|
@ -38,7 +38,12 @@ logger = logging.getLogger(__name__)
|
|||||||
class KeyConfig(Config):
|
class KeyConfig(Config):
|
||||||
|
|
||||||
def read_config(self, config):
|
def read_config(self, config):
|
||||||
self.signing_key = self.read_signing_key(config["signing_key_path"])
|
# the signing key can be specified inline or in a separate file
|
||||||
|
if "signing_key" in config:
|
||||||
|
self.signing_key = read_signing_keys([config["signing_key"]])
|
||||||
|
else:
|
||||||
|
self.signing_key = self.read_signing_key(config["signing_key_path"])
|
||||||
|
|
||||||
self.old_signing_keys = self.read_old_signing_keys(
|
self.old_signing_keys = self.read_old_signing_keys(
|
||||||
config.get("old_signing_keys", {})
|
config.get("old_signing_keys", {})
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,7 @@ from twisted.internet import defer, reactor
|
|||||||
|
|
||||||
from synapse.api.constants import EventTypes, RoomVersions
|
from synapse.api.constants import EventTypes, RoomVersions
|
||||||
from synapse.api.errors import CodeMessageException, cs_error
|
from synapse.api.errors import CodeMessageException, cs_error
|
||||||
from synapse.config.server import ServerConfig
|
from synapse.config.homeserver import HomeServerConfig
|
||||||
from synapse.federation.transport import server as federation_server
|
from synapse.federation.transport import server as federation_server
|
||||||
from synapse.http.server import HttpServer
|
from synapse.http.server import HttpServer
|
||||||
from synapse.server import HomeServer
|
from synapse.server import HomeServer
|
||||||
@ -111,14 +111,25 @@ def default_config(name):
|
|||||||
"""
|
"""
|
||||||
Create a reasonable test config.
|
Create a reasonable test config.
|
||||||
"""
|
"""
|
||||||
config = Mock()
|
config_dict = {
|
||||||
config.signing_key = [MockKey()]
|
"server_name": name,
|
||||||
|
"media_store_path": "media",
|
||||||
|
"uploads_path": "uploads",
|
||||||
|
|
||||||
|
# the test signing key is just an arbitrary ed25519 key to keep the config
|
||||||
|
# parser happy
|
||||||
|
"signing_key": "ed25519 a_lPym qvioDNmfExFBRPgdTU+wtFYKq4JfwFRv7sYVgWvmgJg",
|
||||||
|
}
|
||||||
|
|
||||||
|
config = HomeServerConfig()
|
||||||
|
config.parse_config_dict(config_dict)
|
||||||
|
|
||||||
|
# TODO: move this stuff into config_dict or get rid of it
|
||||||
config.event_cache_size = 1
|
config.event_cache_size = 1
|
||||||
config.enable_registration = True
|
config.enable_registration = True
|
||||||
config.enable_registration_captcha = False
|
config.enable_registration_captcha = False
|
||||||
config.macaroon_secret_key = "not even a little secret"
|
config.macaroon_secret_key = "not even a little secret"
|
||||||
config.expire_access_token = False
|
config.expire_access_token = False
|
||||||
config.server_name = name
|
|
||||||
config.trusted_third_party_id_servers = []
|
config.trusted_third_party_id_servers = []
|
||||||
config.room_invite_state_types = []
|
config.room_invite_state_types = []
|
||||||
config.password_providers = []
|
config.password_providers = []
|
||||||
@ -176,13 +187,6 @@ def default_config(name):
|
|||||||
# background, which upsets the test runner.
|
# background, which upsets the test runner.
|
||||||
config.update_user_directory = False
|
config.update_user_directory = False
|
||||||
|
|
||||||
def is_threepid_reserved(threepid):
|
|
||||||
return ServerConfig.is_threepid_reserved(
|
|
||||||
config.mau_limits_reserved_threepids, threepid
|
|
||||||
)
|
|
||||||
|
|
||||||
config.is_threepid_reserved.side_effect = is_threepid_reserved
|
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user