From 2c6d1bb3615db36a26e7d927a4347dfc920f8aee Mon Sep 17 00:00:00 2001 From: Sumit Kumar Date: Wed, 18 Nov 2020 16:55:39 +0530 Subject: [PATCH] Fix mongodb datasource test. (#1783) 1. Fix mongodb datasource cypress test failure. 2. Against certain mongodb instances, we expect to receive an exception of type "unauthorized" when testing datasource. Earlier, this case was caught and whitelisted until the recent change to replace mongodb infra with reactive mongodb infra. --- .../java/com/external/plugins/MongoPlugin.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java b/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java index 803b8a81f6..1609f591b4 100644 --- a/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java +++ b/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java @@ -341,7 +341,19 @@ public class MongoPlugin extends BasePlugin { }) .then(Mono.just(new DatasourceTestResult())) .onErrorResume(error -> { - return Mono.just(new DatasourceTestResult(error.getMessage()));}); + /** + * 1. Return OK response on "Unauthorized" exception. + * 2. If we get an exception with error code "Unauthorized" then it means that the connection to + * the MongoDB instance is valid. It also means we don't have access to the admin database, + * but that's okay for our purposes here. + */ + if(error instanceof MongoCommandException && + ((MongoCommandException) error).getErrorCodeName().equals("Unauthorized")) { + return Mono.just(new DatasourceTestResult()); + } + + return Mono.just(new DatasourceTestResult(error.getMessage())); + }); } @Override