def test_get_password_hash(): assert len(configuration.get_password_hash("")) == 64 assert len(configuration.get_password_hash("1")) == 64 assert len(configuration.get_password_hash("1a")) == 64 for _ in range(100): rand_password = str(uuid.uuid4()) hashed_password = configuration.get_password_hash(rand_password) assert len(hashed_password) == 64 assert not hashed_password == rand_password
async def get_web_interface(require_password): try: web_interface_instance = web_interface.WebInterface({}) web_interface_instance.port = PORT web_interface_instance.should_open_web_interface = False web_interface_instance.requires_password = require_password web_interface_instance.password_hash = configuration.get_password_hash(PASSWORD) interfaces.AbstractInterface.bot_api = (await _init_bot()).octobot_api with mock.patch.object(web_interface_instance, "_register_on_channels", new=mock.AsyncMock()): threading.Thread(target=_start_web_interface, args=(web_interface_instance,)).start() # ensure web interface had time to start or it can't be stopped at the moment await asyncio.sleep(1) yield web_interface_instance finally: await web_interface_instance.stop()
def _handle_special_fields(config, new_config): try: # replace web interface password by its hash before storage web_password_key = constants.UPDATED_CONFIG_SEPARATOR.join([services_constants.CONFIG_CATEGORY_SERVICES, services_constants.CONFIG_WEB, services_constants.CONFIG_WEB_PASSWORD]) if web_password_key in new_config: new_config[web_password_key] = configuration.get_password_hash(new_config[web_password_key]) # add exchange enabled param if missing for key in list(new_config.keys()): values = key.split(constants.UPDATED_CONFIG_SEPARATOR) if values[0] == commons_constants.CONFIG_EXCHANGES and \ values[1] not in config[commons_constants.CONFIG_EXCHANGES]: enabled_key = constants.UPDATED_CONFIG_SEPARATOR.join([commons_constants.CONFIG_EXCHANGES, values[1], commons_constants.CONFIG_ENABLED_OPTION]) if enabled_key not in new_config: new_config[enabled_key] = True except KeyError: pass
def is_valid_password(self, ip, password): return not is_banned(ip) and configuration.get_password_hash(password) == self.password_hash