fix: mongo uri lowercasing removed (#32375)
## Description > This PR prevents the lowercasing of the URI for the plugins. The URI is now preserved in the same form that the user has added. Fixes #32145 ## Automation /ok-to-test tags="@tag.Datasource" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!IMPORTANT] > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/8592797453> > Commit: `f6dcdc85a4aafdd3329bf7b9de3fa04e583ec340` > Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8592797453&attempt=1" target="_blank">Click here!</a> > All cypress tests have passed 🎉🎉🎉 <!-- end of auto-generated comment: Cypress test results --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Fixed an issue with option processing by retaining the original case of keys, ensuring accurate data handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
parent
5968f87be0
commit
b85cf08a51
|
|
@ -9,6 +9,7 @@ import com.appsmith.external.models.Endpoint;
|
||||||
import com.appsmith.external.models.Property;
|
import com.appsmith.external.models.Property;
|
||||||
import com.appsmith.external.models.SSLDetails;
|
import com.appsmith.external.models.SSLDetails;
|
||||||
import com.external.plugins.exceptions.MongoPluginErrorMessages;
|
import com.external.plugins.exceptions.MongoPluginErrorMessages;
|
||||||
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -131,23 +132,23 @@ public class DatasourceUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String buildURITail(String tailInfo) {
|
private static String buildURITail(String tailInfo) {
|
||||||
Map<String, String> optionsMap = new HashMap<>();
|
// case-insensitive match and preserves order of keys, hence the params ordering in the url remains unchanged
|
||||||
|
Map<String, String> optionsMap = new LinkedCaseInsensitiveMap<>();
|
||||||
for (final String part : tailInfo.split("[&;]")) {
|
for (final String part : tailInfo.split("[&;]")) {
|
||||||
if (part.isEmpty()) {
|
if (part.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int idx = part.indexOf('=');
|
int idx = part.indexOf('=');
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
String key = part.substring(0, idx).toLowerCase();
|
String key = part.substring(0, idx);
|
||||||
String value = part.substring(idx + 1);
|
String value = part.substring(idx + 1);
|
||||||
optionsMap.put(key, value);
|
optionsMap.put(key, value);
|
||||||
} else {
|
} else {
|
||||||
optionsMap.put(part.toLowerCase(), "");
|
optionsMap.put(part, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
optionsMap.putIfAbsent("authsource", "admin");
|
optionsMap.putIfAbsent("authsource", "admin");
|
||||||
optionsMap.put("minpoolsize", "0");
|
optionsMap.putIfAbsent("minpoolsize", "0");
|
||||||
return optionsMap.entrySet().stream()
|
return optionsMap.entrySet().stream()
|
||||||
.map(entry -> {
|
.map(entry -> {
|
||||||
if (StringUtils.hasLength(entry.getValue())) {
|
if (StringUtils.hasLength(entry.getValue())) {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,22 @@ public class DatasourceUtilsTest {
|
||||||
public void testBuildClientURI_withUserInfoAndAuthSource() {
|
public void testBuildClientURI_withUserInfoAndAuthSource() {
|
||||||
|
|
||||||
final String testUri = "mongodb://user:pass@host:port/db?param&authSource=notAdmin";
|
final String testUri = "mongodb://user:pass@host:port/db?param&authSource=notAdmin";
|
||||||
final String resultUri = "mongodb://user:newPass@host:port/db?param&authsource=notAdmin&minpoolsize=0";
|
final String resultUri = "mongodb://user:newPass@host:port/db?param&authSource=notAdmin&minpoolsize=0";
|
||||||
|
|
||||||
|
DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration();
|
||||||
|
final DBAuth dbAuth = new DBAuth();
|
||||||
|
dbAuth.setPassword("newPass");
|
||||||
|
datasourceConfiguration.setAuthentication(dbAuth);
|
||||||
|
datasourceConfiguration.setProperties(List.of(new Property("0", "Yes"), new Property("1", testUri)));
|
||||||
|
final String clientURI = buildClientURI(datasourceConfiguration);
|
||||||
|
assertEquals(resultUri, clientURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuildClientURI_withUpperCaseCharacters_CaseRemainsUnchanged() {
|
||||||
|
|
||||||
|
final String testUri = "mongodb://user:pass@host:port/db?Param&authSource=notAdmin";
|
||||||
|
final String resultUri = "mongodb://user:newPass@host:port/db?Param&authSource=notAdmin&minpoolsize=0";
|
||||||
|
|
||||||
DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration();
|
DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration();
|
||||||
final DBAuth dbAuth = new DBAuth();
|
final DBAuth dbAuth = new DBAuth();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user