Skip to content

requiresAuthentication is self-sufficient for ACL's #3784

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

Merged
merged 3 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 53 additions & 0 deletions spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,4 +1215,57 @@ describe('Class Level Permissions for requiredAuth', () => {
done();
});
});

it('required auth test create/get/update/delete with roles (#3753)', (done) => {
let user;
config.database.loadSchema().then((schema) => {
// Just to create a valid class
return schema.validateObject('Stuff', {foo: 'bar'});
}).then((schema) => {
return schema.setPermissions('Stuff', {
'find': {
'requiresAuthentication': true,
'role:admin': true
},
'create': { 'role:admin': true },
'update': { 'role:admin': true },
'delete': { 'role:admin': true },
'get': {
'requiresAuthentication': true,
'role:admin': true
}
});
}).then(() => {
const stuff = new Parse.Object('Stuff');
stuff.set('foo', 'bar');
return stuff.save(null, {useMasterKey: true}).then(() => {
const query = new Parse.Query('Stuff');
return query.get(stuff.id).then(() => {
done.fail('should not succeed');
}, () => {
return new Parse.Query('Stuff').find();
}).then(() => {
done.fail('should not succeed');
}, () => {
return Promise.resolve();
});
}).then(() => {
return Parse.User.signUp('user', 'password').then((signedUpUser) => {
user = signedUpUser;
const query = new Parse.Query('Stuff');
return query.get(stuff.id, {sessionToken: user.getSessionToken()});
});
});
}).then((result) => {
expect(result.get('foo')).toEqual('bar');
const query = new Parse.Query('Stuff');
return query.find({sessionToken: user.getSessionToken()});
}).then((results) => {
expect(results.length).toBe(1);
done();
}, (e) => {
console.error(e);
done.fail(e);
});
});
})
8 changes: 3 additions & 5 deletions src/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,11 +813,9 @@ export default class SchemaController {
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
'Permission denied, user needs to be authenticated.');
}
// no other CLP than requiresAuthentication
// let's resolve that!
if (Object.keys(perms).length == 1) {
return Promise.resolve();
}
// requiresAuthentication passed, just move forward
// probably would be wise at some point to rename to 'authenticatedUser'
return Promise.resolve();
}

// No matching CLP, let's check the Pointer permissions
Expand Down