Skip to content

Don't perform cannAddField check if using master key #1294

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

Closed
wants to merge 1 commit into from
Closed
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
43 changes: 43 additions & 0 deletions spec/DatabaseController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,47 @@ describe('DatabaseController', () => {
fail();
});
});

describe('canAddField is called appropriately', () => {
let adapter = new MongoStorageAdapter('mongodb://localhost:27017/test');
let databaseController = new DatabaseController(adapter, {
collectionPrefix: 'test_'
});

var connectionP = databaseController.connect()

it("is ignored if using master key", done => {
connectionP.then(() => {
databaseController.canAddField = function() {
console.log('error: canAddField was called');
fail();
}

// master key is implied, by not passing in an acl
var object = {};
var query = {};
var acl = {/* no acl field */}
return databaseController.validateObject('SomeObj', object, query, acl).then(done);
}).catch(error => {
console.log('error', error.stack);
fail();
});
});

it("is called with an explicit ACL, canAddField is called", done => {
connectionP.then(() => {
databaseController.canAddField = function() {
done();
}

var object = {};
var query = {};
var acl = {acl: [] /* explicit empty ACL */}
return databaseController.validateObject('SomeObj', object, query, acl);
}).catch(error => {
console.log('error', error.stack);
fail();
});
});
});
});
7 changes: 6 additions & 1 deletion src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,15 @@ DatabaseController.prototype.redirectClassNameForKey = function(className, key)
// This does not update this.schema, because in a situation like a
// batch request, that could confuse other users of the schema.
DatabaseController.prototype.validateObject = function(className, object, query, options) {
var isMaster = !('acl' in options);
let schema;
return this.loadSchema().then(s => {
schema = s;
return this.canAddField(schema, className, object, options.acl || []);

// If we are using the master key, we can always add fields
if (!isMaster) {
return this.canAddField(schema, className, object, options.acl || []);
}
}).then(() => {
return schema.validateObject(className, object, query);
});
Expand Down