Skip to content

Commit

Permalink
Merge pull request #438 from str4d/proptest
Browse files Browse the repository at this point in the history
Migrate from `quickcheck` to `proptest`
  • Loading branch information
str4d authored Jan 7, 2024
2 parents dd14a4e + b568e43 commit 3cd0ca2
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 78 deletions.
112 changes: 81 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions age/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ criterion = "0.5"
futures-test = "0.3"
hex = "0.4"
i18n-embed = { workspace = true, features = ["desktop-requester"] }
quickcheck = "1"
quickcheck_macros = "1"
proptest = "1"
test-case = "3"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Expand Down
45 changes: 22 additions & 23 deletions age/src/x25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ impl crate::Recipient for Recipient {
#[cfg(test)]
pub(crate) mod tests {
use age_core::secrecy::ExposeSecret;
use quickcheck::TestResult;
use quickcheck_macros::quickcheck;
use proptest::prelude::*;
use x25519_dalek::{PublicKey, StaticSecret};

use super::{Identity, Recipient};
Expand All @@ -255,27 +254,27 @@ pub(crate) mod tests {
assert_eq!(key.to_public().to_string(), TEST_PK);
}

#[quickcheck]
fn wrap_and_unwrap(sk_bytes: Vec<u8>) -> TestResult {
if sk_bytes.len() > 32 {
return TestResult::discard();
}

let file_key = [7; 16].into();
let sk = {
let mut tmp = [0; 32];
tmp[..sk_bytes.len()].copy_from_slice(&sk_bytes);
StaticSecret::from(tmp)
};

let stanzas = Recipient(PublicKey::from(&sk))
.wrap_file_key(&file_key)
.unwrap();
let res = Identity(sk).unwrap_stanzas(&stanzas);

match res {
Some(Ok(res)) => TestResult::from_bool(res.expose_secret() == file_key.expose_secret()),
_ => TestResult::from_bool(false),
proptest! {
#[test]
fn wrap_and_unwrap(sk_bytes in proptest::collection::vec(any::<u8>(), ..=32)) {
let file_key = [7; 16].into();
let sk = {
let mut tmp = [0; 32];
tmp[..sk_bytes.len()].copy_from_slice(&sk_bytes);
StaticSecret::from(tmp)
};

let stanzas = Recipient(PublicKey::from(&sk))
.wrap_file_key(&file_key);
prop_assert!(stanzas.is_ok());

let res = Identity(sk).unwrap_stanzas(&stanzas.unwrap());
prop_assert!(res.is_some());
let res = res.unwrap();
prop_assert!(res.is_ok());
let res = res.unwrap();

prop_assert_eq!(res.expose_secret(), file_key.expose_secret());
}
}
}
24 changes: 20 additions & 4 deletions supply-chain/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,16 @@ criteria = "safe-to-deploy"
version = "1.0.4"
criteria = "safe-to-deploy"

[[exemptions.quick-xml]]
version = "0.26.0"
[[exemptions.proptest]]
version = "1.2.0"
criteria = "safe-to-run"

[[exemptions.quickcheck]]
version = "1.0.3"
[[exemptions.quick-error]]
version = "1.2.3"
criteria = "safe-to-run"

[[exemptions.quick-xml]]
version = "0.26.0"
criteria = "safe-to-run"

[[exemptions.rand]]
Expand Down Expand Up @@ -605,6 +609,10 @@ criteria = "safe-to-deploy"
version = "0.38.28"
criteria = "safe-to-deploy"

[[exemptions.rusty-fork]]
version = "0.3.0"
criteria = "safe-to-run"

[[exemptions.ryu]]
version = "1.0.15"
criteria = "safe-to-run"
Expand Down Expand Up @@ -761,6 +769,10 @@ criteria = "safe-to-deploy"
version = "1.15.0"
criteria = "safe-to-deploy"

[[exemptions.unarray]]
version = "0.1.4"
criteria = "safe-to-run"

[[exemptions.unic-langid]]
version = "0.9.4"
criteria = "safe-to-deploy"
Expand All @@ -773,6 +785,10 @@ criteria = "safe-to-deploy"
version = "1.6.1"
criteria = "safe-to-run"

[[exemptions.wait-timeout]]
version = "0.2.0"
criteria = "safe-to-run"

[[exemptions.walkdir]]
version = "2.4.0"
criteria = "safe-to-deploy"
Expand Down
Loading

0 comments on commit 3cd0ca2

Please sign in to comment.