Skip to content

Commit e87eb37

Browse files
authored
Add test, remove extra quotes serialized into credential preview attribute values (#503)
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
1 parent 47d5813 commit e87eb37

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

aries_vcx/src/handlers/issuance/issuer.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ pub struct IssuerConfig {
2525
}
2626

2727
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));
3029
let cred_values: serde_json::Value = serde_json::from_str(credential_json)
3130
.map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Can't deserialize credential preview json. credential_json: {}, error: {:?}", credential_json, err)))?;
3231

@@ -48,7 +47,7 @@ fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPrevi
4847
let (key, value) = item;
4948
credential_preview = credential_preview.add_value(
5049
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"))?,
5251
MimeType::Plain,
5352
);
5453
}
@@ -242,6 +241,20 @@ pub mod test {
242241
}
243242
}
244243

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+
245258
#[tokio::test]
246259
#[cfg(feature = "general_test")]
247260
async fn test_cant_revoke_without_revocation_details() {

0 commit comments

Comments
 (0)