@@ -51,12 +51,36 @@ describe('encrypt and decrypt', async () => {
5151 table : 'users' ,
5252 serviceToken : undefined ,
5353 lockContext : undefined ,
54+ unverifiedContext : undefined ,
5455 } )
5556
5657 const decrypted = await decrypt ( client , {
5758 ciphertext : ciphertext . c ,
5859 lockContext : undefined ,
5960 serviceToken : undefined ,
61+ unverifiedContext : undefined ,
62+ } )
63+
64+ expect ( decrypted ) . toBe ( originalPlaintext )
65+ } )
66+
67+ test ( 'can pass in unverified context' , async ( ) => {
68+ const client = await newClient ( { encryptConfig } )
69+ const originalPlaintext = 'abc'
70+ const unverifiedContext = {
71+ sub : 'sub-single' ,
72+ }
73+
74+ const ciphertext = await encrypt ( client , {
75+ plaintext : originalPlaintext ,
76+ column : 'email' ,
77+ table : 'users' ,
78+ unverifiedContext,
79+ } )
80+
81+ const decrypted = await decrypt ( client , {
82+ ciphertext : ciphertext . c ,
83+ unverifiedContext,
6084 } )
6185
6286 expect ( decrypted ) . toBe ( originalPlaintext )
@@ -147,6 +171,7 @@ describe('encryptBulk and decryptBulk', async () => {
147171 } ,
148172 ] ,
149173 serviceToken : undefined ,
174+ unverifiedContext : undefined ,
150175 } )
151176
152177 const decrypted = await decryptBulk ( client , {
@@ -155,6 +180,39 @@ describe('encryptBulk and decryptBulk', async () => {
155180 lockContext : undefined ,
156181 } ) ) ,
157182 serviceToken : undefined ,
183+ unverifiedContext : undefined ,
184+ } )
185+
186+ expect ( decrypted ) . toEqual ( [ plaintextOne , plaintextTwo ] )
187+ } )
188+
189+ test ( 'can pass in unverified context' , async ( ) => {
190+ const client = await newClient ( { encryptConfig } )
191+ const plaintextOne = 'abc'
192+ const plaintextTwo = 'def'
193+ const unverifiedContext = {
194+ sub : 'sub-bulk' ,
195+ }
196+
197+ const ciphertexts = await encryptBulk ( client , {
198+ plaintexts : [
199+ {
200+ plaintext : plaintextOne ,
201+ column : 'email' ,
202+ table : 'users' ,
203+ } ,
204+ {
205+ plaintext : plaintextTwo ,
206+ column : 'email' ,
207+ table : 'users' ,
208+ } ,
209+ ] ,
210+ unverifiedContext,
211+ } )
212+
213+ const decrypted = await decryptBulk ( client , {
214+ ciphertexts : ciphertexts . map ( ( { c } ) => ( { ciphertext : c } ) ) ,
215+ unverifiedContext,
158216 } )
159217
160218 expect ( decrypted ) . toEqual ( [ plaintextOne , plaintextTwo ] )
@@ -187,6 +245,38 @@ describe('encryptBulk and decryptBulk', async () => {
187245 expect ( decrypted ) . toEqual ( [ { data : plaintextOne } , { data : plaintextTwo } ] )
188246 } )
189247
248+ test ( 'can use unverified context with decryptBulkFallible' , async ( ) => {
249+ const client = await newClient ( { encryptConfig } )
250+ const plaintextOne = 'abc'
251+ const plaintextTwo = 'def'
252+ const unverifiedContext = {
253+ sub : 'sub-bulk-fallible' ,
254+ }
255+
256+ const ciphertexts = await encryptBulk ( client , {
257+ plaintexts : [
258+ {
259+ plaintext : plaintextOne ,
260+ column : 'email' ,
261+ table : 'users' ,
262+ } ,
263+ {
264+ plaintext : plaintextTwo ,
265+ column : 'email' ,
266+ table : 'users' ,
267+ } ,
268+ ] ,
269+ unverifiedContext,
270+ } )
271+
272+ const decrypted = await decryptBulkFallible ( client , {
273+ ciphertexts : ciphertexts . map ( ( c ) => ( { ciphertext : c . c } ) ) ,
274+ unverifiedContext,
275+ } )
276+
277+ expect ( decrypted ) . toEqual ( [ { data : plaintextOne } , { data : plaintextTwo } ] )
278+ } )
279+
190280 test ( 'encryptBulk throws an errow when identityClaim is used without a service token' , async ( ) => {
191281 const client = await newClient ( { encryptConfig } )
192282
0 commit comments