@@ -332,6 +332,53 @@ describe('bulk encryption and decryption', () => {
332
332
333
333
expect ( decryptedData . data ) . toHaveLength ( 0 )
334
334
} , 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 )
335
382
} )
336
383
337
384
describe ( 'bulk operations with lock context' , ( ) => {
0 commit comments