From 725d2ebf90556d1b25e3e9f26eea9737df4b75e4 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Fri, 9 Oct 2020 15:06:55 +0200 Subject: [PATCH] Use filtering API in tests, remove old name matching via get_proof_request_messages Signed-off-by: Miroslav Kovar --- libvcx/src/api/disclosed_proof.rs | 2 +- .../proof_presentation/prover/prover.rs | 18 +++--------------- libvcx/src/aries/mod.rs | 2 +- libvcx/src/disclosed_proof.rs | 8 ++++---- libvcx/src/lib.rs | 15 +++++++++++++-- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/libvcx/src/api/disclosed_proof.rs b/libvcx/src/api/disclosed_proof.rs index 01fcbde703..223ef701bd 100644 --- a/libvcx/src/api/disclosed_proof.rs +++ b/libvcx/src/api/disclosed_proof.rs @@ -381,7 +381,7 @@ pub extern fn vcx_disclosed_proof_get_requests(command_handle: CommandHandle, command_handle, connection_handle); spawn(move || { - match disclosed_proof::get_proof_request_messages(connection_handle, None) { + match disclosed_proof::get_proof_request_messages(connection_handle) { Ok(x) => { trace!("vcx_disclosed_proof_get_requests_cb(command_handle: {}, rc: {}, msg: {})", command_handle, error::SUCCESS.message, x); diff --git a/libvcx/src/aries/handlers/proof_presentation/prover/prover.rs b/libvcx/src/aries/handlers/proof_presentation/prover/prover.rs index da7435131f..7b3b8853e7 100644 --- a/libvcx/src/aries/handlers/proof_presentation/prover/prover.rs +++ b/libvcx/src/aries/handlers/proof_presentation/prover/prover.rs @@ -17,13 +17,6 @@ pub struct Prover { prover_sm: ProverSM } -fn _filter_by_name(content: &str, match_name: &str, presentation_request: PresentationRequest) -> Option { - match serde_json::from_str(&content).map(|value: serde_json::Value| value.get("name").unwrap_or(&serde_json::Value::Null).as_str().unwrap_or("").to_string()) { - Ok(name) if name == String::from(match_name) => Some(presentation_request), - _ => None - } -} - impl Prover { pub fn create(source_id: &str, presentation_request: PresentationRequest) -> VcxResult { trace!("Prover::create >>> source_id: {}, presentation_request: {:?}", source_id, presentation_request); @@ -124,20 +117,15 @@ impl Prover { Ok(presentation_request) } - pub fn get_presentation_request_messages(connection_handle: u32, match_name: Option<&str>) -> VcxResult> { - trace!("Prover::get_presentation_request_messages >>> connection_handle: {:?}, match_name: {:?}", connection_handle, match_name); + pub fn get_presentation_request_messages(connection_handle: u32) -> VcxResult> { + trace!("Prover::get_presentation_request_messages >>> connection_handle: {:?}", connection_handle); let presentation_requests: Vec = connection::get_messages(connection_handle)? .into_iter() .filter_map(|(_, message)| { match message { - A2AMessage::PresentationRequest(presentation_request) => { - match (presentation_request.request_presentations_attach.content().ok(), match_name) { - (Some(content), Some(match_name)) => _filter_by_name(&content, match_name, presentation_request), - _ => Some(presentation_request) - } - } + A2AMessage::PresentationRequest(presentation_request) => Some(presentation_request), _ => None } }) diff --git a/libvcx/src/aries/mod.rs b/libvcx/src/aries/mod.rs index ca6bf0c1f6..5401310e7d 100644 --- a/libvcx/src/aries/mod.rs +++ b/libvcx/src/aries/mod.rs @@ -396,7 +396,7 @@ pub mod test { pub fn get_proof_request_messages(&self) -> String { self.activate(); - let presentation_requests = ::disclosed_proof::get_proof_request_messages(self.connection_handle, None).unwrap(); + let presentation_requests = ::disclosed_proof::get_proof_request_messages(self.connection_handle).unwrap(); let presentation_request = ::serde_json::from_str::>(&presentation_requests).unwrap()[0].clone(); let presentation_request_json = ::serde_json::to_string(&presentation_request).unwrap(); presentation_request_json diff --git a/libvcx/src/disclosed_proof.rs b/libvcx/src/disclosed_proof.rs index ebb95508d8..ab5c6a3e7b 100644 --- a/libvcx/src/disclosed_proof.rs +++ b/libvcx/src/disclosed_proof.rs @@ -181,14 +181,14 @@ fn get_proof_request(connection_handle: u32, msg_id: &str) -> VcxResult .map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Cannot serialize message: {}", err))); } -pub fn get_proof_request_messages(connection_handle: u32, match_name: Option<&str>) -> VcxResult { - trace!("get_proof_request_messages >>> connection_handle: {}, match_name: {:?}", connection_handle, match_name); +pub fn get_proof_request_messages(connection_handle: u32) -> VcxResult { + trace!("get_proof_request_messages >>> connection_handle: {}", connection_handle); if !connection::is_v3_connection(connection_handle)? { return Err(VcxError::from_msg(VcxErrorKind::InvalidConnectionHandle, format!("Connection can not be used for Proprietary Issuance protocol"))); } - let presentation_requests = Prover::get_presentation_request_messages(connection_handle, match_name)?; + let presentation_requests = Prover::get_presentation_request_messages(connection_handle)?; Ok(json!(presentation_requests).to_string()) } @@ -244,7 +244,7 @@ mod tests { use super::*; fn _get_proof_request_messages(connection_h: u32) -> String { - let requests = get_proof_request_messages(connection_h, None).unwrap(); + let requests = get_proof_request_messages(connection_h).unwrap(); let requests: Value = serde_json::from_str(&requests).unwrap(); let requests = serde_json::to_string(&requests[0]).unwrap(); requests diff --git a/libvcx/src/lib.rs b/libvcx/src/lib.rs index f1f99d9d2d..f63689aeb6 100644 --- a/libvcx/src/lib.rs +++ b/libvcx/src/lib.rs @@ -70,6 +70,7 @@ mod tests { use issuer_credential; use proof; use settings; + use filters; use utils::{ constants::TEST_TAILS_FILE, devsetup::{set_consumer, set_institution}, @@ -215,8 +216,18 @@ mod tests { fn create_proof(connection_handle: u32, consumer_handle: Option, request_name: Option<&str>) -> u32 { set_consumer(consumer_handle); info!("create_proof >>> getting proof request messages"); - let requests = disclosed_proof::get_proof_request_messages(connection_handle, request_name).unwrap(); - info!("create_proof :: get proof request messages returned {}", requests); + let requests = { + let _requests = disclosed_proof::get_proof_request_messages(connection_handle).unwrap(); + info!("create_proof :: get proof request messages returned {}", _requests); + match request_name { + Some(request_name) => { + let filtered = filters::filter_proof_requests_by_name(&_requests, request_name).unwrap(); + info!("create_proof :: proof request messages filtered by name {}: {}", request_name, filtered); + filtered + } + _ => _requests + } + }; let requests: Value = serde_json::from_str(&requests).unwrap(); let requests = requests.as_array().unwrap(); assert_eq!(requests.len(), 1);