def setup_test_homeserver(name="test", datastore=None, config=None, **kargs): """Setup a homeserver suitable for running tests against. Keyword arguments are passed to the Homeserver constructor. If no datastore is supplied a datastore backed by an in-memory sqlite db will be given to the HS. """ if config is None: config = Mock() config.signing_key = [MockKey()] config.event_cache_size = 1 config.disable_registration = False config.macaroon_secret_key = "not even a little secret" config.server_name = "server.under.test" if "clock" not in kargs: kargs["clock"] = MockClock() if datastore is None: db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer(name, db_pool=db_pool, config=config, version_string="Synapse/tests", database_engine=create_engine("sqlite3"), **kargs) else: hs = HomeServer(name, db_pool=None, datastore=datastore, config=config, version_string="Synapse/tests", database_engine=create_engine("sqlite3"), **kargs) # bcrypt is far too slow to be doing in unit tests def swap_out_hash_for_testing(old_build_handlers): def build_handlers(): handlers = old_build_handlers() auth_handler = handlers.auth_handler auth_handler.hash = lambda p: hashlib.md5(p).hexdigest() auth_handler.validate_hash = lambda p, h: hashlib.md5(p).hexdigest( ) == h return handlers return build_handlers hs.build_handlers = swap_out_hash_for_testing(hs.build_handlers) defer.returnValue(hs)
def setup_test_homeserver(name="test", datastore=None, config=None, **kargs): """Setup a homeserver suitable for running tests against. Keyword arguments are passed to the Homeserver constructor. If no datastore is supplied a datastore backed by an in-memory sqlite db will be given to the HS. """ if config is None: config = Mock() config.signing_key = [MockKey()] config.event_cache_size = 1 config.disable_registration = False config.macaroon_secret_key = "not even a little secret" config.server_name = "server.under.test" if "clock" not in kargs: kargs["clock"] = MockClock() if datastore is None: db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( name, db_pool=db_pool, config=config, version_string="Synapse/tests", database_engine=create_engine("sqlite3"), **kargs ) else: hs = HomeServer( name, db_pool=None, datastore=datastore, config=config, version_string="Synapse/tests", database_engine=create_engine("sqlite3"), **kargs ) # bcrypt is far too slow to be doing in unit tests def swap_out_hash_for_testing(old_build_handlers): def build_handlers(): handlers = old_build_handlers() auth_handler = handlers.auth_handler auth_handler.hash = lambda p: hashlib.md5(p).hexdigest() auth_handler.validate_hash = lambda p, h: hashlib.md5(p).hexdigest() == h return handlers return build_handlers hs.build_handlers = swap_out_hash_for_testing(hs.build_handlers) defer.returnValue(hs)
def setup_test_homeserver(name="test", datastore=None, config=None, **kargs): """Setup a homeserver suitable for running tests against. Keyword arguments are passed to the Homeserver constructor. If no datastore is supplied a datastore backed by an in-memory sqlite db will be given to the HS. """ if config is None: config = Mock() config.signing_key = [MockKey()] config.event_cache_size = 1 config.enable_registration = True config.macaroon_secret_key = "not even a little secret" config.server_name = "server.under.test" config.trusted_third_party_id_servers = [] if "clock" not in kargs: kargs["clock"] = MockClock() if datastore is None: db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( name, db_pool=db_pool, config=config, version_string="Synapse/tests", database_engine=create_engine("sqlite3"), get_db_conn=db_pool.get_db_conn, **kargs ) hs.setup() else: hs = HomeServer( name, db_pool=None, datastore=datastore, config=config, version_string="Synapse/tests", database_engine=create_engine("sqlite3"), **kargs ) # bcrypt is far too slow to be doing in unit tests def swap_out_hash_for_testing(old_build_handlers): def build_handlers(): handlers = old_build_handlers() auth_handler = handlers.auth_handler auth_handler.hash = lambda p: hashlib.md5(p).hexdigest() auth_handler.validate_hash = lambda p, h: hashlib.md5(p).hexdigest() == h return handlers return build_handlers hs.build_handlers = swap_out_hash_for_testing(hs.build_handlers) fed = kargs.get("resource_for_federation", None) if fed: server.register_servlets( hs, resource=fed, authenticator=server.Authenticator(hs), ratelimiter=FederationRateLimiter( hs.get_clock(), window_size=hs.config.federation_rc_window_size, sleep_limit=hs.config.federation_rc_sleep_limit, sleep_msec=hs.config.federation_rc_sleep_delay, reject_limit=hs.config.federation_rc_reject_limit, concurrent_requests=hs.config.federation_rc_concurrent ), ) defer.returnValue(hs)
def setup_test_homeserver(name="test", datastore=None, config=None, **kargs): """Setup a homeserver suitable for running tests against. Keyword arguments are passed to the Homeserver constructor. If no datastore is supplied a datastore backed by an in-memory sqlite db will be given to the HS. """ if config is None: config = Mock() config.signing_key = [MockKey()] config.event_cache_size = 1 config.enable_registration = True config.macaroon_secret_key = "not even a little secret" config.server_name = "server.under.test" config.trusted_third_party_id_servers = [] config.room_invite_state_types = [] config.database_config = {"name": "sqlite3"} if "clock" not in kargs: kargs["clock"] = MockClock() if datastore is None: db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer(name, db_pool=db_pool, config=config, version_string="Synapse/tests", database_engine=create_engine(config), get_db_conn=db_pool.get_db_conn, **kargs) hs.setup() else: hs = HomeServer(name, db_pool=None, datastore=datastore, config=config, version_string="Synapse/tests", database_engine=create_engine(config), **kargs) # bcrypt is far too slow to be doing in unit tests def swap_out_hash_for_testing(old_build_handlers): def build_handlers(): handlers = old_build_handlers() auth_handler = handlers.auth_handler auth_handler.hash = lambda p: hashlib.md5(p).hexdigest() auth_handler.validate_hash = lambda p, h: hashlib.md5(p).hexdigest( ) == h return handlers return build_handlers hs.build_handlers = swap_out_hash_for_testing(hs.build_handlers) fed = kargs.get("resource_for_federation", None) if fed: server.register_servlets( hs, resource=fed, authenticator=server.Authenticator(hs), ratelimiter=FederationRateLimiter( hs.get_clock(), window_size=hs.config.federation_rc_window_size, sleep_limit=hs.config.federation_rc_sleep_limit, sleep_msec=hs.config.federation_rc_sleep_delay, reject_limit=hs.config.federation_rc_reject_limit, concurrent_requests=hs.config.federation_rc_concurrent), ) defer.returnValue(hs)