From c8b6129bce87f4f4d42bc49d315f7394b4788c4f Mon Sep 17 00:00:00 2001 From: Mattia Faraci Date: Sun, 12 Nov 2023 01:07:44 +0100 Subject: [PATCH] Fix enableCollationCaseComparison, caseInsensitive and test --- spec/DatabaseController.spec.js | 2 +- src/Controllers/DatabaseController.js | 30 ++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/spec/DatabaseController.spec.js b/spec/DatabaseController.spec.js index 4633f1c26f..e1b50a5a52 100644 --- a/spec/DatabaseController.spec.js +++ b/spec/DatabaseController.spec.js @@ -515,7 +515,7 @@ describe('DatabaseController', function () { it('should not find a case insensitive user by email with convertEmailToLowercase', async () => { await reconfigureServer({ convertEmailToLowercase: true }); const user = new Parse.User(); - await user.save({ email: 'EXAMPLE@EXAMPLE.COM', password: 'password' }); + await user.save({ username: 'EXAMPLE', email: 'EXAMPLE@EXAMPLE.COM', password: 'password' }); const query = new Parse.Query(Parse.User); query.equalTo('email', 'EXAMPLE@EXAMPLE.COM'); diff --git a/src/Controllers/DatabaseController.js b/src/Controllers/DatabaseController.js index c1dbfdacfe..5975e94053 100644 --- a/src/Controllers/DatabaseController.js +++ b/src/Controllers/DatabaseController.js @@ -1235,7 +1235,7 @@ class DatabaseController { keys, readPreference, hint, - caseInsensitive, + caseInsensitive: this.options.enableCollationCaseComparison ? false : caseInsensitive, explain, }; Object.keys(sort).forEach(fieldName => { @@ -1739,25 +1739,27 @@ class DatabaseController { throw error; }); - await this.adapter - .ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true) - .catch(error => { - logger.warn('Unable to create case insensitive username index: ', error); - throw error; - }); + if (!this.options.enableCollationCaseComparison) { + await this.adapter + .ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true) + .catch(error => { + logger.warn('Unable to create case insensitive username index: ', error); + throw error; + }); + + await this.adapter + .ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true) + .catch(error => { + logger.warn('Unable to create case insensitive email index: ', error); + throw error; + }); + } await this.adapter.ensureUniqueness('_User', requiredUserFields, ['email']).catch(error => { logger.warn('Unable to ensure uniqueness for user email addresses: ', error); throw error; }); - await this.adapter - .ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true) - .catch(error => { - logger.warn('Unable to create case insensitive email index: ', error); - throw error; - }); - await this.adapter.ensureUniqueness('_Role', requiredRoleFields, ['name']).catch(error => { logger.warn('Unable to ensure uniqueness for role name: ', error); throw error;