Skip to content

Commit

Permalink
Removed mocks from aries_vcx
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Mircea <[email protected]>
  • Loading branch information
bobozaur committed Oct 2, 2023
1 parent fa257f0 commit 2ac7f05
Show file tree
Hide file tree
Showing 27 changed files with 47 additions and 330 deletions.
4 changes: 2 additions & 2 deletions agents/rust/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use aries_vcx::{
core::profile::{ledger::VcxPoolConfig, vdrtools_profile::VdrtoolsProfile, Profile},
global::settings::{init_issuer_config, DEFAULT_LINK_SECRET_ALIAS},
global::settings::DEFAULT_LINK_SECRET_ALIAS,
};
use aries_vcx_core::{
self,
Expand Down Expand Up @@ -63,7 +63,7 @@ impl Agent {
let config_issuer = wallet_configure_issuer(wallet_handle, &init_config.enterprise_seed)
.await
.unwrap();
init_issuer_config(&config_issuer.institution_did).unwrap();

let wallet = Arc::new(IndySdkWallet::new(wallet_handle));

let pool_config = VcxPoolConfig {
Expand Down
4 changes: 0 additions & 4 deletions aries_vcx/src/common/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use serde_json::Value;
use crate::{
common::{keys::get_verkey_from_ledger, ledger::service_didsov::EndpointDidSov},
errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult},
global::settings,
handlers::util::AnyInvitation,
};

Expand Down Expand Up @@ -361,9 +360,6 @@ pub async fn clear_attr(
}

fn check_response(response: &str) -> VcxResult<()> {
if settings::indy_mocks_enabled() {
return Ok(());
}
match parse_response(response)? {
Response::Reply(_) => Ok(()),
Response::Reject(res) | Response::ReqNACK(res) => Err(AriesVcxError::from_msg(
Expand Down
12 changes: 1 addition & 11 deletions aries_vcx/src/common/primitives/credential_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ use aries_vcx_core::{

use crate::{
errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult},
global::settings::indy_mocks_enabled,
utils::{
constants::{CRED_DEF_ID, CRED_DEF_JSON, DEFAULT_SERIALIZE_VERSION},
serialization::ObjectWithVersion,
},
utils::{constants::DEFAULT_SERIALIZE_VERSION, serialization::ObjectWithVersion},
};

#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Default)]
Expand Down Expand Up @@ -85,9 +81,6 @@ async fn _try_get_cred_def_from_ledger(
issuer_did: &str,
cred_def_id: &str,
) -> VcxResult<Option<String>> {
if indy_mocks_enabled() {
return Ok(None);
}
match ledger.get_cred_def(cred_def_id, Some(issuer_did)).await {
Ok(cred_def) => Ok(Some(cred_def)),
Err(err) if err.kind() == AriesVcxCoreErrorKind::LedgerItemNotFound => Ok(None),
Expand Down Expand Up @@ -255,9 +248,6 @@ pub async fn generate_cred_def(
sig_type,
support_revocation
);
if indy_mocks_enabled() {
return Ok((CRED_DEF_ID.to_string(), CRED_DEF_JSON.to_string()));
}

let config_json =
json!({"support_revocation": support_revocation.unwrap_or(false)}).to_string();
Expand Down
26 changes: 1 addition & 25 deletions aries_vcx/src/common/primitives/credential_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ use aries_vcx_core::{
use super::credential_definition::PublicEntityStateType;
use crate::{
errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult},
global::settings,
utils::{
constants::{DEFAULT_SERIALIZE_VERSION, SCHEMA_ID, SCHEMA_JSON},
serialization::ObjectWithVersion,
},
utils::{constants::DEFAULT_SERIALIZE_VERSION, serialization::ObjectWithVersion},
};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -55,19 +51,6 @@ impl Schema {
data
);

if settings::indy_mocks_enabled() {
return Ok(Self {
source_id: source_id.to_string(),
version: version.to_string(),
submitter_did: submitter_did.to_string(),
schema_id: SCHEMA_ID.to_string(),
schema_json: SCHEMA_JSON.to_string(),
name: name.to_string(),
state: PublicEntityStateType::Built,
..Self::default()
});
}

let data_str = serde_json::to_string(data).map_err(|err| {
AriesVcxError::from_msg(
AriesVcxErrorKind::SerializationError,
Expand Down Expand Up @@ -122,13 +105,6 @@ impl Schema {
) -> VcxResult<Self> {
trace!("Schema::publish >>>");

if settings::indy_mocks_enabled() {
return Ok(Self {
state: PublicEntityStateType::Published,
..self
});
}

ledger
.publish_schema(&self.schema_json, &self.submitter_did, endorser_did)
.await?;
Expand Down
14 changes: 1 addition & 13 deletions aries_vcx/src/common/primitives/revocation_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use aries_vcx_core::{
};

use super::credential_definition::PublicEntityStateType;
use crate::{
errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult},
global::settings,
utils::constants::REV_REG_ID,
};
use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult};

#[derive(Clone, Deserialize, Debug, Serialize, PartialEq, Eq)]
pub struct RevocationRegistry {
Expand Down Expand Up @@ -302,14 +298,6 @@ pub async fn generate_rev_reg(
max_creds,
tag
);
if settings::indy_mocks_enabled() {
debug!("generate_rev_reg >>> returning mocked value");
return Ok((
REV_REG_ID.to_string(),
RevocationRegistryDefinition::default(),
"".to_string(),
));
}

let (rev_reg_id, rev_reg_def_json, rev_reg_entry_json) = anoncreds
.issuer_create_and_store_revoc_reg(issuer_did, cred_def_id, tails_dir, max_creds, tag)
Expand Down
6 changes: 1 addition & 5 deletions aries_vcx/src/common/proofs/verifier/verifier_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use aries_vcx_core::{
};
use serde_json::{self, Value};

use crate::{errors::error::prelude::*, global::settings, utils::openssl::encode};
use crate::{errors::error::prelude::*, utils::openssl::encode};

#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct CredInfoVerifier {
Expand Down Expand Up @@ -51,10 +51,6 @@ pub fn get_credential_info(proof: &str) -> VcxResult<Vec<CredInfoVerifier>> {
}

pub fn validate_proof_revealed_attributes(proof_json: &str) -> VcxResult<()> {
if settings::indy_mocks_enabled() {
return Ok(());
}

let proof: Value = serde_json::from_str(proof_json).map_err(|err| {
AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidJson,
Expand Down
158 changes: 0 additions & 158 deletions aries_vcx/src/global/settings.rs
Original file line number Diff line number Diff line change
@@ -1,167 +1,9 @@
use std::{collections::HashMap, sync::RwLock};

use crate::errors::error::prelude::*;

pub static CONFIG_SDK_TO_REMOTE_ROLE: &str = "sdk_to_remote_role";
pub static CONFIG_INSTITUTION_DID: &str = "institution_did";
pub static CONFIG_INSTITUTION_VERKEY: &str = "institution_verkey";

// functionally not used
pub static CONFIG_WEBHOOK_URL: &str = "webhook_url";
pub static CONFIG_ENABLE_TEST_MODE: &str = "enable_test_mode";
pub static CONFIG_GENESIS_PATH: &str = "genesis_path";
pub static CONFIG_LOG_CONFIG: &str = "log_config";
pub static CONFIG_EXPORTED_WALLET_PATH: &str = "exported_wallet_path";
pub static CONFIG_WALLET_KEY: &str = "wallet_key";
pub static CONFIG_WALLET_NAME: &str = "wallet_name";
pub static CONFIG_WALLET_TYPE: &str = "wallet_type";
pub static CONFIG_WALLET_KEY_DERIVATION: &str = "wallet_key_derivation";
pub static CONFIG_PROTOCOL_VERSION: &str = "protocol_version";
pub static CONFIG_TXN_AUTHOR_AGREEMENT: &str = "author_agreement";
pub static CONFIG_POOL_CONFIG: &str = "pool_config";
pub static CONFIG_DID_METHOD: &str = "did_method";
pub static DEFAULT_PROTOCOL_VERSION: usize = 2;
pub static MAX_SUPPORTED_PROTOCOL_VERSION: usize = 2;
pub static UNINITIALIZED_WALLET_KEY: &str = "<KEY_IS_NOT_SET>";
pub static DEFAULT_GENESIS_PATH: &str = "genesis.txn";
pub static DEFAULT_WALLET_NAME: &str = "LIBVCX_SDK_WALLET";
pub static DEFAULT_POOL_NAME: &str = "pool1";
pub static DEFAULT_LINK_SECRET_ALIAS: &str = "main";
pub static DEFAULT_DID: &str = "2hoqvcwupRTUNkXn6ArYzs";
pub static DEFAULT_ROLE: &str = "0";
pub static DEFAULT_WALLET_BACKUP_KEY: &str = "backup_wallet_key";
pub static DEFAULT_WALLET_KEY: &str = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY";
pub static MASK_VALUE: &str = "********";
pub static WALLET_KDF_RAW: &str = "RAW";
pub static WALLET_KDF_ARGON2I_INT: &str = "ARGON2I_INT";
pub static WALLET_KDF_ARGON2I_MOD: &str = "ARGON2I_MOD";
pub static WALLET_KDF_DEFAULT: &str = WALLET_KDF_ARGON2I_MOD;

lazy_static! {
static ref SETTINGS: RwLock<HashMap<String, String>> = RwLock::new(HashMap::new());
}

pub fn aries_vcx_enable_indy_mocks() -> VcxResult<()> {
debug!("enable_indy_mocks >>>");
set_config_value(CONFIG_ENABLE_TEST_MODE, "true")
}

pub fn aries_vcx_disable_indy_mocks() -> VcxResult<()> {
debug!("disable_indy_mocks >>>");
set_config_value(CONFIG_ENABLE_TEST_MODE, "false")
}

pub fn indy_mocks_enabled() -> bool {
let config = SETTINGS.read().expect("Unable to access SETTINGS");

match config.get(CONFIG_ENABLE_TEST_MODE) {
None => false,
Some(value) => {
debug!("indy_mocks_enabled >>> {}", value);
value == "true" || value == "indy"
}
}
}

pub fn get_config_value(key: &str) -> VcxResult<String> {
trace!("get_config_value >>> key: {}", key);

SETTINGS
.read()
.or(Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidConfiguration,
"Cannot read settings",
)))?
.get(key)
.map(|v| v.to_string())
.ok_or(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidConfiguration,
format!("Cannot read \"{}\" from settings", key),
))
}

pub fn set_config_value(key: &str, value: &str) -> VcxResult<()> {
trace!("set_config_value >>> key: {}, value: {}", key, value);
SETTINGS
.write()
.or(Err(AriesVcxError::from_msg(
AriesVcxErrorKind::UnknownError,
"Cannot write settings",
)))?
.insert(key.to_string(), value.to_string());
Ok(())
}

pub fn reset_config_values_ariesvcx() -> VcxResult<()> {
trace!("reset_config_values >>>");
let mut config = SETTINGS.write()?;
config.clear();
Ok(())
}

pub fn get_protocol_version() -> usize {
let protocol_version = match get_config_value(CONFIG_PROTOCOL_VERSION) {
Ok(ver) => ver.parse::<usize>().unwrap_or_else(|err| {
warn!(
"Can't parse value of protocol version from config ({}), use default one ({})",
err, DEFAULT_PROTOCOL_VERSION
);
DEFAULT_PROTOCOL_VERSION
}),
Err(err) => {
info!(
"Can't fetch protocol version from config ({}), use default one ({})",
err, DEFAULT_PROTOCOL_VERSION
);
DEFAULT_PROTOCOL_VERSION
}
};
if protocol_version > MAX_SUPPORTED_PROTOCOL_VERSION {
error!(
"Protocol version from config {}, greater then maximal supported {}, use maximum one",
protocol_version, MAX_SUPPORTED_PROTOCOL_VERSION
);
MAX_SUPPORTED_PROTOCOL_VERSION
} else {
protocol_version
}
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
pub mod unit_tests {
use super::*;
use crate::utils::devsetup::SetupDefaults;

fn _pool_config() -> String {
r#"{"timeout":40}"#.to_string()
}

fn _mandatory_config() -> HashMap<String, String> {
let mut config: HashMap<String, String> = HashMap::new();
config.insert(CONFIG_WALLET_KEY.to_string(), "password".to_string());
config
}

#[test]
fn test_get_and_set_values() {
let _setup = SetupDefaults::init();

let key = "key1".to_string();
let value1 = "value1".to_string();

// Fails with invalid key
assert_eq!(
get_config_value(&key).unwrap_err().kind(),
AriesVcxErrorKind::InvalidConfiguration
);

set_config_value(&key, &value1).unwrap();
assert_eq!(get_config_value(&key).unwrap(), value1);
}
}

pub fn init_issuer_config(institution_did: &str) -> VcxResult<()> {
set_config_value(CONFIG_INSTITUTION_DID, institution_did)?;
Ok(())
}
7 changes: 0 additions & 7 deletions aries_vcx/src/handlers/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ pub(crate) use make_attach_from_str;
pub(crate) use matches_opt_thread_id;
pub(crate) use matches_thread_id;

use crate::global::settings;

pub fn verify_thread_id(thread_id: &str, message: &AriesMessage) -> VcxResult<()> {
// todo: ultimately remove this - improve tests
// libvcx_core unit tests are passing in hardcoded message which have mismatching thid
if settings::indy_mocks_enabled() {
return Ok(());
}
let is_match = match message {
AriesMessage::BasicMessage(msg) => matches_opt_thread_id!(msg, thread_id),
AriesMessage::Connection(Connection::Invitation(msg)) => msg.id == thread_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use messages::msg_fields::protocols::{
use crate::{
common::proofs::verifier::validate_indy_proof,
errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult},
global::settings,
handlers::util::{get_attach_as_string, matches_thread_id, Status},
protocols::proof_presentation::verifier::{
states::finished::FinishedState, verification_status::PresentationVerificationStatus,
Expand All @@ -29,7 +28,7 @@ impl PresentationRequestSentState {
presentation: &Presentation,
thread_id: &str,
) -> VcxResult<()> {
if !settings::indy_mocks_enabled() && !matches_thread_id!(presentation, thread_id) {
if !matches_thread_id!(presentation, thread_id) {
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidJson,
format!(
Expand Down
Loading

0 comments on commit 2ac7f05

Please sign in to comment.