Skip to content

Commit

Permalink
#26481 include in 23.10.24
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Dec 5, 2023
1 parent b65dbfa commit 9ddf536
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
7 changes: 7 additions & 0 deletions dotCMS/hotfix_tracking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## DOTCMS BACKPORT LIST

This maintenance release includes the following code fixes:

**Release-23.10.24 LTS**

1. https://github.com/dotCMS/core/issues/26481 : Pubsub Connection should prefer SSL #26481
14 changes: 12 additions & 2 deletions dotCMS/src/main/java/com/dotcms/dotpubsub/PgNgDataSourceUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
*/
class PgNgDataSourceUrl {

static final String SSL_MODE = System.getenv("DOT_PUBSUB_SSL_MODE") != null ? System.getenv("DOT_PUBSUB_SSL_MODE") : "prefer";
private final String finalUrl;

/**
Expand Down Expand Up @@ -66,7 +66,17 @@ private String createUrl(final String username, final String password, final Str
sw.append("/");
sw.append(data[data.length - 1]);

return sw.toString();
if(url.contains("ssl.mode=")){
return sw.toString();
}
if(url.contains("?")){
sw.append( "&");
}else{
sw.append( "?");
}

sw.append("ssl.mode=" + SSL_MODE);
return sw.toString();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotcms.dotpubsub;

import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.junit.BeforeClass;
Expand All @@ -11,9 +12,9 @@ public class PgNgDataSourceUrlTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {}



final String PgNgUrl = "jdbc:pgsql://dotcmsUserName:dotcmsPassword@dbServer.com/dotcms";

final String PgNgUrl = "jdbc:pgsql://dotcmsUserName:dotcmsPassword@dbServer.com/dotcms?ssl.mode=" + PgNgDataSourceUrl.SSL_MODE;



Expand Down Expand Up @@ -72,8 +73,27 @@ public void test_PgNgDataSourceUrl_URL_escapes_special_chars() {


}



@Test
public void test_ssl_mode_is_added() throws MalformedURLException {

String url = "jdbc:postgresql://dbServer.com/dotcms";
String username = "username";
String password = "password";


PgNgDataSourceUrl testDataSource = new PgNgDataSourceUrl(username, password, url);

assert testDataSource.getDbUrl().contains("?ssl.mode=" + PgNgDataSourceUrl.SSL_MODE);

url = "jdbc:postgresql://dbServer.com/dotcms?test=here";


testDataSource = new PgNgDataSourceUrl(username, password, url);

assert testDataSource.getDbUrl().contains("&ssl.mode=" + PgNgDataSourceUrl.SSL_MODE);

}

}

0 comments on commit 9ddf536

Please sign in to comment.