Skip to content

Commit a7556a2

Browse files
committed
chore(protect): ensure bulk interfaces work when striping down EQL payload
1 parent 18b1c6e commit a7556a2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

packages/protect/__tests__/bulk-protect.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,53 @@ describe('bulk encryption and decryption', () => {
332332

333333
expect(decryptedData.data).toHaveLength(0)
334334
}, 30000)
335+
336+
it('should handle encrypted payloads with only "c" key', async () => {
337+
// First encrypt some data
338+
const plaintexts = [
339+
{ id: 'user1', plaintext: 'alice@example.com' },
340+
{ id: 'user2', plaintext: 'bob@example.com' },
341+
{ id: 'user3', plaintext: 'charlie@example.com' },
342+
]
343+
344+
const encryptedData = await protectClient.bulkEncrypt(plaintexts, {
345+
column: users.email,
346+
table: users,
347+
})
348+
349+
if (encryptedData.failure) {
350+
throw new Error(`[protect]: ${encryptedData.failure.message}`)
351+
}
352+
353+
// Remove all keys except "c" from each encrypted payload
354+
const modifiedEncryptedData = encryptedData.data.map((item) => ({
355+
id: item.id,
356+
data: {
357+
c: item.data?.c,
358+
} as EncryptedPayload,
359+
}))
360+
361+
// Now decrypt the modified data
362+
const decryptedData = await protectClient.bulkDecrypt(
363+
modifiedEncryptedData,
364+
)
365+
366+
if (decryptedData.failure) {
367+
throw new Error(`[protect]: ${decryptedData.failure.message}`)
368+
}
369+
370+
// Verify structure
371+
expect(decryptedData.data).toHaveLength(3)
372+
expect(decryptedData.data[0]).toHaveProperty('id', 'user1')
373+
expect(decryptedData.data[0]).toHaveProperty('data', 'alice@example.com')
374+
expect(decryptedData.data[1]).toHaveProperty('id', 'user2')
375+
expect(decryptedData.data[1]).toHaveProperty('data', 'bob@example.com')
376+
expect(decryptedData.data[2]).toHaveProperty('id', 'user3')
377+
expect(decryptedData.data[2]).toHaveProperty(
378+
'data',
379+
'charlie@example.com',
380+
)
381+
}, 30000)
335382
})
336383

337384
describe('bulk operations with lock context', () => {

0 commit comments

Comments
 (0)