Skip to content

Commit

Permalink
Use filtering API in tests, remove old name matching via get_proof_re…
Browse files Browse the repository at this point in the history
…quest_messages

Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
  • Loading branch information
mirgee committed Oct 9, 2020
1 parent 412315e commit 725d2eb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion libvcx/src/api/disclosed_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 3 additions & 15 deletions libvcx/src/aries/handlers/proof_presentation/prover/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ pub struct Prover {
prover_sm: ProverSM
}

fn _filter_by_name(content: &str, match_name: &str, presentation_request: PresentationRequest) -> Option<PresentationRequest> {
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<Prover> {
trace!("Prover::create >>> source_id: {}, presentation_request: {:?}", source_id, presentation_request);
Expand Down Expand Up @@ -124,20 +117,15 @@ impl Prover {
Ok(presentation_request)
}

pub fn get_presentation_request_messages(connection_handle: u32, match_name: Option<&str>) -> VcxResult<Vec<PresentationRequest>> {
trace!("Prover::get_presentation_request_messages >>> connection_handle: {:?}, match_name: {:?}", connection_handle, match_name);
pub fn get_presentation_request_messages(connection_handle: u32) -> VcxResult<Vec<PresentationRequest>> {
trace!("Prover::get_presentation_request_messages >>> connection_handle: {:?}", connection_handle);

let presentation_requests: Vec<PresentationRequest> =
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
}
})
Expand Down
2 changes: 1 addition & 1 deletion libvcx/src/aries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<::serde_json::Value>>(&presentation_requests).unwrap()[0].clone();
let presentation_request_json = ::serde_json::to_string(&presentation_request).unwrap();
presentation_request_json
Expand Down
8 changes: 4 additions & 4 deletions libvcx/src/disclosed_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ fn get_proof_request(connection_handle: u32, msg_id: &str) -> VcxResult<String>
.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<String> {
trace!("get_proof_request_messages >>> connection_handle: {}, match_name: {:?}", connection_handle, match_name);
pub fn get_proof_request_messages(connection_handle: u32) -> VcxResult<String> {
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())
}

Expand Down Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions libvcx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -215,8 +216,18 @@ mod tests {
fn create_proof(connection_handle: u32, consumer_handle: Option<u32>, 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);
Expand Down

0 comments on commit 725d2eb

Please sign in to comment.