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
@@ -1246,6 +1246,32 @@ describe('Parse.User testing', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
it('can not set authdata to null', async () => {
|
||||
try {
|
||||
const provider = getMockFacebookProvider();
|
||||
Parse.User._registerAuthenticationProvider(provider);
|
||||
const user = await Parse.User._logInWith('facebook');
|
||||
user.set('authData', null);
|
||||
await user.save();
|
||||
fail();
|
||||
} catch (e) {
|
||||
expect(e.message).toBe('This authentication method is unsupported.');
|
||||
}
|
||||
});
|
||||
|
||||
it('ignore setting authdata to undefined', async () => {
|
||||
const provider = getMockFacebookProvider();
|
||||
Parse.User._registerAuthenticationProvider(provider);
|
||||
const user = await Parse.User._logInWith('facebook');
|
||||
user.set('authData', undefined);
|
||||
await user.save();
|
||||
let authData = user.get('authData');
|
||||
expect(authData).toBe(undefined);
|
||||
await user.fetch();
|
||||
authData = user.get('authData');
|
||||
expect(authData.facebook.id).toBeDefined();
|
||||
});
|
||||
|
||||
it('user authData should be available in cloudcode (#2342)', async done => {
|
||||
Parse.Cloud.define('checkLogin', req => {
|
||||
expect(req.user).not.toBeUndefined();
|
||||
@@ -3924,4 +3950,29 @@ describe('Security Advisory GHSA-8w3j-g983-8jh5', function() {
|
||||
done();
|
||||
}
|
||||
);
|
||||
it_only_db('mongo')('should ignore authData field', async () => {
|
||||
// Add User to Database with authData
|
||||
const database = Config.get(Parse.applicationId).database;
|
||||
const collection = await database.adapter._adaptiveCollection('_User');
|
||||
await collection.insertOne({
|
||||
_id: '1234ABCDEF',
|
||||
name: '<some_name>',
|
||||
email: '<some_email>',
|
||||
username: '<some_username>',
|
||||
_hashed_password: '<some_password>',
|
||||
_auth_data_custom: {
|
||||
id: 'linkedID',
|
||||
},
|
||||
sessionToken: '<some_session_token>',
|
||||
authData: null, // should ignore
|
||||
});
|
||||
const provider = {
|
||||
getAuthType: () => 'custom',
|
||||
restoreAuthentication: () => true,
|
||||
};
|
||||
Parse.User._registerAuthenticationProvider(provider);
|
||||
const query = new Parse.Query(Parse.User);
|
||||
const user = await query.get('1234ABCDEF', { useMasterKey: true });
|
||||
expect(user.get('authData')).toEqual({ custom: { id: 'linkedID' } });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user