Skip to content

Commit

Permalink
Merge pull request #5393 from ant-media/fix_uri_issue
Browse files Browse the repository at this point in the history
Fix Mongodb URI issue
  • Loading branch information
mekya authored Aug 14, 2023
2 parents a013f49 + cd8ecaf commit 1f2a7c5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/server/create_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ check_result
sed -i $SED_COMPATIBILITY 's^<param-value>/StreamApp^<param-value>/'$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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:[email protected]: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);
Expand Down

0 comments on commit 1f2a7c5

Please sign in to comment.