[ https://issues.apache.org/jira/browse/CB-8870?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14520135#comment-14520135 ]
ASF GitHub Bot commented on CB-8870: ------------------------------------ Github user nikhilkh commented on a diff in the pull request: https://github.com/apache/cordova-medic/pull/47#discussion_r29376101 --- Diff: bin/medic.js --- @@ -55,6 +181,210 @@ function exclusiveLs(lsPath, excludes) { }); } +function getConfigPath(appPath) { + return path.join(appPath, "config.xml"); +} + +function getCSPPath(appPath) { + return path.join(appPath, "www", "csp-incl.js"); +} + +function addURIToWhitelist(appPath, uri) { + + var configFile = getConfigPath(appPath); + var cspFile = getCSPPath(appPath); + + var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING); + var cspContent = fs.readFileSync(cspFile, DEFAULT_ENCODING); + + // add whitelisting rule allow access to couch server + medicLog("Adding whitelist rule for CouchDB host: " + uri); + var accessOriginTag = "<access origin=\"" + uri + "\" />"; + if (!contains(configContent, accessOriginTag)) { + configContent = configContent.split("</widget>").join(""); + configContent += " " + accessOriginTag + "\n</widget>\n"; + fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING); + } + + // add couchdb address to csp rules + medicLog("Adding CSP rule for CouchDB host: " + uri); + var cspRule = "connect-src " + uri; + if (!contains(cspContent, cspRule)) { + cspContent = cspContent.replace("connect-src", cspRule); + fs.writeFileSync(cspFile, cspContent, DEFAULT_ENCODING); + } +} + +function setEntryPoint(appPath, entryPoint) { + + var configFile = getConfigPath(appPath); + var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING); + + // replace/add start page preference + // check if config.xml already contains <content /> element + medicLog("Setting entry point to " + entryPoint + " in config.xml"); + + if (configContent.match(/<content\s*src=".*"\s*\/>/gi)) { + configContent = configContent.replace( + /<content\s*src=".*"\s*\/>/gi, + "<content src=\"" + entryPoint + "\" />" + ); + + } else { + + // add entry point to config + configContent = configContent.split("</widget>").join("") + + " <content src=\"" + entryPoint + "\" />\n</widget>"; + } + + // write the changes + fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING); +} + +function changeLoadTimeout(appPath, timeout) { + + medicLog("Increasing url loading timeout for android to " + timeout); + + var timeoutRegex = /<preference\s*name\s *= \s*"?loadUrlTimeoutValue"?.*?((\/>)|(>.*?<\/\s*preference>))/i; + var timeoutTag = "<preference name=\"loadUrlTimeoutValue\" value=\"" + timeout + "\" />"; + var timeoutTagWithPlatform = " <platform name=\"android\">\n <preference name=\"loadUrlTimeoutValue\" value=\"120000\" />\n </platform>\n"; + var platformRegex = /<platform\s*name\s *= \s*"android"\s*>/i; + var widgetRegex = /<\/s*widget\s*>/i; + + var configFile = getConfigPath(appPath); + var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING); + + if (timeoutRegex.test(configContent)) { + configContent = configContent.replace(timeoutRegex, timeoutTag); + medicLog("Found \"loadUrlTimeoutValue\" preference, replacing with desired value"); + } else if (platformRegex.test(configContent)) { + var oldPlatformTag = platformRegex.exec(configContent)[0]; + configContent = configContent.replace(platformRegex, oldPlatformTag + "\n " + timeoutTag); + medicLog("Found platform tag, appending \"loadUrlTimeoutValue\" preference"); + } else if (widgetRegex.test(configContent)) { + var oldWidgetTag = widgetRegex.exec(configContent)[0]; + configContent = configContent.replace(widgetRegex, timeoutTagWithPlatform + oldWidgetTag); + medicLog("Did not find platform tag, adding preference with platform tag"); + } else { + medicLog("Warning: could not modify config.xml for android: no <widget> tag found!"); + } + + // write the changes + fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING); +} + +function setWindowsTargetStoreVersion(appPath, version) { + + medicLog('setting target store version to ' + version); + + var configFile = getConfigPath(appPath); + var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING); + + var versionPreference = ' <preference name="windows-target-version" value="' + version + '" />'; + configContent = configContent.replace('</widget>', versionPreference + '\r\n</widget>'); + + fs.writeFileSync(configFile, configContent, "utf8"); +} + +function androidSpecifics(argv) { --- End diff -- +1 Please provide meaningful names. > Medic should display test failures in build status > -------------------------------------------------- > > Key: CB-8870 > URL: https://issues.apache.org/jira/browse/CB-8870 > Project: Apache Cordova > Issue Type: Improvement > Components: Medic > Affects Versions: Master > Reporter: Dmitry Blotsky > Labels: improvement, medic > Original Estimate: 72h > Remaining Estimate: 72h > -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org