Skip to content

Commit

Permalink
test: ensure data strictness (#10123)
Browse files Browse the repository at this point in the history
Ensures we don't save and read additional properties to the database
with both, Local API and `payload.db`.
  • Loading branch information
r1tsuu authored Dec 22, 2024
1 parent 68b5f61 commit ed0d339
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/database/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ed0d339

Please sign in to comment.