@@ -2,8 +2,7 @@ mod common;
22
33// TODO: Use the derive macros for this test
44use std:: { borrow:: Cow , collections:: BTreeMap } ;
5- use tracing_test:: traced_test;
6-
5+ use miette:: IntoDiagnostic ;
76use cipherstash_client:: encryption:: TypeParseError ;
87use cipherstash_dynamodb:: {
98 crypto:: Unsealed ,
@@ -55,10 +54,9 @@ impl Identifiable for Test {
5554 }
5655}
5756
58- // TODO: Make this function consume and return the Unsealed
5957fn put_attrs ( unsealed : & mut Unsealed , attrs : BTreeMap < String , String > ) {
6058 attrs. into_iter ( ) . for_each ( |( k, v) | {
61- unsealed. add_protected ( format ! ( "attrs.{k}" ) , Plaintext :: from ( v) ) ;
59+ unsealed. add_protected_map_field ( "attrs" , k , Plaintext :: from ( v) ) ;
6260 } )
6361}
6462
@@ -76,9 +74,8 @@ impl Encryptable for Test {
7674 }
7775
7876 fn into_unsealed ( self ) -> Unsealed {
79- // FIXME: This should be a "consuming" method
8077 let mut unsealed = Unsealed :: new_with_descriptor ( <Self as Identifiable >:: type_name ( ) ) ;
81- unsealed. add_protected ( "pk" , Plaintext :: from ( self . pk ) ) ;
78+ unsealed. add_unprotected ( "pk" , TableAttribute :: from ( self . pk ) ) ;
8279 unsealed. add_unprotected ( "sk" , TableAttribute :: from ( self . sk ) ) ;
8380 unsealed. add_protected ( "name" , Plaintext :: from ( self . name ) ) ;
8481 unsealed. add_protected ( "age" , Plaintext :: from ( self . age ) ) ;
9491{
9592 unsealed
9693 . take_protected_map ( "attrs" )
97- // FIXME: This method should have a better error
9894 . ok_or ( TypeParseError ( "attrs" . to_string ( ) ) ) ?
9995 . into_iter ( )
10096 . map ( |( k, v) | TryFromPlaintext :: try_from_plaintext ( v) . map ( |v| ( k, v) ) )
@@ -103,26 +99,23 @@ where
10399
104100impl Decryptable for Test {
105101 fn from_unsealed ( mut unsealed : Unsealed ) -> Result < Self , SealError > {
106- println ! ( "IN FROM UNSEALED" ) ;
107102 Ok ( Self {
108- /* pk: TryFromTableAttr::try_from_table_attr(
103+ pk : TryFromTableAttr :: try_from_table_attr (
109104 unsealed. get_plaintext ( "pk" ) ,
110105 ) ?,
111106 sk : TryFromTableAttr :: try_from_table_attr (
112107 unsealed. get_plaintext ( "sk" ) ,
113- )?,*/
114- pk : String :: from ( "pk-hack" ) ,
115- sk : String :: from ( "sk-hack" ) ,
116- name : dbg ! ( TryFromPlaintext :: try_from_optional_plaintext(
117- dbg!( unsealed. take_protected( "name" ) ) ,
118- ) ) ?,
119- age : dbg ! ( TryFromPlaintext :: try_from_optional_plaintext(
108+ ) ?,
109+ name : TryFromPlaintext :: try_from_optional_plaintext (
110+ unsealed. take_protected ( "name" ) ,
111+ ) ?,
112+ age : TryFromPlaintext :: try_from_optional_plaintext (
120113 unsealed. take_protected ( "age" ) ,
121- ) ) ?,
122- tag : dbg ! ( TryFromTableAttr :: try_from_table_attr(
114+ ) ?,
115+ tag : TryFromTableAttr :: try_from_table_attr (
123116 unsealed. get_plaintext ( "tag" ) ,
124- ) ) ?,
125- attrs : dbg ! ( get_attrs( & mut unsealed) ) ?,
117+ ) ?,
118+ attrs : get_attrs ( & mut unsealed) ?,
126119 } )
127120 }
128121
@@ -140,8 +133,7 @@ impl Decryptable for Test {
140133}
141134
142135#[ tokio:: test]
143- #[ traced_test]
144- async fn test_round_trip ( ) {
136+ async fn test_round_trip ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
145137 let config = aws_config:: from_env ( )
146138 . endpoint_url ( "http://localhost:8000" )
147139 . load ( )
@@ -154,7 +146,7 @@ async fn test_round_trip() {
154146
155147 let table = EncryptedTable :: init ( client, table_name)
156148 . await
157- . expect ( "Failed to init table" ) ;
149+ . into_diagnostic ( ) ? ;
158150
159151 let record = Test {
160152 pk : "pk" . to_string ( ) ,
@@ -168,17 +160,14 @@ async fn test_round_trip() {
168160 table
169161 . put ( record. clone ( ) )
170162 . await
171- . expect ( "Failed to insert record" ) ;
163+ . into_diagnostic ( ) ? ;
172164
173- /* let check = table
165+ let check = table
174166 . get :: < Test > ( ( "pk" , "sk" ) )
175- .await;
176-
177- if let Err(e) = check {
178- panic!("Failed to get record: {:?}", e);
179- }*/
167+ . await
168+ . into_diagnostic ( ) ?;
180169
181- assert ! ( false ) ;
170+ assert_eq ! ( check , Some ( record ) ) ;
182171
183- //assert_eq!(check, record);
172+ Ok ( ( ) )
184173}
0 commit comments