From 2ec2f65abce89c17e9b89303cbcc05b9a4bc2de9 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Tue, 29 Aug 2023 19:21:57 +0200 Subject: [PATCH 01/10] Test code adjustments Signed-off-by: Patrik Stas --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 41b1f38b76..d6baeb5c64 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -336,7 +336,6 @@ jobs: run: | cargo test --manifest-path="wallet_migrator/Cargo.toml"; RUST_TEST_THREADS=1 CARGO_INCREMENTAL=0 TEST_POOL_IP=127.0.0.1 cargo test --manifest-path="aries_vcx/Cargo.toml" -F migration --test test_creds_proofs -- --include-ignored; - RUST_TEST_THREADS=1 CARGO_INCREMENTAL=0 TEST_POOL_IP=127.0.0.1 cargo test --manifest-path="aries_vcx/Cargo.toml" -F migration --test test_creds_proofs_revocations -- --include-ignored; test-integration-libvcx: needs: workflow-setup From 03ef8783dc754b688a5e145b3f3ed067642a3628 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Tue, 29 Aug 2023 18:28:21 +0200 Subject: [PATCH 02/10] wip Signed-off-by: Patrik Stas --- .../src/handlers/proof_presentation/prover.rs | 2 +- aries_vcx/tests/test_creds_proofs.rs | 73 +++++++++++++++++++ aries_vcx/tests/utils/scenarios.rs | 5 +- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/aries_vcx/src/handlers/proof_presentation/prover.rs b/aries_vcx/src/handlers/proof_presentation/prover.rs index ea078fbf12..bd84de6881 100644 --- a/aries_vcx/src/handlers/proof_presentation/prover.rs +++ b/aries_vcx/src/handlers/proof_presentation/prover.rs @@ -58,7 +58,7 @@ impl Prover { let json_retrieved_credentials = anoncreds .prover_get_credentials_for_proof_req(&presentation_request) .await?; - + trace!("Prover::retrieve_credentials >>> presentation_request: {presentation_request}, json_retrieved_credentials: {json_retrieved_credentials}"); Ok(serde_json::from_str(&json_retrieved_credentials)?) } diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index ba2cf1b478..ef00e790d6 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -663,6 +663,79 @@ mod tests { .await; } + #[tokio::test] + #[ignore] + async fn test_agency_pool_proof_should_be_validated_even_if_at_least_one_of_restrictions_set_is_valid() { + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; + + let (consumer_to_institution, institution_to_consumer) = + create_connected_connections(&mut consumer, &mut institution).await; + let (schema_id, cred_def_id, _rev_reg_id, _cred_def, _rev_reg, _credential_handle) = + issue_address_credential( + &mut consumer, + &mut institution, + &consumer_to_institution, + &institution_to_consumer, + ) + .await; + + #[cfg(feature = "migration")] + institution.migrate().await; + + let requested_attrs_string = serde_json::to_string(&json!([ + { + "name": "address1", + "restrictions": [{ + "issuer_did": "abcdef0000000000000000" + }, + { + "issuer_did": institution.institution_did, + "schema_id": schema_id, + }] + } + ])) + .unwrap(); + + info!( + "test_proof_should_be_validated :: Going to seng proof request with attributes {}", + &requested_attrs_string + ); + let mut verifier = send_proof_request( + &mut institution, + &institution_to_consumer, + &requested_attrs_string, + "[]", + "{}", + None, + ) + .await; + + #[cfg(feature = "migration")] + consumer.migrate().await; + + prover_select_credentials_and_send_proof(&mut consumer, &consumer_to_institution, None, None).await; + + info!("test_proof_should_be_validated :: verifier :: going to verify proof"); + verifier_update_with_mediator( + &mut verifier, + &institution.profile.inject_wallet(), + &institution.profile.inject_anoncreds_ledger_read(), + &institution.profile.inject_anoncreds(), + &institution.agency_client, + &institution_to_consumer, + ) + .await + .unwrap(); + assert_eq!( + verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + }) + .await; + } + #[tokio::test] #[ignore] async fn test_agency_pool_proof_with_predicates_should_be_validated() { diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index a0b6cf2c46..d16a5dfbe1 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -1131,6 +1131,7 @@ pub mod test_utils { .retrieve_credentials(&alice.profile.inject_anoncreds()) .await .unwrap(); + info!("prover_select_credentials >> retrieved_credentials: {retrieved_credentials:?}"); let selected_credentials = match requested_values { Some(requested_values) => { let credential_data = prover.presentation_request_data().unwrap(); @@ -1373,7 +1374,7 @@ pub mod test_utils { with_tails: bool, ) -> SelectedCredentials { info!( - "test_real_proof >>> retrieved matching credentials {:?}", + "retrieved_to_selected_credentials_simple >>> retrieved matching credentials {:?}", retrieved_credentials ); let mut selected_credentials = SelectedCredentials::default(); @@ -1399,7 +1400,7 @@ pub mod test_utils { with_tails: bool, ) -> SelectedCredentials { info!( - "test_real_proof >>> retrieved matching credentials {:?}", + "retrieved_to_selected_credentials_specific >>> retrieved matching credentials {:?}", retrieved_credentials ); let credential_data: Value = serde_json::from_str(credential_data).unwrap(); From b8b06d727a149142cf933c44fed2d5e7c77accc8 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Tue, 29 Aug 2023 19:33:54 +0200 Subject: [PATCH 03/10] Rename 'requested_credentials' to 'preselected_credentials' Signed-off-by: Patrik Stas --- aries_vcx/tests/test_creds_proofs.rs | 12 +++++------ aries_vcx/tests/utils/scenarios.rs | 31 ++++++++++++---------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index ef00e790d6..9478b02858 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -679,7 +679,7 @@ mod tests { &consumer_to_institution, &institution_to_consumer, ) - .await; + .await; #[cfg(feature = "migration")] institution.migrate().await; @@ -696,7 +696,7 @@ mod tests { }] } ])) - .unwrap(); + .unwrap(); info!( "test_proof_should_be_validated :: Going to seng proof request with attributes {}", @@ -710,7 +710,7 @@ mod tests { "{}", None, ) - .await; + .await; #[cfg(feature = "migration")] consumer.migrate().await; @@ -726,14 +726,14 @@ mod tests { &institution.agency_client, &institution_to_consumer, ) - .await - .unwrap(); + .await + .unwrap(); assert_eq!( verifier.get_verification_status(), PresentationVerificationStatus::Valid ); }) - .await; + .await; } #[tokio::test] diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index d16a5dfbe1..7224b7358a 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -1121,7 +1121,7 @@ pub mod test_utils { prover: &mut Prover, alice: &mut Alice, connection: &MediatedConnection, - requested_values: Option<&str>, + preselected_credentials: Option<&str>, ) -> SelectedCredentials { prover_update_with_mediator(prover, &alice.agency_client, connection) .await @@ -1132,15 +1132,10 @@ pub mod test_utils { .await .unwrap(); info!("prover_select_credentials >> retrieved_credentials: {retrieved_credentials:?}"); - let selected_credentials = match requested_values { - Some(requested_values) => { + let selected_credentials = match preselected_credentials { + Some(preselected_credentials) => { let credential_data = prover.presentation_request_data().unwrap(); - retrieved_to_selected_credentials_specific( - &retrieved_credentials, - requested_values, - &credential_data, - true, - ) + match_preselected_credentials(&retrieved_credentials, preselected_credentials, &credential_data, true) } _ => retrieved_to_selected_credentials_simple(&retrieved_credentials, true), }; @@ -1152,12 +1147,12 @@ pub mod test_utils { alice: &mut Alice, consumer_to_institution: &MediatedConnection, request_name: Option<&str>, - requested_values: Option<&str>, + preselected_credentials: Option<&str>, expected_prover_state: ProverState, ) { let mut prover = create_proof(alice, consumer_to_institution, request_name).await; let selected_credentials = - prover_select_credentials(&mut prover, alice, consumer_to_institution, requested_values).await; + prover_select_credentials(&mut prover, alice, consumer_to_institution, preselected_credentials).await; info!( "Prover :: Retrieved credential converted to selected: {:?}", &selected_credentials @@ -1170,13 +1165,13 @@ pub mod test_utils { consumer: &mut Alice, consumer_to_institution: &MediatedConnection, request_name: Option<&str>, - requested_values: Option<&str>, + preselected_credentials: Option<&str>, ) { prover_select_credentials_and_send_proof_and_assert( consumer, consumer_to_institution, request_name, - requested_values, + preselected_credentials, ProverState::PresentationSent, ) .await @@ -1393,9 +1388,9 @@ pub mod test_utils { return selected_credentials; } - pub fn retrieved_to_selected_credentials_specific( + pub fn match_preselected_credentials( retrieved_credentials: &RetrievedCredentials, - requested_values: &str, + preselected_credentials: &str, credential_data: &str, with_tails: bool, ) -> SelectedCredentials { @@ -1404,7 +1399,7 @@ pub mod test_utils { retrieved_credentials ); let credential_data: Value = serde_json::from_str(credential_data).unwrap(); - let requested_values: Value = serde_json::from_str(requested_values).unwrap(); + let preselected_credentials: Value = serde_json::from_str(preselected_credentials).unwrap(); let requested_attributes: &Value = &credential_data["requested_attributes"]; let mut selected_credentials = SelectedCredentials::default(); @@ -1415,8 +1410,8 @@ pub mod test_utils { .into_iter() .filter_map(|cred| { let attribute_name = requested_attributes[referent]["name"].as_str().unwrap(); - let requested_value = requested_values[attribute_name].as_str().unwrap(); - if cred.cred_info.attributes[attribute_name] == requested_value { + let preselected_credential = preselected_credentials[attribute_name].as_str().unwrap(); + if cred.cred_info.attributes[attribute_name] == preselected_credential { Some(cred) } else { None From 8e7a4ed5a9d4704060fac00951247a81c2e2aabc Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Tue, 29 Aug 2023 19:45:30 +0200 Subject: [PATCH 04/10] Remove prover_select_credentials_and_fail_to_generate_proof in favor of simpler testing approach Signed-off-by: Patrik Stas --- aries_vcx/tests/test_creds_proofs.rs | 14 ++++++++------ aries_vcx/tests/utils/scenarios.rs | 16 ---------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index 9478b02858..f8b58e44d5 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -587,10 +587,10 @@ mod tests { accept_cred_proposal, accept_cred_proposal_1, accept_offer, accept_proof_proposal, attr_names, create_and_send_nonrevocable_cred_offer, create_connected_connections, create_proof, decline_offer, generate_and_send_proof, issue_address_credential, prover_select_credentials, - prover_select_credentials_and_fail_to_generate_proof, prover_select_credentials_and_send_proof, - receive_proof_proposal_rejection, reject_proof_proposal, retrieved_to_selected_credentials_simple, - send_cred_proposal, send_cred_proposal_1, send_cred_req, send_credential, send_proof_proposal, - send_proof_proposal_1, send_proof_request, verifier_create_proof_and_send_request, verify_proof, + prover_select_credentials_and_send_proof, receive_proof_proposal_rejection, reject_proof_proposal, + retrieved_to_selected_credentials_simple, send_cred_proposal, send_cred_proposal_1, send_cred_req, + send_credential, send_proof_proposal, send_proof_proposal_1, send_proof_request, + verifier_create_proof_and_send_request, verify_proof, }; #[tokio::test] @@ -852,8 +852,10 @@ mod tests { #[cfg(feature = "migration")] consumer.migrate().await; - prover_select_credentials_and_fail_to_generate_proof(&mut consumer, &consumer_to_institution, None, None) - .await; + let mut prover = create_proof(&mut consumer, &consumer_to_institution, None).await; + let selected_credentials = + prover_select_credentials(&mut prover, &mut consumer, &consumer_to_institution, None).await; + assert!(selected_credentials.credential_for_referent.is_empty()); }) .await; } diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index 7224b7358a..b6559ba8cd 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -1177,22 +1177,6 @@ pub mod test_utils { .await } - pub async fn prover_select_credentials_and_fail_to_generate_proof( - consumer: &mut Alice, - consumer_to_institution: &MediatedConnection, - request_name: Option<&str>, - requested_values: Option<&str>, - ) { - prover_select_credentials_and_send_proof_and_assert( - consumer, - consumer_to_institution, - request_name, - requested_values, - ProverState::PresentationPreparationFailed, - ) - .await - } - pub async fn connect_using_request_sent_to_public_agent( alice: &mut Alice, faber: &mut Faber, From deaf8c261b18df3d90add4019c6d2d891a1c7415 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Tue, 29 Aug 2023 19:46:57 +0200 Subject: [PATCH 05/10] Simplify common testing case of sending proof Signed-off-by: Patrik Stas --- aries_vcx/tests/utils/scenarios.rs | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index b6559ba8cd..9171fb07ab 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -1143,12 +1143,11 @@ pub mod test_utils { selected_credentials } - pub async fn prover_select_credentials_and_send_proof_and_assert( + pub async fn prover_select_credentials_and_send_proof( alice: &mut Alice, consumer_to_institution: &MediatedConnection, request_name: Option<&str>, preselected_credentials: Option<&str>, - expected_prover_state: ProverState, ) { let mut prover = create_proof(alice, consumer_to_institution, request_name).await; let selected_credentials = @@ -1158,23 +1157,7 @@ pub mod test_utils { &selected_credentials ); generate_and_send_proof(alice, &mut prover, consumer_to_institution, selected_credentials).await; - assert_eq!(expected_prover_state, prover.get_state()); - } - - pub async fn prover_select_credentials_and_send_proof( - consumer: &mut Alice, - consumer_to_institution: &MediatedConnection, - request_name: Option<&str>, - preselected_credentials: Option<&str>, - ) { - prover_select_credentials_and_send_proof_and_assert( - consumer, - consumer_to_institution, - request_name, - preselected_credentials, - ProverState::PresentationSent, - ) - .await + assert_eq!(ProverState::PresentationSent, prover.get_state()); } pub async fn connect_using_request_sent_to_public_agent( From 26074c3a2bc4858d4aa4fe36655e0a34f16271f1 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Tue, 29 Aug 2023 20:00:32 +0200 Subject: [PATCH 06/10] Add test test_agency_pool_it_should_select_credentials_for_satisfiable_restriction Signed-off-by: Patrik Stas --- aries_vcx/tests/test_creds_proofs.rs | 115 +++++++++++---------------- 1 file changed, 45 insertions(+), 70 deletions(-) diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index f8b58e44d5..27e8cd7cf0 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -665,48 +665,41 @@ mod tests { #[tokio::test] #[ignore] - async fn test_agency_pool_proof_should_be_validated_even_if_at_least_one_of_restrictions_set_is_valid() { + async fn test_agency_pool_proof_with_predicates_should_be_validated() { SetupPoolDirectory::run(|setup| async move { let mut institution = create_faber_trustee(setup.genesis_file_path.clone()).await; let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; - let (schema_id, cred_def_id, _rev_reg_id, _cred_def, _rev_reg, _credential_handle) = - issue_address_credential( - &mut consumer, - &mut institution, - &consumer_to_institution, - &institution_to_consumer, - ) - .await; + issue_address_credential( + &mut consumer, + &mut institution, + &consumer_to_institution, + &institution_to_consumer, + ) + .await; #[cfg(feature = "migration")] institution.migrate().await; - let requested_attrs_string = serde_json::to_string(&json!([ + let requested_preds_string = serde_json::to_string(&json!([ { - "name": "address1", - "restrictions": [{ - "issuer_did": "abcdef0000000000000000" - }, - { - "issuer_did": institution.institution_did, - "schema_id": schema_id, - }] - } - ])) + "name": "zip", + "p_type": ">=", + "p_value": 83000 + }])) .unwrap(); info!( - "test_proof_should_be_validated :: Going to seng proof request with attributes {}", - &requested_attrs_string + "test_basic_proof :: Going to seng proof request with attributes {}", + &requested_preds_string ); let mut verifier = send_proof_request( &mut institution, &institution_to_consumer, - &requested_attrs_string, "[]", + &requested_preds_string, "{}", None, ) @@ -717,7 +710,7 @@ mod tests { prover_select_credentials_and_send_proof(&mut consumer, &consumer_to_institution, None, None).await; - info!("test_proof_should_be_validated :: verifier :: going to verify proof"); + info!("test_proof_with_predicates_should_be_validated :: verifier :: going to verify proof"); verifier_update_with_mediator( &mut verifier, &institution.profile.inject_wallet(), @@ -732,13 +725,17 @@ mod tests { verifier.get_verification_status(), PresentationVerificationStatus::Valid ); + info!( + "test_proof_with_predicates_should_be_validated :: verifier received presentation!: {}", + verifier.get_presentation_attachment().unwrap() + ); }) .await; } #[tokio::test] #[ignore] - async fn test_agency_pool_proof_with_predicates_should_be_validated() { + async fn test_agency_pool_it_should_fail_to_select_credentials_for_predicate() { SetupPoolDirectory::run(|setup| async move { let mut institution = create_faber_trustee(setup.genesis_file_path.clone()).await; let mut consumer = create_alice(setup.genesis_file_path).await; @@ -756,19 +753,14 @@ mod tests { #[cfg(feature = "migration")] institution.migrate().await; - let requested_preds_string = serde_json::to_string(&json!([ - { + let requested_preds_string = serde_json::to_string(&json!([{ "name": "zip", "p_type": ">=", - "p_value": 83000 + "p_value": 85000 }])) .unwrap(); - info!( - "test_basic_proof :: Going to seng proof request with attributes {}", - &requested_preds_string - ); - let mut verifier = send_proof_request( + send_proof_request( &mut institution, &institution_to_consumer, "[]", @@ -781,34 +773,18 @@ mod tests { #[cfg(feature = "migration")] consumer.migrate().await; - prover_select_credentials_and_send_proof(&mut consumer, &consumer_to_institution, None, None).await; - - info!("test_proof_with_predicates_should_be_validated :: verifier :: going to verify proof"); - verifier_update_with_mediator( - &mut verifier, - &institution.profile.inject_wallet(), - &institution.profile.inject_anoncreds_ledger_read(), - &institution.profile.inject_anoncreds(), - &institution.agency_client, - &institution_to_consumer, - ) - .await - .unwrap(); - assert_eq!( - verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - info!( - "test_proof_with_predicates_should_be_validated :: verifier received presentation!: {}", - verifier.get_presentation_attachment().unwrap() - ); + let mut prover = create_proof(&mut consumer, &consumer_to_institution, None).await; + let selected_credentials = + prover_select_credentials(&mut prover, &mut consumer, &consumer_to_institution, None).await; + assert!(selected_credentials.credential_for_referent.is_empty()); }) .await; } + #[tokio::test] #[ignore] - async fn test_agency_pool_it_should_fail_to_select_credentials_for_predicate() { + async fn test_agency_pool_it_should_select_credentials_for_satisfiable_restriction() { SetupPoolDirectory::run(|setup| async move { let mut institution = create_faber_trustee(setup.genesis_file_path.clone()).await; let mut consumer = create_alice(setup.genesis_file_path).await; @@ -821,33 +797,32 @@ mod tests { &consumer_to_institution, &institution_to_consumer, ) - .await; + .await; #[cfg(feature = "migration")] institution.migrate().await; - let requested_preds_string = serde_json::to_string(&json!([ + let requested_attrs_string = serde_json::to_string(&json!([ { - "name": "zip", - "p_type": ">=", - "p_value": 85000 + "name": "address1", + "restrictions": [{ + "issuer_did": "abcdef0000000000000000", + }, + { + "issuer_did": institution.institution_did, + }] }])) - .unwrap(); - - info!( - "test_basic_proof :: Going to seng proof request with attributes {}", - &requested_preds_string - ); + .unwrap(); send_proof_request( &mut institution, &institution_to_consumer, + &requested_attrs_string, "[]", - &requested_preds_string, "{}", None, ) - .await; + .await; #[cfg(feature = "migration")] consumer.migrate().await; @@ -855,9 +830,9 @@ mod tests { let mut prover = create_proof(&mut consumer, &consumer_to_institution, None).await; let selected_credentials = prover_select_credentials(&mut prover, &mut consumer, &consumer_to_institution, None).await; - assert!(selected_credentials.credential_for_referent.is_empty()); + assert_eq!(selected_credentials.credential_for_referent.is_empty(), false); }) - .await; + .await; } #[tokio::test] From dd2678a446e1ca50fa43271f789bcc1736a2543a Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Tue, 29 Aug 2023 20:16:21 +0200 Subject: [PATCH 07/10] Fix credential retrieval by prover Signed-off-by: Patrik Stas --- aries_vcx/tests/test_creds_proofs.rs | 15 ++++----------- aries_vcx_core/src/anoncreds/credx_anoncreds.rs | 11 ++++++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index 27e8cd7cf0..7c4cae49a8 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -781,7 +781,6 @@ mod tests { .await; } - #[tokio::test] #[ignore] async fn test_agency_pool_it_should_select_credentials_for_satisfiable_restriction() { @@ -797,10 +796,7 @@ mod tests { &consumer_to_institution, &institution_to_consumer, ) - .await; - - #[cfg(feature = "migration")] - institution.migrate().await; + .await; let requested_attrs_string = serde_json::to_string(&json!([ { @@ -812,7 +808,7 @@ mod tests { "issuer_did": institution.institution_did, }] }])) - .unwrap(); + .unwrap(); send_proof_request( &mut institution, @@ -822,17 +818,14 @@ mod tests { "{}", None, ) - .await; - - #[cfg(feature = "migration")] - consumer.migrate().await; + .await; let mut prover = create_proof(&mut consumer, &consumer_to_institution, None).await; let selected_credentials = prover_select_credentials(&mut prover, &mut consumer, &consumer_to_institution, None).await; assert_eq!(selected_credentials.credential_for_referent.is_empty(), false); }) - .await; + .await; } #[tokio::test] diff --git a/aries_vcx_core/src/anoncreds/credx_anoncreds.rs b/aries_vcx_core/src/anoncreds/credx_anoncreds.rs index 5d2fc34479..9182857af8 100644 --- a/aries_vcx_core/src/anoncreds/credx_anoncreds.rs +++ b/aries_vcx_core/src/anoncreds/credx_anoncreds.rs @@ -160,12 +160,13 @@ impl IndyCredxAnonCreds { let wql_query = if let Some(restrictions) = restrictions { match restrictions { - Value::Array(mut arr) => { - arr.extend(attrs); - json!({ "$and": arr }) + Value::Array(restrictions) => { + let restrictions_wql = json!({ "$or": restrictions }); + attrs.push(restrictions_wql); + json!({ "$and": attrs }) } - Value::Object(obj) => { - attrs.push(Value::Object(obj)); + Value::Object(restriction) => { + attrs.push(Value::Object(restriction)); json!({ "$and": attrs }) } _ => json!(attrs), From 0cbee98f935fb60d3bb858e04e202ba8d2664b1d Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Tue, 29 Aug 2023 21:50:55 +0200 Subject: [PATCH 08/10] Do not run test_agency_pool_it_should_fail_to_select_credentials_for_predicate for credx implementation Signed-off-by: Patrik Stas --- aries_vcx/tests/test_creds_proofs.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index 7c4cae49a8..d3ca1df5b5 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -733,6 +733,8 @@ mod tests { .await; } + // todo: credx implementation does not support checking credential value in respect to predicate + #[cfg(not(feature = "modular_libs"))] #[tokio::test] #[ignore] async fn test_agency_pool_it_should_fail_to_select_credentials_for_predicate() { @@ -776,6 +778,7 @@ mod tests { let mut prover = create_proof(&mut consumer, &consumer_to_institution, None).await; let selected_credentials = prover_select_credentials(&mut prover, &mut consumer, &consumer_to_institution, None).await; + assert!(selected_credentials.credential_for_referent.is_empty()); }) .await; From 4299e8c65f84f29f09fbcac479e371468bd869c9 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 30 Aug 2023 01:04:59 +0200 Subject: [PATCH 09/10] Address code review Signed-off-by: Patrik Stas --- aries_vcx_core/src/anoncreds/credx_anoncreds.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/aries_vcx_core/src/anoncreds/credx_anoncreds.rs b/aries_vcx_core/src/anoncreds/credx_anoncreds.rs index 9182857af8..1fc8239a59 100644 --- a/aries_vcx_core/src/anoncreds/credx_anoncreds.rs +++ b/aries_vcx_core/src/anoncreds/credx_anoncreds.rs @@ -169,10 +169,13 @@ impl IndyCredxAnonCreds { attrs.push(Value::Object(restriction)); json!({ "$and": attrs }) } - _ => json!(attrs), + _ => Err(AriesVcxCoreError::from_msg( + AriesVcxCoreErrorKind::InvalidInput, + "Invalid attribute restrictions (must be array or an object)", + ))?, } } else { - json!(attrs) + json!({ "$and": attrs }) }; let wql_query = serde_json::to_string(&wql_query)?; @@ -751,7 +754,7 @@ impl BaseAnonCreds for IndyCredxAnonCreds { .map(|v| v.try_as_str().map(_normalize_attr_name)) .collect::>()?, _ => Err(AriesVcxCoreError::from_msg( - AriesVcxCoreErrorKind::InvalidAttributesStructure, + AriesVcxCoreErrorKind::InvalidInput, "exactly one of 'name' or 'names' must be present", ))?, }; From ada697656720bbcaf97459d75046e0ecbe35a50e Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 30 Aug 2023 12:10:53 +0200 Subject: [PATCH 10/10] Revert CI change Signed-off-by: Patrik Stas --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d6baeb5c64..41b1f38b76 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -336,6 +336,7 @@ jobs: run: | cargo test --manifest-path="wallet_migrator/Cargo.toml"; RUST_TEST_THREADS=1 CARGO_INCREMENTAL=0 TEST_POOL_IP=127.0.0.1 cargo test --manifest-path="aries_vcx/Cargo.toml" -F migration --test test_creds_proofs -- --include-ignored; + RUST_TEST_THREADS=1 CARGO_INCREMENTAL=0 TEST_POOL_IP=127.0.0.1 cargo test --manifest-path="aries_vcx/Cargo.toml" -F migration --test test_creds_proofs_revocations -- --include-ignored; test-integration-libvcx: needs: workflow-setup