From 2f1ee2186b98bc47b66c4ea3700972bee45676a3 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Fri, 12 Aug 2016 16:15:55 -0400 Subject: [PATCH] Makes sure _acl is set as empty {} (#2495) * regression test for #2465 * Makes sure _acl is set when locked down - Fixes #2465 --- spec/ParseAPI.spec.js | 33 ++++++++++++++++++++ src/Adapters/Storage/Mongo/MongoTransform.js | 4 +-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/spec/ParseAPI.spec.js b/spec/ParseAPI.spec.js index 61007099..93b43314 100644 --- a/spec/ParseAPI.spec.js +++ b/spec/ParseAPI.spec.js @@ -1478,4 +1478,37 @@ describe('miscellaneous', function() { done(); }); }); + + it_exclude_dbs(['postgres'])('should have _acl when locking down (regression for #2465)', (done) =>  { + let headers = { + 'X-Parse-Application-Id': 'test', + 'X-Parse-REST-API-Key': 'rest' + } + rp({ + method: 'POST', + headers: headers, + uri: 'http://localhost:8378/1/classes/Report', + body: { + ACL: {}, + name: 'My Report' + }, + json: true + }).then(() => { + let config = new Config('test'); + let adapter = config.database.adapter; + return adapter._adaptiveCollection("Report") + .then(collection => collection.find({})) + }).then((results) => { + expect(results.length).toBe(1); + let result = results[0]; + expect(result.name).toEqual('My Report'); + expect(result._wperm).toEqual([]); + expect(result._rperm).toEqual([]); + expect(result._acl).toEqual({}); + done(); + }).catch((err) => { + fail(JSON.stringify(err)); + done(); + }); + }); }); diff --git a/src/Adapters/Storage/Mongo/MongoTransform.js b/src/Adapters/Storage/Mongo/MongoTransform.js index 9ea1742d..31399afb 100644 --- a/src/Adapters/Storage/Mongo/MongoTransform.js +++ b/src/Adapters/Storage/Mongo/MongoTransform.js @@ -341,6 +341,7 @@ const addLegacyACL = restObject => { restObject._wperm.forEach(entry => { _acl[entry] = { w: true }; }); + restObjectCopy._acl = _acl; } if (restObject._rperm) { @@ -351,9 +352,6 @@ const addLegacyACL = restObject => { _acl[entry].r = true; } }); - } - - if (Object.keys(_acl).length > 0) { restObjectCopy._acl = _acl; }