Case insensitive signup (#5634)

* Always delete data after each, even for mongo.

* Add failing simple case test

* run all tests

* 1. when validating username be case insensitive

2. add _auth_data_anonymous to specialQueryKeys...whatever that is!

* More case sensitivity

1. also make email validation case insensitive
2. update comments to reflect what this change does

* wordsmithery and grammar

* first pass at a preformant case insensitive query.  mongo only so far.

* change name of parameter from insensitive to
caseInsensitive

* Postgres support

* properly handle auth data null

* wip

* use 'caseInsensitive' instead of 'insensitive' in all places.

* update commenet to reclect current plan

* skip the mystery test for now

* create case insensitive indecies for
mongo to support case insensitive
checks for email and username

* remove unneeded specialKey

* pull collation out to a function.

* not sure what i planned
to do with this test.
removing.

* remove typo

* remove another unused flag

* maintain order

* maintain order of params

* boil the ocean on param sequence
i like having explain last cause it seems
like something you would
change/remove after getting what you want
from the explain?

* add test to verify creation
and use of caseInsensitive index

* add no op func to prostgress

* get collation object from mongocollection
make flow lint happy by declaring things Object.

* fix typo

* add changelog

* kick travis

* properly reference static method

* add a test to confirm that anonymous users with
unique username that do collide when compared
insensitively can still be created.

* minot doc nits

* add a few tests to make sure our spy is working as expected
wordsmith the changelog

Co-authored-by: Diamond Lewis <findlewis@gmail.com>
This commit is contained in:
Arthur Cinader
2020-02-14 09:44:51 -08:00
committed by GitHub
parent 1ea3f864a8
commit fd0b535159
10 changed files with 413 additions and 35 deletions

View File

@@ -704,13 +704,21 @@ RestWrite.prototype._validateUserName = function() {
}
return Promise.resolve();
}
// We need to a find to check for duplicate username in case they are missing the unique index on usernames
// TODO: Check if there is a unique index, and if so, skip this query.
/*
Usernames should be unique when compared case insensitively
Users should be able to make case sensitive usernames and
login using the case they entered. I.e. 'Snoopy' should preclude
'snoopy' as a valid username.
*/
return this.config.database
.find(
this.className,
{ username: this.data.username, objectId: { $ne: this.objectId() } },
{ limit: 1 },
{
username: this.data.username,
objectId: { $ne: this.objectId() },
},
{ limit: 1, caseInsensitive: true },
{},
this.validSchemaController
)
@@ -725,6 +733,18 @@ RestWrite.prototype._validateUserName = function() {
});
};
/*
As with usernames, Parse should not allow case insensitive collisions of email.
unlike with usernames (which can have case insensitive collisions in the case of
auth adapters), emails should never have a case insensitive collision.
This behavior can be enforced through a properly configured index see:
https://docs.mongodb.com/manual/core/index-case-insensitive/#create-a-case-insensitive-index
which could be implemented instead of this code based validation.
Given that this lookup should be a relatively low use case and that the case sensitive
unique index will be used by the db for the query, this is an adequate solution.
*/
RestWrite.prototype._validateEmail = function() {
if (!this.data.email || this.data.email.__op === 'Delete') {
return Promise.resolve();
@@ -738,12 +758,15 @@ RestWrite.prototype._validateEmail = function() {
)
);
}
// Same problem for email as above for username
// Case insensitive match, see note above function.
return this.config.database
.find(
this.className,
{ email: this.data.email, objectId: { $ne: this.objectId() } },
{ limit: 1 },
{
email: this.data.email,
objectId: { $ne: this.objectId() },
},
{ limit: 1, caseInsensitive: true },
{},
this.validSchemaController
)