Skip to content

fix: user object may contain already deleted fields #1442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: alpha
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/__tests__/ParseUser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,74 @@ describe('ParseUser', () => {
});
});

it('user who logs out, deletes attribute, then logs back in has correct attributes', done => {
ParseUser.enableUnsafeCurrentUser();
ParseUser._clearCache();
CoreManager.setRESTController({
request(method, path) {
expect(path).toBe('login');

return Promise.resolve(
{
objectId: 'uid2',
username: 'username',
sessionToken: '123abc',
fieldToBeDeleted: 'This field is returned in the first login but not the second',
},
200
);
},
ajax() {},
});

ParseUser.logIn('username', 'password')
.then(u => {
expect(u.isCurrent()).toBe(true);
expect(u.id).toBe('uid2');
expect(u.get('username')).toBe('username');
expect(u.get('fieldToBeDeleted')).toBe(
'This field is returned in the first login but not the second'
);
CoreManager.setRESTController({
request() {
return Promise.resolve({}, 200);
},
ajax() {},
});
return ParseUser.logOut();
})
.then(() => {
expect(ParseUser.current()).toBe(null);
})
.then(() => {
CoreManager.setRESTController({
request(method, path) {
expect(path).toBe('login');

return Promise.resolve(
{
objectId: 'uid2',
username: 'username',
sessionToken: '123abc',
// We assume fieldToBeDeleted was deleted while user was logged out
},
200
);
},
ajax() {},
});
return ParseUser.logIn('username', 'password');
})
.then(u => {
expect(u.isCurrent()).toBe(true);
expect(u.id).toBe('uid2');
expect(u.get('username')).toBe('username');
expect(u.get('fieldToBeDeleted')).toBe(undefined); // Failing test

done();
});
});

it('can retreive a user with sessionToken (me)', async () => {
ParseUser.disableUnsafeCurrentUser();
ParseUser._clearCache();
Expand Down