Skip to content

Commit d0dc511

Browse files
yomybabydavimacedo
authored andcommitted
Add test cases for protectedFields when using Find without constraints. (#5967)
1 parent ed7c263 commit d0dc511

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

spec/UserPII.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,11 +1122,19 @@ describe('Personally Identifiable Information', () => {
11221122
// Even with an authenticated user, Public read ACL should never expose sensitive data.
11231123
describe('with another authenticated user', () => {
11241124
let anotherUser;
1125+
const ANOTHER_EMAIL = '[email protected]';
11251126

11261127
beforeEach(async done => {
11271128
return Parse.User.signUp('another', 'abc')
11281129
.then(loggedInUser => (anotherUser = loggedInUser))
11291130
.then(() => Parse.User.logIn(anotherUser.get('username'), 'abc'))
1131+
.then(() =>
1132+
anotherUser
1133+
.set('email', ANOTHER_EMAIL)
1134+
.set('zip', ZIP)
1135+
.set('ssn', SSN)
1136+
.save()
1137+
)
11301138
.then(() => done());
11311139
});
11321140

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

1167+
it('should not be able to get user PII via API with Find without constraints', done => {
1168+
new Parse.Query(Parse.User)
1169+
.find()
1170+
.then(fetchedUsers => {
1171+
const notCurrentUser = fetchedUsers.find(
1172+
u => u.id !== anotherUser.id
1173+
);
1174+
expect(notCurrentUser.get('email')).toBe(undefined);
1175+
expect(notCurrentUser.get('zip')).toBe(undefined);
1176+
expect(notCurrentUser.get('ssn')).toBe(undefined);
1177+
done();
1178+
})
1179+
.catch(done.fail);
1180+
});
1181+
1182+
it('should be able to get own PII via API with Find without constraints', done => {
1183+
new Parse.Query(Parse.User)
1184+
.find()
1185+
.then(fetchedUsers => {
1186+
const currentUser = fetchedUsers.find(
1187+
u => u.id === anotherUser.id
1188+
);
1189+
expect(currentUser.get('email')).toBe(ANOTHER_EMAIL);
1190+
expect(currentUser.get('zip')).toBe(ZIP);
1191+
expect(currentUser.get('ssn')).toBe(SSN);
1192+
done();
1193+
})
1194+
.catch(done.fail);
1195+
});
1196+
11591197
it('should not be able to get user PII via API with Get', done => {
11601198
new Parse.Query(Parse.User)
11611199
.get(user.id)

0 commit comments

Comments
 (0)