Comparing version 0.6.18 to 0.6.19
Baucis Change Log | ||
================= | ||
v0.6.19 | ||
------- | ||
Better error handling when detecing selected fields when populating via query. | ||
v0.6.18 | ||
@@ -5,0 +10,0 @@ ------- |
@@ -35,3 +35,3 @@ // __Module Definition__ | ||
var populate; | ||
var error; | ||
var error = null; | ||
var query = request.baucis.query; | ||
@@ -59,8 +59,9 @@ | ||
populate.forEach(function (field) { | ||
if (error) return; | ||
if (request.app.checkBadSelection(field.path || field)) { | ||
return next(new Error('Including excluded fields is not permitted.')); | ||
return error = new Error('Including excluded fields is not permitted.'); | ||
} | ||
// Don't allow selecting fields from client when populating | ||
if (field.select) { | ||
return next(new Error('May not set selected fields of populated document.')); | ||
return error = new Error('May not set selected fields of populated document.'); | ||
} | ||
@@ -72,4 +73,4 @@ | ||
next(); | ||
next(error); | ||
} | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/wprl/baucis", | ||
"version": "0.6.18", | ||
"version": "0.6.19", | ||
"main": "index.js", | ||
@@ -8,0 +8,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
baucis v0.6.18 | ||
baucis v0.6.19 | ||
============== | ||
@@ -3,0 +3,0 @@ |
@@ -41,3 +41,3 @@ var expect = require('expect.js'); | ||
it('should use JSON content type', function (done) { | ||
it('should use JSON content type', function (done) { | ||
var options = { | ||
@@ -44,0 +44,0 @@ url: 'http://localhost:8012/api/v1/vegetables', |
@@ -136,3 +136,3 @@ var expect = require('expect.js'); | ||
var options = { | ||
url: 'http://localhost:8012/api/v1/vegetables?populate={ "path": "", "select": "arbitrary" }', | ||
url: 'http://localhost:8012/api/v1/vegetables?populate={ "path": "a", "select": "arbitrary" }', | ||
json: true | ||
@@ -148,2 +148,15 @@ }; | ||
it('should not crash when disallowing selecting fields when populating', function (done) { | ||
var options = { | ||
url: 'http://localhost:8012/api/v1/vegetables?populate=[{ "path": "a", "select": "arbitrary actuary" }, { "path": "b", "select": "arbitrary actuary" }]', | ||
json: true | ||
}; | ||
request.get(options, function (error, response, body) { | ||
if (error) return done(error); | ||
expect(response).to.have.property('statusCode', 500); | ||
expect(body).to.match(/May not set selected fields of populated document[.]/i); | ||
done(); | ||
}); | ||
}); | ||
it('should allow selecting fields', function (done) { | ||
@@ -150,0 +163,0 @@ var options = { |
562037
2928