use std::process::Output;
use assert_cmd::cargo::cargo_bin_cmd;
use crate::util::create_state_dir_entry;
const CFG_PATH: &str = "./tests/testcases/keys/keys.in/keys.toml";
const CFG_PATH_WITH_CTOR: &str = "./tests/testcases/keys/conf/keys.toml";
const CLIENT_KEY: &str = " Keystore ID: arti
Role: ks_hsc_desc_enc
Summary: Descriptor decryption key
KeystoreItemType: X25519StaticKeypair
Location: client/mnyizjj7m3hpcr7i5afph3zt7maa65johyu2ruis6z7cmnjmaj3h6tad/ks_hsc_desc_enc.x25519_private
Extra info:
- hs_id: […]tad.onion
";
const UNRECOGNIZED_ENTRY: &str = " Unrecognized entry
Keystore ID: arti
Location: hss/allium-cepa/unrecognized-entry
Error: Key has invalid path: hss/allium-cepa/unrecognized-entry
";
const ID_KEY: &str = " Keystore ID: arti
Role: ks_hs_id
Summary: Long-term identity keypair
KeystoreItemType: Ed25519ExpandedKeypair
Location: hss/allium-cepa/ks_hs_id.ed25519_expanded_private
Extra info:
- nickname: allium-cepa
";
const UNRECOGNIZED_PATH: &str =
" Unrecognized path unrecognized-path-dir/ks_hs_id.ed25519_expanded_private";
const CTOR_SECRET: &str = "Keystore ID: ctor
Role: ks_hs_id
Summary: Long-term identity keypair
KeystoreItemType: Ed25519ExpandedKeypair
Location: hs_ed25519_secret_key
";
const CTOR_PUBLIC: &str = "Keystore ID: ctor
Role: kp_hs_id
Summary: Public part of the identity key
KeystoreItemType: Ed25519PublicKey
Location: hs_ed25519_public_key
";
const CTOR_HOSTNAME: &str = " Unrecognized entry
Keystore ID: ctor
Location: hostname
Error: Key hostname is malformed
";
const CTOR_UNRECOGNIZED_ENTRY: &str = " Unrecognized entry
Keystore ID: ctor
Location: hs_unrecognized_entry
Error: Key hs_unrecognized_entry is malformed
";
pub(super) const LIST_OUTPUT_ARTI: &[&str] =
&[CLIENT_KEY, UNRECOGNIZED_ENTRY, ID_KEY, UNRECOGNIZED_PATH];
pub(super) const LIST_OUTPUT_CTOR: &[&str] = &[
CTOR_HOSTNAME,
CTOR_SECRET,
CTOR_PUBLIC,
CTOR_UNRECOGNIZED_ENTRY,
];
#[derive(Debug, Clone, Default, Eq, PartialEq, derive_builder::Builder)]
pub(super) struct KeysListCmd {
#[builder(default)]
with_arti: bool,
#[builder(default)]
with_ctor: bool,
#[builder(default)]
keystore: Option<String>,
}
impl KeysListCmd {
pub(super) fn output(&self) -> std::io::Result<Output> {
let mut cmd = cargo_bin_cmd!("arti");
if self.with_ctor {
cmd.args(["-c", CFG_PATH_WITH_CTOR]);
} else {
cmd.args(["-c", CFG_PATH]);
}
let state_dir;
if !self.with_arti {
state_dir = tempfile::TempDir::new().unwrap();
let state_dir_path = state_dir.path().to_path_buf();
let state_dir_path = state_dir_path.to_str().unwrap();
let opt = create_state_dir_entry(state_dir_path);
cmd.args(["-o", &opt]);
}
cmd.args(["keys", "list"]);
if let Some(keystore_id) = &self.keystore {
cmd.args(["-k", keystore_id]);
}
cmd.output()
}
}
#[derive(Debug, Clone, Default, Eq, PartialEq, derive_builder::Builder)]
pub(super) struct KeysListKeystoreCmd {
#[builder(default)]
with_ctor: bool,
}
impl KeysListKeystoreCmd {
pub(super) fn output(&self) -> std::io::Result<Output> {
let mut cmd = cargo_bin_cmd!("arti");
if self.with_ctor {
cmd.args(["-c", CFG_PATH_WITH_CTOR]);
} else {
cmd.args(["-c", CFG_PATH]);
}
cmd.args(["keys", "list-keystores"]);
cmd.output()
}
}