Skip to content

Commit

Permalink
Apply credential stripping to all untransforms for _User (parse-commu…
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBrock authored and drew-gross committed Apr 14, 2016
1 parent 34851c0 commit d57e384
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
41 changes: 41 additions & 0 deletions spec/RestQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ var rest = require('../src/rest');
var querystring = require('querystring');
var request = require('request');

var DatabaseAdapter = require('../src/DatabaseAdapter');
var database = DatabaseAdapter.getDatabaseConnection('test', 'test_');

var config = new Config('test');
var nobody = auth.nobody(config);

Expand Down Expand Up @@ -35,6 +38,44 @@ describe('rest query', () => {
});
});

describe('query for user w/ legacy credentials', () => {
var data = {
username: 'blah',
password: 'pass',
sessionToken: 'abc123',
}
describe('without masterKey', () => {
it('has them stripped from results', (done) => {
database.adaptiveCollection('_User').then((collection) => {
return collection.insertOne(data);
}).then(() => {
return rest.find(config, nobody, '_User')
}).then((result) => {
var user = result.results[0];
expect(user.username).toEqual('blah');
expect(user.sessionToken).toBeUndefined();
expect(user.password).toBeUndefined();
done();
});
});
});
describe('with masterKey', () => {
it('has them stripped from results', (done) => {
database.adaptiveCollection('_User').then((collection) => {
return collection.insertOne(data);
}).then(() => {
return rest.find(config, {isMaster: true}, '_User')
}).then((result) => {
var user = result.results[0];
expect(user.username).toEqual('blah');
expect(user.sessionToken).toBeUndefined();
expect(user.password).toBeUndefined();
done();
});
});
});
});

// Created to test a scenario in AnyPic
it('query with include', (done) => {
var photo = {
Expand Down
5 changes: 3 additions & 2 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ DatabaseController.prototype.untransformObject = function(
return object;
}

delete object.authData;
delete object.sessionToken;

if (isMaster || (aclGroup.indexOf(object.objectId) > -1)) {
return object;
}

delete object.authData;
delete object.sessionToken;
return object;
};

Expand Down

0 comments on commit d57e384

Please sign in to comment.