diff --git a/crates/rops/src/integration/age.rs b/crates/rops/src/integration/age.rs index c1705ea..339310a 100644 --- a/crates/rops/src/integration/age.rs +++ b/crates/rops/src/integration/age.rs @@ -106,6 +106,23 @@ mod key_id { rops_file_builder.age_key_ids.push(self) } } + + #[cfg(feature = "test-utils")] + mod mock { + use super::*; + + impl MockDisplayTestUtil for age::x25519::Recipient { + fn mock_display() -> String { + "age1se5ghfycr4n8kcwc3qwf234ymvmr2lex2a99wh8gpfx97glwt9hqch4569".to_string() + } + } + + impl MockTestUtil for age::x25519::Recipient { + fn mock() -> Self { + Self::mock_display().parse().unwrap() + } + } + } } pub use config::AgeConfig; @@ -142,7 +159,7 @@ mod config { impl MockTestUtil for AgeConfig { fn mock() -> Self { Self { - key_id: AgeIntegration::mock_key_id(), + key_id: MockTestUtil::mock(), } } } @@ -154,10 +171,6 @@ mod mock { use super::*; impl IntegrationTestUtils for AgeIntegration { - fn mock_key_id_str() -> impl AsRef { - "age1se5ghfycr4n8kcwc3qwf234ymvmr2lex2a99wh8gpfx97glwt9hqch4569" - } - fn mock_private_key_str() -> impl AsRef { "AGE-SECRET-KEY-1EQUCGFZH8UZKSZ0Z5N5T234YRNDT4U9H7QNYXWRRNJYDDVXE6FWSCPGNJ7" } diff --git a/crates/rops/src/integration/aws_kms/core.rs b/crates/rops/src/integration/aws_kms/core.rs index 8ded962..94dacaf 100644 --- a/crates/rops/src/integration/aws_kms/core.rs +++ b/crates/rops/src/integration/aws_kms/core.rs @@ -109,10 +109,6 @@ mod mock { use super::*; impl IntegrationTestUtils for AwsKmsIntegration { - fn mock_key_id_str() -> impl AsRef { - AwsKeyId::mock_display() - } - fn mock_private_key_str() -> impl AsRef { AwsPrivateKey::mock_display() } diff --git a/crates/rops/src/integration/test_suite.rs b/crates/rops/src/integration/test_suite.rs index ae3be8d..302f2c4 100644 --- a/crates/rops/src/integration/test_suite.rs +++ b/crates/rops/src/integration/test_suite.rs @@ -7,7 +7,7 @@ macro_rules! generate_integration_test_suite { #[test] fn parses_key_id() { - $integration::parse_key_id($integration::mock_key_id_str().as_ref()).unwrap(); + $integration::parse_key_id(&<$integration as Integration>::KeyId::mock_display()).unwrap(); } #[test] @@ -15,8 +15,9 @@ macro_rules! generate_integration_test_suite { $integration::set_mock_private_key_env_var(); let expected_data_key = DataKey::mock(); - let encrypted_data_key = $integration::encrypt_data_key(&$integration::mock_key_id(), &expected_data_key).unwrap(); - let found_data_key = $integration::decrypt_data_key(&$integration::mock_key_id(), &encrypted_data_key) + let encrypted_data_key = + $integration::encrypt_data_key(&<$integration as Integration>::KeyId::mock(), &expected_data_key).unwrap(); + let found_data_key = $integration::decrypt_data_key(&<$integration as Integration>::KeyId::mock(), &encrypted_data_key) .unwrap() .unwrap(); @@ -29,9 +30,12 @@ macro_rules! generate_integration_test_suite { assert_eq!( DataKey::mock(), - $integration::decrypt_data_key(&$integration::mock_key_id(), $integration::mock_encrypted_data_key_str()) - .unwrap() - .unwrap() + $integration::decrypt_data_key( + &<$integration as Integration>::KeyId::mock(), + $integration::mock_encrypted_data_key_str() + ) + .unwrap() + .unwrap() ); } diff --git a/crates/rops/src/integration/test_utils.rs b/crates/rops/src/integration/test_utils.rs index e6c0166..9a9371f 100644 --- a/crates/rops/src/integration/test_utils.rs +++ b/crates/rops/src/integration/test_utils.rs @@ -1,8 +1,6 @@ use crate::*; pub trait IntegrationTestUtils: Integration { - fn mock_key_id_str() -> impl AsRef; - fn mock_private_key_str() -> impl AsRef; fn mock_encrypted_data_key_str() -> &'static str; @@ -11,10 +9,6 @@ pub trait IntegrationTestUtils: Integration { std::env::set_var(Self::private_key_env_var_name(), Self::mock_private_key_str().as_ref()) } - fn mock_key_id() -> Self::KeyId { - Self::parse_key_id(Self::mock_key_id_str().as_ref()).unwrap() - } - fn mock_private_key() -> Self::PrivateKey { Self::parse_private_key(Self::mock_private_key_str()).unwrap() } diff --git a/crates/rops/src/rops_file/builder.rs b/crates/rops/src/rops_file/builder.rs index 76c8c79..2751b62 100644 --- a/crates/rops/src/rops_file/builder.rs +++ b/crates/rops/src/rops_file/builder.rs @@ -84,7 +84,7 @@ mod tests { RopsFileBuilder::::new(RopsFileFormatMap::::mock().into_inner_map()) .with_partial_encryption(MockTestUtil::mock()) .mac_only_encrypted() - .add_integration_key::(AgeIntegration::mock_key_id()) + .add_integration_key::(MockTestUtil::mock()) .encrypt::() .unwrap() .decrypt::() diff --git a/crates/rops/src/rops_file/format/json/mock.rs b/crates/rops/src/rops_file/format/json/mock.rs index 932f40f..df8d84d 100644 --- a/crates/rops/src/rops_file/format/json/mock.rs +++ b/crates/rops/src/rops_file/format/json/mock.rs @@ -181,7 +181,7 @@ mod metadata { {{ \"recipient\": \"{}\" }}", - AgeIntegration::mock_key_id_str().as_ref() + ::KeyId::mock_display() } } } diff --git a/crates/rops/src/rops_file/format/yaml/mock.rs b/crates/rops/src/rops_file/format/yaml/mock.rs index e085408..32f28ca 100644 --- a/crates/rops/src/rops_file/format/yaml/mock.rs +++ b/crates/rops/src/rops_file/format/yaml/mock.rs @@ -166,7 +166,7 @@ mod metadata { #[cfg(feature = "age")] impl MockFileFormatUtil for AgeConfig { fn mock_format_display() -> String { - format!("recipient: {}", AgeIntegration::mock_key_id_str().as_ref()) + format!("recipient: {}", ::KeyId::mock_display()) } }