-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make default DB compulsory in URI string format (#15881)
* fix: Use admin as default database when no Mongo DB is specified * fix: Make default db compulsary instead * Added back check during execution per review * Json field spec fix Co-authored-by: Aishwarya UR <[email protected]>
- Loading branch information
1 parent
e255593
commit 10c9f77
Showing
5 changed files
with
83 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2835,4 +2835,18 @@ public void testStaleConnectionOnMongoSocketWriteExceptionOnGetStructure() { | |
.expectErrorMatches(throwable -> throwable instanceof StaleConnectionException) | ||
.verify(); | ||
} | ||
|
||
@Test | ||
public void testValidateDatasource_withoutDefaultDBInURIString_returnsInvalid() { | ||
final DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration(); | ||
List<Property> properties = new ArrayList<>(); | ||
properties.add(new Property("isUriString", "Yes")); | ||
properties.add(new Property("uriString", "mongodb://user:[email protected]/")); | ||
datasourceConfiguration.setProperties(properties); | ||
|
||
final Set<String> strings = pluginExecutor.validateDatasource(datasourceConfiguration); | ||
|
||
assertEquals(1, strings.size()); | ||
assertTrue(strings.contains("Missing default database name.")); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...th-plugins/mongoPlugin/src/test/java/com/external/plugins/utils/MongoPluginUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.external.plugins.utils; | ||
|
||
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException; | ||
import com.appsmith.external.models.DatasourceConfiguration; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
public class MongoPluginUtilsTest { | ||
|
||
@Test | ||
public void testGetDatabaseName_withoutDatabaseName_throwsDatasourceError() { | ||
final AppsmithPluginException exception = assertThrows( | ||
AppsmithPluginException.class, | ||
() -> MongoPluginUtils.getDatabaseName(new DatasourceConfiguration()) | ||
); | ||
|
||
assertEquals("Missing default database name.", exception.getMessage()); | ||
|
||
} | ||
} |