diff --git a/src/main/server/create_app.sh b/src/main/server/create_app.sh index 30e0dffdb..d5941e1d9 100755 --- a/src/main/server/create_app.sh +++ b/src/main/server/create_app.sh @@ -134,6 +134,10 @@ check_result sed -i $SED_COMPATIBILITY 's^/StreamApp^/'$APP_NAME'^' $WEB_XML_FILE check_result +if [[ $MONGO_HOST == \'*\' ]]; then + MONGO_HOST="${MONGO_HOST:1:-1}" +fi + if [[ "$IS_CLUSTER" == "true" ]]; then echo "Cluster mode" sed -i $SED_COMPATIBILITY 's/db.type=.*/db.type='mongodb'/' $RED5_PROPERTIES_FILE diff --git a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java index f32745e47..ee23d7687 100644 --- a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java +++ b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Random; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import io.antmedia.console.rest.CommonRestService; import org.apache.commons.io.FileUtils; @@ -293,7 +295,76 @@ public void testCreateAppShellBug() { fail(e.getMessage()); } } + @Test + public void testQuotesBug() { + + String installLocation = "/usr/local/antmedia"; + + String command = "sudo " + installLocation + "/create_app.sh -c true -n testapp -m 'mongodb://user:password@127.0.0.1:27018/admin?readPreference=secondaryPreferred' " + installLocation; + + try { + Process exec; + File warfile = new File(installLocation + "/webapps/root/testapp.war"); + boolean exists = warfile.exists(); + if(exists) { + exec = Runtime.getRuntime().exec("sudo rm -rf " + installLocation + "/webapps/root/testapp.war"); + assertEquals(0, exec.waitFor()); + } + + exec = Runtime.getRuntime().exec(command); + + InputStream errorStream = exec.getErrorStream(); + byte[] data = new byte[1024]; + int length = 0; + while ((length = errorStream.read(data, 0, data.length)) > 0) + { + System.out.println("error stream -> " + new String(data, 0, length)); + } + + InputStream inputStream = exec.getInputStream(); + while ((length = inputStream.read(data, 0, data.length)) > 0) + { + System.out.println("inputStream stream -> " + new String(data, 0, length)); + } + exec.waitFor(); + File propertiesFile = new File( installLocation + "/webapps/testapp/WEB-INF/red5-web.properties"); + String content = Files.readString(propertiesFile.toPath()); + + Pattern hostPattern = Pattern.compile("db.host=(.*)"); + Matcher hostMatcher = hostPattern.matcher(content); + + if(hostMatcher.find()){ + String host= hostMatcher.group(1); + String expressions [] = {"^'(.*)'$","^\"(.*)\"$"}; //check if host property is wrapped in single or double quotes + + assertEquals(false,host == null || host.equals("")); // check if host is empty + + for(String expression :expressions){ + Pattern quotesPattern = Pattern.compile(expression); + Matcher quotesMatcher = quotesPattern.matcher(host); + boolean match = quotesMatcher.matches(); + if(match){ + System.out.println("Failed: Host property stored in the property file within quotes "); + } + assertEquals(false,match); + } + }else { + System.out.println("host property not found in the file."); + assert(true); + } + + exec = Runtime.getRuntime().exec("sudo rm -rf " + installLocation + "/webapps/testapp "); + assertEquals(0, exec.waitFor()); + + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (InterruptedException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } public String getStreamAppWar(String installLocation) { File file = new File(installLocation);