Skip to content

Commit 592daf4

Browse files
committed
Added test case that exercises this change
1 parent 603b427 commit 592daf4

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

spec/ParseUser.spec.js

+59
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,65 @@ describe('Parse.User testing', () => {
20612061
})
20622062
});
20632063

2064+
// https://github.com/ParsePlatform/parse-server/issues/1198
2065+
it('should cleanup null authData keys ParseUser update', (done) => {
2066+
Parse.Cloud.beforeSave('_User', (req, res) => {
2067+
req.object.set('foo', 'bar');
2068+
res.success();
2069+
});
2070+
2071+
// Simulate anonymous user save
2072+
new Promise((resolve, reject) => {
2073+
request.post({
2074+
url: 'http://localhost:8378/1/classes/_User',
2075+
headers: {
2076+
'X-Parse-Application-Id': Parse.applicationId,
2077+
'X-Parse-REST-API-Key': 'rest',
2078+
},
2079+
json: {authData: {anonymous: {id: '00000000-0000-0000-0000-000000000001'}}}
2080+
}, (err, res, body) => {
2081+
if (err) {
2082+
reject(err);
2083+
} else {
2084+
resolve(body);
2085+
}
2086+
});
2087+
}).then((user) => {
2088+
// Simulate registration
2089+
return new Promise((resolve, reject) => {
2090+
request.put({
2091+
url: 'http://localhost:8378/1/classes/_User/' + user.objectId,
2092+
headers: {
2093+
'X-Parse-Application-Id': Parse.applicationId,
2094+
'X-Parse-Session-Token': user.sessionToken,
2095+
'X-Parse-REST-API-Key': 'rest',
2096+
},
2097+
json: {
2098+
authData: {anonymous: null},
2099+
user: 'user',
2100+
password: 'password',
2101+
}
2102+
}, (err, res, body) => {
2103+
if (err) {
2104+
reject(err);
2105+
} else {
2106+
resolve(body);
2107+
}
2108+
});
2109+
});
2110+
}).then((user) => {
2111+
expect(typeof user).toEqual('object');
2112+
expect(user.authData).toBeUndefined();
2113+
Parse.Cloud._removeHook('Triggers', 'beforeSave', '_User');
2114+
done();
2115+
}).catch((err) => {
2116+
fail('no request should fail: ' + JSON.stringify(err));
2117+
Parse.Cloud._removeHook('Triggers', 'beforeSave', '_User');
2118+
done();
2119+
});
2120+
});
2121+
2122+
20642123
it('should aftersave with full object', (done) => {
20652124
var hit = 0;
20662125
Parse.Cloud.afterSave('_User', (req, res) => {

src/RestWrite.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ RestWrite.prototype.execute = function() {
7979
return this.expandFilesForExistingObjects();
8080
}).then(() => {
8181
return this.runDatabaseOperation();
82-
}).then(() => {
83-
return this.cleanUserAuthData();
8482
}).then(() => {
8583
return this.handleFollowup();
8684
}).then(() => {
8785
return this.runAfterTrigger();
86+
}).then(() => {
87+
return this.cleanUserAuthData();
8888
}).then(() => {
8989
return this.response;
9090
});

0 commit comments

Comments
 (0)