Пример #1
0
def test_escape_json_control_chars(monkeypatch):
    str1 = r"hello\nworld"
    escaped_str1 = r"hello\\nworld"
    assert escaped_str1 == utils.escape_json_control_chars(str1)

    str1 = r"hello\rworld"
    escaped_str1 = r"hello\\rworld"
    assert escaped_str1 == utils.escape_json_control_chars(str1)

    str1 = r"hello\r\nworld"
    escaped_str1 = r"hello\\r\\nworld"
    assert escaped_str1 == utils.escape_json_control_chars(str1)
Пример #2
0
 def handleEdit(self, confInfo):
     logger.info("start edit setup configure.")
     scheme, host, port = utils.extract_http_scheme_host_port(
         scc.getMgmtUri())
     conf_mgr = conf.ConfManager(self.getSessionKey(),
                                 self.appName,
                                 scheme=scheme,
                                 host=host,
                                 port=port)
     ta_conf_file = get_or_create_conf_file(conf_mgr, setup_const.myta_conf)
     customized_conf_file = get_or_create_conf_file(
         conf_mgr, setup_const.myta_customized_conf)
     all_origin_settings = ta_conf_file.get_all()
     all_settings = utils.escape_json_control_chars(
         self.callerArgs.data[setup_const.all_settings][0])
     all_settings = json.loads(all_settings)
     # write global and proxy settings
     self._updateGlobalSettings(setup_const.global_settings, all_settings,
                                all_origin_settings, ta_conf_file)
     self._updateGlobalSettings(setup_const.proxy_settings, all_settings,
                                all_origin_settings, ta_conf_file)
     # write customized settings
     customized_conf_file = get_or_create_conf_file(
         conf_mgr, setup_const.myta_customized_conf)
     self._updateConfStanzas(
         all_settings.get(setup_const.myta_customized_settings, {}),
         customized_conf_file, self.encrypt_fields_customized)
     logger.info("edit setup configure is done")
Пример #3
0
    def handleList(self, confInfo):
        logger.info("start list setup configure.")
        scheme, host, port = utils.extract_http_scheme_host_port(
            scc.getMgmtUri())
        conf_mgr = conf.ConfManager(self.getSessionKey(),
                                    self.appName,
                                    scheme=scheme,
                                    host=host,
                                    port=port)
        ta_conf_file = get_or_create_conf_file(conf_mgr, setup_const.myta_conf)
        # read globala and proxy settings
        all_settings = ta_conf_file.get_all()
        if not all_settings:
            all_settings = {}
        self._setNoneValues(all_settings.get(setup_const.global_settings, {}))
        # customized conf
        customized_conf_file = get_or_create_conf_file(
            conf_mgr, setup_const.myta_customized_conf)
        settings = customized_conf_file.get_all()
        all_settings[setup_const.myta_customized_settings] = settings

        self._clearPasswords(all_settings, self.cred_fields)
        all_settings = filter_eai_property(all_settings)
        all_settings = json.dumps(all_settings)
        all_settings = utils.escape_json_control_chars(all_settings)
        confInfo[setup_const.myta_settings].append(setup_const.all_settings,
                                                   all_settings)
        logger.info("list setup configure is done.")
Пример #4
0
 def handleEdit(self, confInfo):
     logger.info("start edit setup configure.")
     scheme, host, port = utils.extract_http_scheme_host_port(
         scc.getMgmtUri())
     conf_mgr = conf.ConfManager(self.getSessionKey(),
                                 self.appName,
                                 scheme=scheme,
                                 host=host,
                                 port=port)
     ta_conf_file = get_or_create_conf_file(conf_mgr, setup_const.myta_conf)
     customized_conf_file = get_or_create_conf_file(
         conf_mgr, setup_const.myta_customized_conf)
     all_origin_settings = ta_conf_file.get_all()
     all_settings = utils.escape_json_control_chars(
         self.callerArgs.data[setup_const.all_settings][0])
     all_settings = json.loads(all_settings)
     # write global and proxy settings
     self._updateGlobalSettings(setup_const.global_settings, all_settings,
                                all_origin_settings, ta_conf_file)
     # write customized settings
     customized_conf_file = get_or_create_conf_file(
         conf_mgr, setup_const.myta_customized_conf)
     self._updateConfStanzas(
         all_settings.get(setup_const.myta_customized_settings, {}),
         customized_conf_file, self.encrypt_fields_customized)
     # write account credential settings
     for cred, conf_file in self.cred_confs:
         cred_conf_file = get_or_create_conf_file(conf_mgr, conf_file)
         creds = all_settings.get(cred, {})
         if creds == setup_const.ignore_backend_req:
             logger.info("Ignore backend rest request")
             continue
         if creds:
             self._updateConfStanzas(creds, cred_conf_file,
                                     self.encrypt_fields_credential)
     logger.info("edit setup configure is done")