Skip to content

Commit ed0d339

Browse files
authored
test: ensure data strictness (#10123)
Ensures we don't save and read additional properties to the database with both, Local API and `payload.db`.
1 parent 68b5f61 commit ed0d339

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/database/int.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,57 @@ describe('database', () => {
242242
})
243243
})
244244

245+
describe('Data strictness', () => {
246+
it('should not save and leak password, confirm-password from Local API', async () => {
247+
const createdUser = await payload.create({
248+
collection: 'users',
249+
data: {
250+
password: 'some-password',
251+
// @ts-expect-error
252+
'confirm-password': 'some-password',
253+
email: 'user1@payloadcms.com',
254+
},
255+
})
256+
257+
let keys = Object.keys(createdUser)
258+
259+
expect(keys).not.toContain('password')
260+
expect(keys).not.toContain('confirm-password')
261+
262+
const foundUser = await payload.findByID({ id: createdUser.id, collection: 'users' })
263+
264+
keys = Object.keys(foundUser)
265+
266+
expect(keys).not.toContain('password')
267+
expect(keys).not.toContain('confirm-password')
268+
})
269+
270+
it('should not save and leak password, confirm-password from payload.db', async () => {
271+
const createdUser = await payload.db.create({
272+
collection: 'users',
273+
data: {
274+
password: 'some-password',
275+
'confirm-password': 'some-password',
276+
email: 'user2@payloadcms.com',
277+
},
278+
})
279+
280+
let keys = Object.keys(createdUser)
281+
282+
expect(keys).not.toContain('password')
283+
expect(keys).not.toContain('confirm-password')
284+
285+
const foundUser = await payload.db.findOne({
286+
collection: 'users',
287+
where: { id: createdUser.id },
288+
})
289+
290+
keys = Object.keys(foundUser)
291+
expect(keys).not.toContain('password')
292+
expect(keys).not.toContain('confirm-password')
293+
})
294+
})
295+
245296
describe('migrations', () => {
246297
let ranFreshTest = false
247298

0 commit comments

Comments
 (0)