Skip to content
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

Apply credential stripping to all untransforms for _User #1498

Merged
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
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