Skip to content

Add test cases for protectedFields when using Find without constraints. #5967

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

Merged
merged 1 commit into from
Aug 25, 2019
Merged
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
38 changes: 38 additions & 0 deletions spec/UserPII.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1122,11 +1122,19 @@ describe('Personally Identifiable Information', () => {
// Even with an authenticated user, Public read ACL should never expose sensitive data.
describe('with another authenticated user', () => {
let anotherUser;
const ANOTHER_EMAIL = 'another@bar.com';

beforeEach(async done => {
return Parse.User.signUp('another', 'abc')
.then(loggedInUser => (anotherUser = loggedInUser))
.then(() => Parse.User.logIn(anotherUser.get('username'), 'abc'))
.then(() =>
anotherUser
.set('email', ANOTHER_EMAIL)
.set('zip', ZIP)
.set('ssn', SSN)
.save()
)
.then(() => done());
});

Expand Down Expand Up @@ -1156,6 +1164,36 @@ describe('Personally Identifiable Information', () => {
.catch(done.fail);
});

it('should not be able to get user PII via API with Find without constraints', done => {
new Parse.Query(Parse.User)
.find()
.then(fetchedUsers => {
const notCurrentUser = fetchedUsers.find(
u => u.id !== anotherUser.id
);
expect(notCurrentUser.get('email')).toBe(undefined);
expect(notCurrentUser.get('zip')).toBe(undefined);
expect(notCurrentUser.get('ssn')).toBe(undefined);
done();
})
.catch(done.fail);
});

it('should be able to get own PII via API with Find without constraints', done => {
new Parse.Query(Parse.User)
.find()
.then(fetchedUsers => {
const currentUser = fetchedUsers.find(
u => u.id === anotherUser.id
);
expect(currentUser.get('email')).toBe(ANOTHER_EMAIL);
expect(currentUser.get('zip')).toBe(ZIP);
expect(currentUser.get('ssn')).toBe(SSN);
done();
})
.catch(done.fail);
});

it('should not be able to get user PII via API with Get', done => {
new Parse.Query(Parse.User)
.get(user.id)
Expand Down