Skip to content

Commit 961abda

Browse files
georgesjamousflovilmart
authored andcommitted
"Object not found." instead of "Insufficient auth." when using master key (#5133)
* add additional isMaster check * adding some tests * nits * covering all basis
1 parent de79b70 commit 961abda

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

spec/ParseUser.spec.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3314,7 +3314,9 @@ describe('Parse.User testing', () => {
33143314
done();
33153315
});
33163316
});
3317-
}).pend('this test fails. See: https://github.com/parse-community/parse-server/issues/5097');
3317+
}).pend(
3318+
'this test fails. See: https://github.com/parse-community/parse-server/issues/5097'
3319+
);
33183320

33193321
it('should be able to update user with authData passed', done => {
33203322
let objectId;
@@ -3686,6 +3688,35 @@ describe('Parse.User testing', () => {
36863688
.then(done, done.fail);
36873689
});
36883690

3691+
it('should throw OBJECT_NOT_FOUND instead of SESSION_MISSING when using masterKey', async () => {
3692+
// create a fake user (just so we simulate an object not found)
3693+
const non_existent_user = Parse.User.createWithoutData('fake_id');
3694+
try {
3695+
await non_existent_user.destroy({ useMasterKey: true });
3696+
throw '';
3697+
} catch (e) {
3698+
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
3699+
}
3700+
try {
3701+
await non_existent_user.save({}, { useMasterKey: true });
3702+
throw '';
3703+
} catch (e) {
3704+
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
3705+
}
3706+
try {
3707+
await non_existent_user.save();
3708+
throw '';
3709+
} catch (e) {
3710+
expect(e.code).toBe(Parse.Error.SESSION_MISSING);
3711+
}
3712+
try {
3713+
await non_existent_user.destroy();
3714+
throw '';
3715+
} catch (e) {
3716+
expect(e.code).toBe(Parse.Error.SESSION_MISSING);
3717+
}
3718+
});
3719+
36893720
describe('issue #4897', () => {
36903721
it_only_db('mongo')(
36913722
'should be able to login with a legacy user (no ACL)',

src/rest.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,13 @@ function update(config, auth, className, restWhere, restObject, clientSDK) {
250250
});
251251
}
252252

253-
function handleSessionMissingError(error, className) {
253+
function handleSessionMissingError(error, className, auth) {
254254
// If we're trying to update a user without / with bad session token
255-
if (className === '_User' && error.code === Parse.Error.OBJECT_NOT_FOUND) {
255+
if (
256+
className === '_User' &&
257+
error.code === Parse.Error.OBJECT_NOT_FOUND &&
258+
!auth.isMaster
259+
) {
256260
throw new Parse.Error(Parse.Error.SESSION_MISSING, 'Insufficient auth.');
257261
}
258262
throw error;

0 commit comments

Comments
 (0)