-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Protected fields fix #5463
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
acinader
merged 6 commits into
parse-community:master
from
acinader:protected-fields-fix
Mar 30, 2019
Merged
Protected fields fix #5463
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3ca2b6b
fix minor spelling mistake
acinader 8f5a613
Always process userSensitiveFields if they exist
acinader 34a1a99
Cover change to protectedFields
acinader 9b51263
re-arrange promise deck chairs to not
acinader 95aa1e3
remove noop code
acinader edf7fd6
protect agains the case where options.protectedFields
acinader File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
describe('ProtectedFields', function() { | ||
describe('interaction with legacy userSensitiveFields', function() { | ||
it('should fall back on sensitive fields if protected fields are not configured', async function() { | ||
const userSensitiveFields = ['phoneNumber', 'timeZone']; | ||
|
||
const protectedFields = { _User: { '*': ['email'] } }; | ||
|
||
await reconfigureServer({ userSensitiveFields, protectedFields }); | ||
const user = new Parse.User(); | ||
user.setUsername('Alice'); | ||
user.setPassword('sekrit'); | ||
user.set('email', '[email protected]'); | ||
user.set('phoneNumber', 8675309); | ||
user.set('timeZone', 'America/Los_Angeles'); | ||
user.set('favoriteColor', 'yellow'); | ||
user.set('favoriteFood', 'pizza'); | ||
await user.save(); | ||
|
||
const fetched = await new Parse.Query(Parse.User).get(user.id); | ||
expect(fetched.has('email')).toBeFalsy(); | ||
expect(fetched.has('phoneNumber')).toBeFalsy(); | ||
expect(fetched.has('favoriteColor')).toBeTruthy(); | ||
}); | ||
|
||
it('should merge protected and sensitive for extra safety', async function() { | ||
const userSensitiveFields = ['phoneNumber', 'timeZone']; | ||
|
||
const protectedFields = { _User: { '*': ['email', 'favoriteFood'] } }; | ||
|
||
await reconfigureServer({ userSensitiveFields, protectedFields }); | ||
const user = new Parse.User(); | ||
user.setUsername('Alice'); | ||
user.setPassword('sekrit'); | ||
user.set('email', '[email protected]'); | ||
user.set('phoneNumber', 8675309); | ||
user.set('timeZone', 'America/Los_Angeles'); | ||
user.set('favoriteColor', 'yellow'); | ||
user.set('favoriteFood', 'pizza'); | ||
await user.save(); | ||
|
||
const fetched = await new Parse.Query(Parse.User).get(user.id); | ||
expect(fetched.has('email')).toBeFalsy(); | ||
expect(fetched.has('phoneNumber')).toBeFalsy(); | ||
expect(fetched.has('favoriteFood')).toBeFalsy(); | ||
expect(fetched.has('favoriteColor')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('non user class', function() { | ||
it('should hide fields in a non user class', async function() { | ||
const protectedFields = { | ||
ClassA: { '*': ['foo'] }, | ||
ClassB: { '*': ['bar'] }, | ||
}; | ||
await reconfigureServer({ protectedFields }); | ||
|
||
const objA = await new Parse.Object('ClassA') | ||
.set('foo', 'zzz') | ||
.set('bar', 'yyy') | ||
.save(); | ||
|
||
const objB = await new Parse.Object('ClassB') | ||
.set('foo', 'zzz') | ||
.set('bar', 'yyy') | ||
.save(); | ||
|
||
const [fetchedA, fetchedB] = await Promise.all([ | ||
new Parse.Query('ClassA').get(objA.id), | ||
new Parse.Query('ClassB').get(objB.id), | ||
]); | ||
|
||
expect(fetchedA.has('foo')).toBeFalsy(); | ||
expect(fetchedA.has('bar')).toBeTruthy(); | ||
|
||
expect(fetchedB.has('foo')).toBeTruthy(); | ||
expect(fetchedB.has('bar')).toBeFalsy(); | ||
}); | ||
|
||
it('should hide fields in non user class and non standard user field at same time', async function() { | ||
const protectedFields = { | ||
_User: { '*': ['phoneNumber'] }, | ||
ClassA: { '*': ['foo'] }, | ||
ClassB: { '*': ['bar'] }, | ||
}; | ||
|
||
await reconfigureServer({ protectedFields }); | ||
|
||
const user = new Parse.User(); | ||
user.setUsername('Alice'); | ||
user.setPassword('sekrit'); | ||
user.set('email', '[email protected]'); | ||
user.set('phoneNumber', 8675309); | ||
user.set('timeZone', 'America/Los_Angeles'); | ||
user.set('favoriteColor', 'yellow'); | ||
user.set('favoriteFood', 'pizza'); | ||
await user.save(); | ||
|
||
const objA = await new Parse.Object('ClassA') | ||
.set('foo', 'zzz') | ||
.set('bar', 'yyy') | ||
.save(); | ||
|
||
const objB = await new Parse.Object('ClassB') | ||
.set('foo', 'zzz') | ||
.set('bar', 'yyy') | ||
.save(); | ||
|
||
const [fetchedUser, fetchedA, fetchedB] = await Promise.all([ | ||
new Parse.Query(Parse.User).get(user.id), | ||
new Parse.Query('ClassA').get(objA.id), | ||
new Parse.Query('ClassB').get(objB.id), | ||
]); | ||
|
||
expect(fetchedA.has('foo')).toBeFalsy(); | ||
expect(fetchedA.has('bar')).toBeTruthy(); | ||
|
||
expect(fetchedB.has('foo')).toBeTruthy(); | ||
expect(fetchedB.has('bar')).toBeFalsy(); | ||
|
||
expect(fetchedUser.has('email')).toBeFalsy(); | ||
expect(fetchedUser.has('phoneNumber')).toBeFalsy(); | ||
expect(fetchedUser.has('favoriteColor')).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.