From ba4ef06c7806104a131650034776317643359810 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Sat, 22 Jul 2023 00:56:50 +0530 Subject: [PATCH 1/9] fix Mogodb URI issue --- src/main/java/io/antmedia/console/AdminApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/antmedia/console/AdminApplication.java b/src/main/java/io/antmedia/console/AdminApplication.java index 77135c83c..5376d9298 100644 --- a/src/main/java/io/antmedia/console/AdminApplication.java +++ b/src/main/java/io/antmedia/console/AdminApplication.java @@ -527,7 +527,6 @@ public Process getProcess(String command) throws IOException { if (param.matches(".*[;&|<>()$`\\r\\n\\t*?{}\\[\\]\\\\\"'\\s].*")) { logger.warn("Command includes special characters. Escaping the special characters. Argument:{} and full command:{}", param, command); - param = "'" + param + "'"; } parametersToRun[i] = param; } From 9de3bc9f3f92281fa0a6fff42ee04cab28164b69 Mon Sep 17 00:00:00 2001 From: USAMA Date: Fri, 28 Jul 2023 17:15:09 +0530 Subject: [PATCH 2/9] Fix application not getting created in cluster mode with mongodb uri --- src/main/java/io/antmedia/console/AdminApplication.java | 1 + src/main/server/create_app.sh | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/io/antmedia/console/AdminApplication.java b/src/main/java/io/antmedia/console/AdminApplication.java index 5376d9298..77135c83c 100644 --- a/src/main/java/io/antmedia/console/AdminApplication.java +++ b/src/main/java/io/antmedia/console/AdminApplication.java @@ -527,6 +527,7 @@ public Process getProcess(String command) throws IOException { if (param.matches(".*[;&|<>()$`\\r\\n\\t*?{}\\[\\]\\\\\"'\\s].*")) { logger.warn("Command includes special characters. Escaping the special characters. Argument:{} and full command:{}", param, command); + param = "'" + param + "'"; } parametersToRun[i] = param; } 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 From 5d3d9d7300821e93b2bfa052bc50f814c05b03b4 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Thu, 10 Aug 2023 16:07:06 +0530 Subject: [PATCH 3/9] Add Test Case --- .../ConsoleAppRestServiceTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java index f32745e47..5c8e186a8 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,69 @@ public void testCreateAppShellBug() { fail(e.getMessage()); } } + @Test + public void testQuotesBug() { + + String installLocation = "/usr/local/antmedia"; + + String command = installLocation + "/create_app.sh -c true -n testapp -m 'mongodb://user:password@127.0.0.1:27018/admin?readPreference=secondaryPreferred' " + installLocation; + + try { + + Process 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("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); From 3b8abcebcb0780bedc0c49cabbc5927994366516 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Thu, 10 Aug 2023 19:44:57 +0530 Subject: [PATCH 4/9] add sudo to create app --- .../java/io/antmedia/integration/ConsoleAppRestServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java index 5c8e186a8..eb7634a2a 100644 --- a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java +++ b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java @@ -300,7 +300,7 @@ public void testQuotesBug() { String installLocation = "/usr/local/antmedia"; - String command = installLocation + "/create_app.sh -c true -n testapp -m 'mongodb://user:password@127.0.0.1:27018/admin?readPreference=secondaryPreferred' " + installLocation; + 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 { From b958f68301ff8c229bffe148383ac37ac7d69a21 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Fri, 11 Aug 2023 00:30:31 +0530 Subject: [PATCH 5/9] fix test case --- .../io/antmedia/integration/ConsoleAppRestServiceTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java index eb7634a2a..85c7789d6 100644 --- a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java +++ b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java @@ -306,6 +306,9 @@ public void testQuotesBug() { Process exec = Runtime.getRuntime().exec(command); + exec = Runtime.getRuntime().exec("rm -rf " + installLocation + "/webapps/root/testapp.war "); + assertEquals(0, exec.waitFor()); + InputStream errorStream = exec.getErrorStream(); byte[] data = new byte[1024]; int length = 0; @@ -347,7 +350,7 @@ public void testQuotesBug() { assert(true); } - exec = Runtime.getRuntime().exec("rm -rf " + installLocation + "/webapps/testapp "); + exec = Runtime.getRuntime().exec("sudo rm -rf " + installLocation + "/webapps/testapp "); assertEquals(0, exec.waitFor()); } catch (IOException e) { From 72cec59513be097ebb935e59ef42ff5ce7ca0d46 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Fri, 11 Aug 2023 11:00:45 +0530 Subject: [PATCH 6/9] fix test case --- .../java/io/antmedia/integration/ConsoleAppRestServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java index 85c7789d6..0bb3f56c0 100644 --- a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java +++ b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java @@ -306,7 +306,7 @@ public void testQuotesBug() { Process exec = Runtime.getRuntime().exec(command); - exec = Runtime.getRuntime().exec("rm -rf " + installLocation + "/webapps/root/testapp.war "); + exec = Runtime.getRuntime().exec("sudo rm -rf " + installLocation + "/webapps/root/testapp.war "); assertEquals(0, exec.waitFor()); InputStream errorStream = exec.getErrorStream(); From da2987a9ab7e9cfa79ba21b8678f624884e54d8f Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Fri, 11 Aug 2023 11:22:56 +0530 Subject: [PATCH 7/9] fix test case --- .../integration/ConsoleAppRestServiceTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java index 0bb3f56c0..2d27d47e0 100644 --- a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java +++ b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java @@ -305,10 +305,12 @@ public void testQuotesBug() { try { Process exec = Runtime.getRuntime().exec(command); - - exec = Runtime.getRuntime().exec("sudo rm -rf " + installLocation + "/webapps/root/testapp.war "); - assertEquals(0, exec.waitFor()); - + File tempFile = new File(installLocation + "/webapps/root/testapp.war"); + boolean exists = tempFile.exists(); + if(exists) { + exec = Runtime.getRuntime().exec("sudo rm -rf " + installLocation + "/webapps/root/testapp.war"); + assertEquals(0, exec.waitFor()); + } InputStream errorStream = exec.getErrorStream(); byte[] data = new byte[1024]; int length = 0; From ce908cb7cd9bfa4f6fbcb8a86c792e8e80957833 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Fri, 11 Aug 2023 11:53:44 +0530 Subject: [PATCH 8/9] fix test case --- .../antmedia/integration/ConsoleAppRestServiceTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java index 2d27d47e0..a3ec8e0a2 100644 --- a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java +++ b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java @@ -303,14 +303,17 @@ public void testQuotesBug() { 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(); - Process exec = Runtime.getRuntime().exec(command); - File tempFile = new File(installLocation + "/webapps/root/testapp.war"); - boolean exists = tempFile.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; From 5b551d369ee3ce79c29177ff248304af4026e2a3 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Fri, 11 Aug 2023 11:56:39 +0530 Subject: [PATCH 9/9] fix test case --- .../java/io/antmedia/integration/ConsoleAppRestServiceTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java index a3ec8e0a2..ee23d7687 100644 --- a/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java +++ b/src/test/java/io/antmedia/integration/ConsoleAppRestServiceTest.java @@ -306,7 +306,6 @@ public void testQuotesBug() { 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());