@@ -25,8 +25,7 @@ pub struct IssuerConfig {
25
25
}
26
26
27
27
fn _build_credential_preview ( credential_json : & str ) -> VcxResult < CredentialPreviewData > {
28
- trace ! ( "Issuer::_build_credential_preview >>> credential_json: {:?}" , credential_json) ;
29
-
28
+ trace ! ( "Issuer::_build_credential_preview >>> credential_json: {:?}" , secret!( credential_json) ) ;
30
29
let cred_values: serde_json:: Value = serde_json:: from_str ( credential_json)
31
30
. map_err ( |err| VcxError :: from_msg ( VcxErrorKind :: InvalidJson , format ! ( "Can't deserialize credential preview json. credential_json: {}, error: {:?}" , credential_json, err) ) ) ?;
32
31
@@ -48,7 +47,7 @@ fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPrevi
48
47
let ( key, value) = item;
49
48
credential_preview = credential_preview. add_value (
50
49
key,
51
- & value. to_string ( ) ,
50
+ value. as_str ( ) . ok_or_else ( || VcxError :: from_msg ( VcxErrorKind :: InvalidOption , "Credential values are currently only allowed to be strings" ) ) ? ,
52
51
MimeType :: Plain ,
53
52
) ;
54
53
}
@@ -242,6 +241,20 @@ pub mod test {
242
241
}
243
242
}
244
243
244
+ #[ tokio:: test]
245
+ #[ cfg( feature = "general_test" ) ]
246
+ async fn test_build_credential_preview ( ) {
247
+ let _setup = SetupMocks :: init ( ) ;
248
+ let input = json ! ( { "name" : "Alice" , "age" : "123" } ) . to_string ( ) ;
249
+ let preview = _build_credential_preview ( & input) . unwrap ( ) ;
250
+ let value_name = preview. attributes . clone ( ) . into_iter ( ) . find ( |x| x. name == "name" ) . unwrap ( ) ;
251
+ let value_age = preview. attributes . clone ( ) . into_iter ( ) . find ( |x| x. name == "age" ) . unwrap ( ) ;
252
+ assert_eq ! ( value_name. name, "name" ) ;
253
+ assert_eq ! ( value_name. value, "Alice" ) ;
254
+ assert_eq ! ( value_age. name, "age" ) ;
255
+ assert_eq ! ( value_age. value, "123" ) ;
256
+ }
257
+
245
258
#[ tokio:: test]
246
259
#[ cfg( feature = "general_test" ) ]
247
260
async fn test_cant_revoke_without_revocation_details ( ) {
0 commit comments