@@ -251,6 +251,45 @@ describe("User tests", () => {
251
251
chai . assert . equal ( verify , true ) ;
252
252
} ) ;
253
253
254
+ //encrypt tests
255
+ const string = "hello there £ Я a a" ;
256
+ let encryptedString ;
257
+
258
+ it ( "should encrypt string data for another user" , async function ( ) {
259
+ encryptedString = await user . encryptString ( string , user_2 . user_data . user_id ) ;
260
+
261
+ //should not decrypt it again
262
+ try {
263
+ await user . decryptString ( encryptedString ) ;
264
+ } catch ( e ) {
265
+ const json = JSON . parse ( e ) ;
266
+
267
+ chai . assert . equal ( json . status , "server_304" ) ;
268
+ }
269
+ } ) ;
270
+
271
+ it ( "should decrypt the string for the other user" , async function ( ) {
272
+ const decrypted = await user_2 . decryptString ( encryptedString ) ;
273
+
274
+ chai . assert . equal ( decrypted , string ) ;
275
+ } ) ;
276
+
277
+ it ( "should encrypt string with sign" , async function ( ) {
278
+ encryptedString = await user . encryptString ( string , user_2 . user_data . user_id , true ) ;
279
+ } ) ;
280
+
281
+ it ( "should decrypt the signed string without verify" , async function ( ) {
282
+ const decrypted = await user_2 . decryptString ( encryptedString ) ;
283
+
284
+ chai . assert . equal ( decrypted , string ) ;
285
+ } ) ;
286
+
287
+ it ( "should decrypt the string with verify" , async function ( ) {
288
+ const decrypted = await user_2 . decryptString ( encryptedString , true , user . user_data . user_id ) ;
289
+
290
+ chai . assert . equal ( decrypted , string ) ;
291
+ } ) ;
292
+
254
293
it ( "should delete the user" , async function ( ) {
255
294
await user . deleteUser ( pw ) ;
256
295
await user_2 . deleteUser ( pw ) ;
0 commit comments