mirror of
https://github.com/str4d/rage.git
synced 2025-04-04 19:37:51 +03:00
age: Run testkit test cases on async APIs
This commit is contained in:
parent
c9f67621d9
commit
14effef70b
3 changed files with 154 additions and 1 deletions
36
Cargo.lock
generated
36
Cargo.lock
generated
|
@ -93,6 +93,7 @@ dependencies = [
|
|||
"sha2 0.10.5",
|
||||
"subtle",
|
||||
"test-case",
|
||||
"tokio",
|
||||
"web-sys",
|
||||
"which",
|
||||
"wsl",
|
||||
|
@ -2285,6 +2286,16 @@ version = "1.9.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
|
@ -2526,6 +2537,31 @@ dependencies = [
|
|||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num_cpus",
|
||||
"once_cell",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.9"
|
||||
|
|
|
@ -97,6 +97,7 @@ i18n-embed = { version = "0.13", features = ["desktop-requester", "fluent-system
|
|||
quickcheck = "1"
|
||||
quickcheck_macros = "1"
|
||||
test-case = "2"
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
|
||||
[target.'cfg(unix)'.dev-dependencies]
|
||||
pprof = { version = "0.10", features = ["criterion", "flamegraph"] }
|
||||
|
@ -128,6 +129,10 @@ bench = false
|
|||
name = "test_vectors"
|
||||
required-features = ["ssh"]
|
||||
|
||||
[[test]]
|
||||
name = "testkit"
|
||||
required-features = ["async"]
|
||||
|
||||
[[bench]]
|
||||
name = "parser"
|
||||
harness = false
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
|||
};
|
||||
|
||||
use age::{secrecy::SecretString, x25519, DecryptError, Decryptor, Identity};
|
||||
use futures::AsyncReadExt;
|
||||
use sha2::{Digest, Sha256};
|
||||
use test_case::test_case;
|
||||
|
||||
|
@ -109,7 +110,118 @@ fn testkit(filename: &str) {
|
|||
}) {
|
||||
Ok(mut r) => {
|
||||
let mut payload = vec![];
|
||||
let res = r.read_to_end(&mut payload);
|
||||
let res = io::Read::read_to_end(&mut r, &mut payload);
|
||||
check_decrypt_success(filename, testfile, &comment, res, &payload);
|
||||
}
|
||||
Err(e) => check_decrypt_error(testfile, e),
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case("header_crlf")]
|
||||
#[test_case("hmac_bad")]
|
||||
#[test_case("hmac_extra_space")]
|
||||
#[test_case("hmac_garbage")]
|
||||
#[test_case("hmac_missing")]
|
||||
#[test_case("hmac_no_space")]
|
||||
#[test_case("hmac_not_canonical")]
|
||||
#[test_case("hmac_trailing_space")]
|
||||
#[test_case("hmac_truncated")]
|
||||
#[test_case("scrypt")]
|
||||
#[test_case("scrypt_and_x25519")]
|
||||
#[test_case("scrypt_bad_tag")]
|
||||
#[test_case("scrypt_double")]
|
||||
#[test_case("scrypt_extra_argument")]
|
||||
#[test_case("scrypt_long_file_key")]
|
||||
#[test_case("scrypt_no_match")]
|
||||
#[test_case("scrypt_not_canonical_body")]
|
||||
#[test_case("scrypt_not_canonical_salt")]
|
||||
#[test_case("scrypt_salt_long")]
|
||||
#[test_case("scrypt_salt_missing")]
|
||||
#[test_case("scrypt_salt_short")]
|
||||
#[test_case("scrypt_uppercase")]
|
||||
#[test_case("scrypt_work_factor_23")]
|
||||
#[test_case("scrypt_work_factor_hex")]
|
||||
#[test_case("scrypt_work_factor_leading_garbage")]
|
||||
#[test_case("scrypt_work_factor_leading_plus")]
|
||||
#[test_case("scrypt_work_factor_leading_zero_decimal")]
|
||||
#[test_case("scrypt_work_factor_leading_zero_octal")]
|
||||
#[test_case("scrypt_work_factor_missing")]
|
||||
#[test_case("scrypt_work_factor_negative")]
|
||||
#[test_case("scrypt_work_factor_overflow")]
|
||||
#[test_case("scrypt_work_factor_trailing_garbage")]
|
||||
#[test_case("scrypt_work_factor_wrong")]
|
||||
#[test_case("scrypt_work_factor_zero")]
|
||||
#[test_case("stanza_bad_start")]
|
||||
#[test_case("stanza_base64_padding")]
|
||||
#[test_case("stanza_empty_argument")]
|
||||
#[test_case("stanza_empty_body")]
|
||||
#[test_case("stanza_empty_last_line")]
|
||||
#[test_case("stanza_invalid_character")]
|
||||
#[test_case("stanza_long_line")]
|
||||
#[test_case("stanza_missing_body")]
|
||||
#[test_case("stanza_missing_final_line")]
|
||||
#[test_case("stanza_multiple_short_lines")]
|
||||
#[test_case("stanza_no_arguments")]
|
||||
#[test_case("stanza_not_canonical")]
|
||||
#[test_case("stanza_spurious_cr")]
|
||||
#[test_case("stanza_valid_characters")]
|
||||
#[test_case("stream_bad_tag")]
|
||||
#[test_case("stream_bad_tag_second_chunk")]
|
||||
#[test_case("stream_bad_tag_second_chunk_full")]
|
||||
#[test_case("stream_empty_payload")]
|
||||
#[test_case("stream_last_chunk_empty")]
|
||||
#[test_case("stream_last_chunk_full")]
|
||||
#[test_case("stream_last_chunk_full_second")]
|
||||
#[test_case("stream_missing_tag")]
|
||||
#[test_case("stream_no_chunks")]
|
||||
#[test_case("stream_no_final")]
|
||||
#[test_case("stream_no_final_full")]
|
||||
#[test_case("stream_no_final_two_chunks")]
|
||||
#[test_case("stream_no_final_two_chunks_full")]
|
||||
#[test_case("stream_no_nonce")]
|
||||
#[test_case("stream_short_chunk")]
|
||||
#[test_case("stream_short_nonce")]
|
||||
#[test_case("stream_short_second_chunk")]
|
||||
#[test_case("stream_three_chunks")]
|
||||
#[test_case("stream_trailing_garbage_long")]
|
||||
#[test_case("stream_trailing_garbage_short")]
|
||||
#[test_case("stream_two_chunks")]
|
||||
#[test_case("stream_two_final_chunks")]
|
||||
#[test_case("version_unsupported")]
|
||||
#[test_case("x25519")]
|
||||
#[test_case("x25519_bad_tag")]
|
||||
#[test_case("x25519_extra_argument")]
|
||||
#[test_case("x25519_grease")]
|
||||
#[test_case("x25519_identity")]
|
||||
#[test_case("x25519_long_file_key")]
|
||||
#[test_case("x25519_long_share")]
|
||||
#[test_case("x25519_lowercase")]
|
||||
#[test_case("x25519_low_order")]
|
||||
#[test_case("x25519_multiple_recipients")]
|
||||
#[test_case("x25519_no_match")]
|
||||
#[test_case("x25519_not_canonical_body")]
|
||||
#[test_case("x25519_not_canonical_share")]
|
||||
#[test_case("x25519_short_share")]
|
||||
#[tokio::test]
|
||||
async fn testkit_async(filename: &str) {
|
||||
let testfile = TestFile::parse(filename);
|
||||
let comment = format_testkit_comment(&testfile);
|
||||
|
||||
match Decryptor::new_async(&testfile.age_file[..])
|
||||
.await
|
||||
.and_then(|d| match d {
|
||||
Decryptor::Recipients(d) => {
|
||||
let identities = get_testkit_identities(filename, &testfile);
|
||||
d.decrypt_async(identities.iter().map(|i| i as &dyn Identity))
|
||||
}
|
||||
Decryptor::Passphrase(d) => {
|
||||
let passphrase = get_testkit_passphrase(&testfile, &comment);
|
||||
d.decrypt_async(&passphrase, Some(16))
|
||||
}
|
||||
}) {
|
||||
Ok(mut r) => {
|
||||
let mut payload = vec![];
|
||||
let res = AsyncReadExt::read_to_end(&mut r, &mut payload).await;
|
||||
check_decrypt_success(filename, testfile, &comment, res, &payload);
|
||||
}
|
||||
Err(e) => check_decrypt_error(testfile, e),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue