Throw error when setting authData to null (#6154)
* added ignore authData field * add fix for Postgres * add test for mongoDB * add test login with provider despite invalid authData * removed fit * fixed ignoring authData in postgres * Fix postgres test * Throw error instead of ignore * improve tests * Add mongo test * allow authData when not user class * fix tests * more tests * add condition to synthesize authData field only in _User class it is forbidden to add a custom field name beginning with `_`, so if the object is not `_User` , the transform should throw * add warning log when ignoring invalid `authData` in `_User` * add test to throw when custom field begins with underscore
This commit is contained in:
committed by
Diamond Lewis
parent
1c8d4a6519
commit
9d781c481f
@@ -1403,10 +1403,19 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
|
||||
case 'times_used':
|
||||
restObject['timesUsed'] = mongoObject[key];
|
||||
break;
|
||||
case 'authData':
|
||||
if (className === '_User') {
|
||||
log.warn(
|
||||
'ignoring authData in _User as this key is reserved to be synthesized of `_auth_data_*` keys'
|
||||
);
|
||||
} else {
|
||||
restObject['authData'] = mongoObject[key];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Check other auth data keys
|
||||
var authDataMatch = key.match(/^_auth_data_([a-zA-Z0-9_]+)$/);
|
||||
if (authDataMatch) {
|
||||
if (authDataMatch && className === '_User') {
|
||||
var provider = authDataMatch[1];
|
||||
restObject['authData'] = restObject['authData'] || {};
|
||||
restObject['authData'][provider] = mongoObject[key];
|
||||
|
||||
@@ -417,8 +417,21 @@ RestWrite.prototype.validateAuthData = function() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.data.authData || !Object.keys(this.data.authData).length) {
|
||||
if (
|
||||
(this.data.authData && !Object.keys(this.data.authData).length) ||
|
||||
!Object.prototype.hasOwnProperty.call(this.data, 'authData')
|
||||
) {
|
||||
// Handle saving authData to {} or if authData doesn't exist
|
||||
return;
|
||||
} else if (
|
||||
Object.prototype.hasOwnProperty.call(this.data, 'authData') &&
|
||||
!this.data.authData
|
||||
) {
|
||||
// Handle saving authData to null
|
||||
throw new Parse.Error(
|
||||
Parse.Error.UNSUPPORTED_SERVICE,
|
||||
'This authentication method is unsupported.'
|
||||
);
|
||||
}
|
||||
|
||||
var authData = this.data.authData;
|
||||
|
||||
Reference in New Issue
Block a user