Skip to content

Commit

Permalink
CLI shared recovery create - add test for interactive threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Dec 9, 2024
1 parent 703380d commit a68c67f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
1 change: 1 addition & 0 deletions .cspell/custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ Reqwest
rerunfailures
reseted
retrier
rexpect
Richcmp
Rlib
rmvb
Expand Down
35 changes: 33 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ regex = { version = "1.11.1", default-features = false }
regex-syntax = { version = "0.8.4", default-features = false }
reqwest = { version = "0.12.9", default-features = false }
reqwest-eventsource = { version = "0.6.0", default-features = false }
rexpect = "0.6.0"
rmp-serde = { version = "1.3.0", default-features = false }
rpassword = { version = "7.3.1", default-features = false }
rsa = { version = "0.8.2", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ libparsec = { workspace = true, features = ["cli-tests"] }

assert_cmd = { workspace = true }
predicates = { workspace = true, features = ["regex"] }
rexpect = { workspace = true }
rstest = { workspace = true }
uuid = { workspace = true, features = ["v6", "std", "rng"] }

Expand Down
33 changes: 31 additions & 2 deletions cli/tests/integration/shared_recovery/create.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use libparsec::{tmp_path, TmpPath};

use crate::testenv_utils::{TestOrganization, DEFAULT_DEVICE_PASSWORD};

use crate::integration_tests::bootstrap_cli_test;
use crate::testenv_utils::{TestOrganization, DEFAULT_DEVICE_PASSWORD};
use rexpect::session::spawn;

#[rstest::rstest]
#[tokio::test]
Expand Down Expand Up @@ -84,3 +84,32 @@ async fn create_shared_recovery_inexistent_email(tmp_path: TmpPath) {
)
.stderr(predicates::str::contains("A user is missing"));
}

#[rstest::rstest]
#[tokio::test]
async fn create_shared_recovery_default(tmp_path: TmpPath) {
let (_, TestOrganization { bob, .. }, _) = bootstrap_cli_test(&tmp_path).await.unwrap();
let mut cmd = assert_cmd::Command::cargo_bin("parsec-cli").unwrap();
cmd.args([
"shared-recovery",
"create",
"--device",
&bob.device_id.hex(),
]);

let program = cmd.get_program().to_str().unwrap().to_string();
let program = cmd
.get_args()
.fold(program, |acc, s| format!("{acc} {s:?}"));

let mut p = spawn(&dbg!(program), Some(1000)).unwrap();

p.exp_string("Enter password for the device:").unwrap();
p.send_line(DEFAULT_DEVICE_PASSWORD).unwrap();

p.exp_regex(".*The threshold is the minimum number of recipients that one must gather to recover the account:.*").unwrap();
p.send_line("1").unwrap();
p.exp_regex(".*Shared recovery setup has been created.*")
.unwrap();
p.exp_eof().unwrap();
}

0 comments on commit a68c67f

Please sign in to comment.