@@ -165,13 +165,40 @@ fn should_remove_map_values() {
165165 let env = TestEnvironment :: new ( rng) ;
166166 let caller = random_self_authenticating_principal ( rng) ;
167167 let map_name = random_map_name ( rng) ;
168+ let map_key = random_map_key ( rng) ;
169+ let encrypted_value = random_encrypted_value ( rng) ;
170+
171+ // Add an entry into the map
172+ env. update :: < Result < Option < ByteBuf > , String > > (
173+ caller,
174+ "insert_encrypted_value" ,
175+ encode_args ( (
176+ caller,
177+ map_name. clone ( ) ,
178+ map_key. clone ( ) ,
179+ encrypted_value. clone ( ) ,
180+ ) )
181+ . unwrap ( ) ,
182+ )
183+ . unwrap ( ) ;
168184
185+ // Remove map values and ensure the removed key is returned
169186 let result = env. update :: < Result < Vec < ByteBuf > , String > > (
170187 caller,
171188 "remove_map_values" ,
172- encode_args ( ( caller, map_name) ) . unwrap ( ) ,
189+ encode_args ( ( caller, map_name. clone ( ) ) ) . unwrap ( ) ,
173190 ) ;
174- assert_eq ! ( result, Ok ( vec![ ] ) ) ;
191+ assert_eq ! ( result, Ok ( vec![ map_key. clone( ) ] ) ) ;
192+
193+ // Ensure that the map is indeed empty afterwards
194+ let remaining_values = env
195+ . query :: < Result < Vec < ( ByteBuf , ByteBuf ) > , String > > (
196+ caller,
197+ "get_encrypted_values_for_map" ,
198+ encode_args ( ( caller, map_name) ) . unwrap ( ) ,
199+ )
200+ . unwrap ( ) ;
201+ assert_eq ! ( remaining_values, vec![ ] ) ;
175202}
176203
177204#[ test]
@@ -247,6 +274,10 @@ fn should_add_user_to_map() {
247274
248275#[ test]
249276fn should_fail_to_invoke_operations_by_unauthorized ( ) {
277+ // Note: Unauthorized access to
278+ // * insert_encrypted_value is tested in should_fail_to_add_a_key_to_map_by_unauthorized and should_fail_modify_key_value_in_map_by_unauthorized
279+ // * remove_encrypted_value is tested in should_fail_to_remove_a_key_from_map_by_unauthorized
280+
250281 let rng = & mut reproducible_rng ( ) ;
251282 let env = TestEnvironment :: new ( rng) ;
252283 let unauthorized = random_self_authenticating_principal ( rng) ;
@@ -268,7 +299,7 @@ fn should_fail_to_invoke_operations_by_unauthorized() {
268299 env. query:: <Result <Option <ByteBuf >, String >>(
269300 unauthorized,
270301 "get_encrypted_value" ,
271- encode_args( ( owner, map_name. clone( ) , map_key) ) . unwrap( ) ,
302+ encode_args( ( owner, map_name. clone( ) , map_key. clone ( ) ) ) . unwrap( ) ,
272303 ) ,
273304 Err ( "unauthorized" . to_string( ) )
274305 ) ;
@@ -282,6 +313,26 @@ fn should_fail_to_invoke_operations_by_unauthorized() {
282313 Err ( "unauthorized" . to_string( ) )
283314 ) ;
284315
316+ assert_eq ! (
317+ env. query:: <Result <Vec <( Principal , AccessRights ) >, String >>(
318+ unauthorized,
319+ "get_shared_user_access_for_map" ,
320+ encode_args( ( owner, map_name. clone( ) ) ) . unwrap( ) ,
321+ ) ,
322+ Err ( "unauthorized" . to_string( ) )
323+ ) ;
324+
325+ let transport_key = random_transport_key ( rng) ;
326+ let transport_key_bytes = TransportKey :: from ( transport_key. public_key ( ) ) ;
327+ assert_eq ! (
328+ env. update:: <Result <VetKey , String >>(
329+ unauthorized,
330+ "get_encrypted_vetkey" ,
331+ encode_args( ( owner, map_name. clone( ) , transport_key_bytes) ) . unwrap( ) ,
332+ ) ,
333+ Err ( "unauthorized" . to_string( ) )
334+ ) ;
335+
285336 for _ in 0 ..2 {
286337 assert_eq ! (
287338 env. update:: <Result <Vec <ByteBuf >, String >>(
@@ -367,6 +418,15 @@ fn should_remove_user_from_map() {
367418 ) ,
368419 Ok ( Some ( access_rights) )
369420 ) ;
421+
422+ assert_eq ! (
423+ env. query:: <Result <Option <AccessRights >, String >>(
424+ caller,
425+ "get_user_rights" ,
426+ encode_args( ( caller, map_name. clone( ) , user_to_be_added) ) . unwrap( ) ,
427+ ) ,
428+ Ok ( None )
429+ ) ;
370430}
371431
372432#[ test]
@@ -430,10 +490,25 @@ fn should_add_a_key_to_map() {
430490 env. update:: <Result <Option <ByteBuf >, String >>(
431491 caller,
432492 "insert_encrypted_value" ,
433- encode_args( ( caller, map_name. clone( ) , map_key, encrypted_value) ) . unwrap( ) ,
493+ encode_args( (
494+ caller,
495+ map_name. clone( ) ,
496+ map_key. clone( ) ,
497+ encrypted_value. clone( )
498+ ) )
499+ . unwrap( ) ,
434500 ) ,
435501 Ok ( None )
436502 ) ;
503+
504+ assert_eq ! (
505+ env. query:: <Result <Option <ByteBuf >, String >>(
506+ caller,
507+ "get_encrypted_value" ,
508+ encode_args( ( caller, map_name. clone( ) , map_key) ) . unwrap( ) ,
509+ ) ,
510+ Ok ( Some ( encrypted_value) )
511+ ) ;
437512}
438513
439514#[ test]
@@ -518,6 +593,15 @@ fn should_remove_key_from_map() {
518593 ) ,
519594 Ok ( Some ( encrypted_value) )
520595 ) ;
596+
597+ assert_eq ! (
598+ env. query:: <Result <Option <ByteBuf >, String >>(
599+ caller,
600+ "get_encrypted_value" ,
601+ encode_args( ( caller, map_name. clone( ) , map_key) ) . unwrap( ) ,
602+ ) ,
603+ Ok ( None )
604+ ) ;
521605}
522606
523607#[ test]
@@ -708,18 +792,20 @@ fn should_modify_key_value_in_map() {
708792 let map_key = random_map_key ( rng) ;
709793 let encrypted_value = random_encrypted_value ( rng) ;
710794
711- env. update :: < Result < Option < ByteBuf > , String > > (
712- caller,
713- "insert_encrypted_value" ,
714- encode_args ( (
795+ assert_eq ! (
796+ env. update:: <Result <Option <ByteBuf >, String >>(
715797 caller,
716- map_name. clone ( ) ,
717- map_key. clone ( ) ,
718- encrypted_value. clone ( ) ,
719- ) )
720- . unwrap ( ) ,
721- )
722- . unwrap ( ) ;
798+ "insert_encrypted_value" ,
799+ encode_args( (
800+ caller,
801+ map_name. clone( ) ,
802+ map_key. clone( ) ,
803+ encrypted_value. clone( ) ,
804+ ) )
805+ . unwrap( ) ,
806+ ) ,
807+ Ok ( None )
808+ ) ;
723809
724810 let new_encrypted_value = random_encrypted_value ( rng) ;
725811 assert_eq ! (
@@ -730,12 +816,21 @@ fn should_modify_key_value_in_map() {
730816 caller,
731817 map_name. clone( ) ,
732818 map_key. clone( ) ,
733- new_encrypted_value
819+ new_encrypted_value. clone ( )
734820 ) )
735821 . unwrap( ) ,
736822 ) ,
737823 Ok ( Some ( encrypted_value) )
738824 ) ;
825+
826+ assert_eq ! (
827+ env. query:: <Result <Option <ByteBuf >, String >>(
828+ caller,
829+ "get_encrypted_value" ,
830+ encode_args( ( caller, map_name. clone( ) , map_key) ) . unwrap( ) ,
831+ ) ,
832+ Ok ( Some ( new_encrypted_value) )
833+ ) ;
739834}
740835
741836#[ test]
0 commit comments