-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ensure data strictness (#10123)
Ensures we don't save and read additional properties to the database with both, Local API and `payload.db`.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -242,6 +242,57 @@ describe('database', () => { | |
}) | ||
}) | ||
|
||
describe('Data strictness', () => { | ||
it('should not save and leak password, confirm-password from Local API', async () => { | ||
const createdUser = await payload.create({ | ||
collection: 'users', | ||
data: { | ||
password: 'some-password', | ||
// @ts-expect-error | ||
'confirm-password': 'some-password', | ||
email: '[email protected]', | ||
}, | ||
}) | ||
|
||
let keys = Object.keys(createdUser) | ||
|
||
expect(keys).not.toContain('password') | ||
expect(keys).not.toContain('confirm-password') | ||
|
||
const foundUser = await payload.findByID({ id: createdUser.id, collection: 'users' }) | ||
|
||
keys = Object.keys(foundUser) | ||
|
||
expect(keys).not.toContain('password') | ||
expect(keys).not.toContain('confirm-password') | ||
}) | ||
|
||
it('should not save and leak password, confirm-password from payload.db', async () => { | ||
const createdUser = await payload.db.create({ | ||
collection: 'users', | ||
data: { | ||
password: 'some-password', | ||
'confirm-password': 'some-password', | ||
email: '[email protected]', | ||
}, | ||
}) | ||
|
||
let keys = Object.keys(createdUser) | ||
|
||
expect(keys).not.toContain('password') | ||
expect(keys).not.toContain('confirm-password') | ||
|
||
const foundUser = await payload.db.findOne({ | ||
collection: 'users', | ||
where: { id: createdUser.id }, | ||
}) | ||
|
||
keys = Object.keys(foundUser) | ||
expect(keys).not.toContain('password') | ||
expect(keys).not.toContain('confirm-password') | ||
}) | ||
}) | ||
|
||
describe('migrations', () => { | ||
let ranFreshTest = false | ||
|
||
|