Skip to content

Commit

Permalink
Cosmetic changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Jan 13, 2025
1 parent e1549f8 commit b41fb88
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 47 deletions.
19 changes: 12 additions & 7 deletions cli/src/commands/invite/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ pub async fn main(args: Args) -> anyhow::Result<()> {
match ctx {
ShamirRecoveryClaimMaybeFinalizeCtx::Offline(ctx) => {
let retry = Select::new()
.default(0)
.with_prompt("Unable to join server, do you want to retry ?")
.items(&["yes", "no"])
.interact()?;

if retry == 0 {
// yes
device_ctx = ctx;
continue;
} else {
// no
return Err(anyhow!("Server offline, try again later."));
}
}
Expand Down Expand Up @@ -142,7 +145,7 @@ async fn step0(

let ctx = claimer_retrieve_info(Arc::new(config.into()), addr, None).await?;

handle.stop_with_newline();
handle.stop_with_symbol(GREEN_CHECKMARK);

Ok(ctx)
}
Expand All @@ -151,9 +154,10 @@ async fn step0(
fn shamir_pick_recipient(
ctx: &ShamirRecoveryClaimPickRecipientCtx,
) -> anyhow::Result<ShamirRecoveryClaimInitialCtx> {
let recipients = ctx.yet_to_contact_recipients();
let human_recipients: Vec<_> = recipients.iter().map(|r| r.human_handle.clone()).collect();
let recipients = ctx.recipients_without_a_share();
let human_recipients: Vec<&_> = recipients.iter().map(|r| &r.human_handle).collect();
let selection = Select::new()
.default(0)
.with_prompt("Choose a person to contact now")
.items(&human_recipients)
.interact()?;
Expand Down Expand Up @@ -208,7 +212,7 @@ async fn step1_shamir(

let ctx = ctx.do_wait_peer().await?;

handle.stop_with_newline();
handle.stop_with_symbol(GREEN_CHECKMARK);

Ok(ctx)
}
Expand Down Expand Up @@ -252,6 +256,7 @@ async fn step2_shamir(
let sas_codes = ctx.generate_greeter_sas_choices(3);

let selected_sas = Select::new()
.default(0)
.items(&sas_codes)
.with_prompt("Select code provided by greeter")
.interact()?;
Expand Down Expand Up @@ -291,7 +296,7 @@ async fn step3_shamir(

let ctx = ctx.do_wait_peer_trust().await?;

handle.stop_with_newline();
handle.stop_with_symbol(GREEN_CHECKMARK);

Ok(ctx)
}
Expand Down Expand Up @@ -349,7 +354,7 @@ async fn step4_shamir(

let ctx = ctx.do_recover_share().await?;

handle.stop_with_newline();
handle.stop_with_symbol(GREEN_CHECKMARK);

Ok(ctx)
}
Expand All @@ -364,7 +369,7 @@ async fn step5_shamir(

let ctx = ctx.recover_device(device_label).await?;

handle.stop_with_newline();
handle.stop_with_symbol(GREEN_CHECKMARK);

Ok(ctx)
}
Expand Down
7 changes: 4 additions & 3 deletions cli/src/commands/invite/greet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async fn step0(
None => return Err(anyhow::anyhow!("Invitation not found")),
};

handle.stop_with_newline();
handle.stop_with_symbol(GREEN_CHECKMARK);

Ok(invitation)
}
Expand Down Expand Up @@ -126,7 +126,7 @@ async fn step1_shamir(

let ctx = ctx.do_wait_peer().await?;

handle.stop_with_newline();
handle.stop_with_symbol(GREEN_CHECKMARK);

Ok(ctx)
}
Expand Down Expand Up @@ -176,7 +176,7 @@ async fn step2_shamir(

let ctx = ctx.do_wait_peer_trust().await?;

handle.stop_with_newline();
handle.stop_with_symbol(GREEN_CHECKMARK);

Ok(ctx)
}
Expand Down Expand Up @@ -217,6 +217,7 @@ async fn step3_shamir(
) -> anyhow::Result<ShamirRecoveryGreetInProgress3Ctx> {
let sas_codes = ctx.generate_claimer_sas_choices(3);
let selected_sas = Select::new()
.default(0)
.items(&sas_codes)
.with_prompt("Select code provided by claimer")
.interact()?;
Expand Down
7 changes: 6 additions & 1 deletion cli/src/commands/invite/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ crate::build_main_with_client!(main, list_invite);

pub async fn list_invite(_args: Args, client: &StartedClient) -> anyhow::Result<()> {
log::trace!("Listing invitations");
{
let mut spinner = start_spinner("Poll server for new certificates".into());
client.poll_server_for_new_certificates().await?;
spinner.stop_with_symbol(GREEN_CHECKMARK);
}

let mut handle = start_spinner("Listing invitations".into());

Expand All @@ -31,7 +36,7 @@ pub async fn list_invite(_args: Args, client: &StartedClient) -> anyhow::Result<
status,
token,
..
} => (token, status, format!("user (email={claimer_email}")),
} => (token, status, format!("user (email={claimer_email})")),
InviteListItem::Device { status, token, .. } => (token, status, "device".into()),
InviteListItem::ShamirRecovery {
status,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub const GREEN: &str = "\x1B[92m";
pub const RED: &str = "\x1B[91m";
pub const RESET: &str = "\x1B[39m";
pub const YELLOW: &str = "\x1B[33m";
pub const GREEN_CHECKMARK: &str = "\x1B[92m🗸\x1B[39m";
pub const GREEN_CHECKMARK: &str = "\x1B[92m\x1B[39m";
pub const BULLET_CHAR: &str = "•";

pub fn format_devices(
Expand Down
56 changes: 22 additions & 34 deletions cli/tests/integration/invitations/shared_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ use crate::{
testenv_utils::{TestOrganization, DEFAULT_DEVICE_PASSWORD},
};

macro_rules! match_sas_code {
($locked:ident, $sas_code:ident) => {
$locked.read_line().unwrap(); //empty line
let first = dbg!($locked.read_line().unwrap());
let second = dbg!($locked.read_line().unwrap());
let third = dbg!($locked.read_line().unwrap());

if $sas_code == first[first.len() - 4..] {
$locked.send_line("").unwrap();
} else if $sas_code == second[second.len() - 4..] {
$locked.send_line("j").unwrap();
} else if $sas_code == third[third.len() - 4..] {
$locked.send_line("jj").unwrap();
} else {
panic!("no corresponding sas code available")
}
};
}

#[rstest::rstest]
#[tokio::test]
async fn invite_shared_recovery_dance(tmp_path: TmpPath) {
Expand Down Expand Up @@ -70,12 +89,7 @@ async fn invite_shared_recovery_dance(tmp_path: TmpPath) {
// spawn claimer thread

let mut cmd_claimer = assert_cmd::Command::cargo_bin("parsec-cli").unwrap();
cmd_claimer.args([
"invite",
"claim",
invitation_addr.to_url().as_ref(),
"--password-stdin",
]);
cmd_claimer.args(["invite", "claim", invitation_addr.to_url().as_ref()]);

let program_claimer = cmd_claimer.get_program().to_str().unwrap().to_string();
let program_claimer = cmd_claimer
Expand Down Expand Up @@ -126,20 +140,7 @@ async fn invite_shared_recovery_dance(tmp_path: TmpPath) {
{
let mut locked = cloned_claimer.lock().unwrap();

dbg!(locked.read_line().unwrap()); //empty line
let first = dbg!(locked.read_line().unwrap());
let second = dbg!(locked.read_line().unwrap());
let third = dbg!(locked.read_line().unwrap());

if sas_code == first[first.len() - 4..] {
locked.send_line("j").unwrap();
} else if sas_code == second[second.len() - 4..] {
locked.send_line("jj").unwrap();
} else if sas_code == third[third.len() - 4..] {
locked.send_line("jjj").unwrap();
} else {
panic!("no corresponding sas code available")
}
match_sas_code!(locked, sas_code);
}

// retrieve claimer code
Expand All @@ -164,20 +165,7 @@ async fn invite_shared_recovery_dance(tmp_path: TmpPath) {
{
let mut locked = p_greeter.lock().unwrap();

dbg!(locked.read_line().unwrap()); //empty line
let first = dbg!(locked.read_line().unwrap());
let second = dbg!(locked.read_line().unwrap());
let third = dbg!(locked.read_line().unwrap());

if sas_code == first[first.len() - 4..] {
locked.send_line("j").unwrap();
} else if sas_code == second[second.len() - 4..] {
locked.send_line("jj").unwrap();
} else if sas_code == third[third.len() - 4..] {
locked.send_line("jjj").unwrap();
} else {
panic!("no corresponding sas code available")
}
match_sas_code!(locked, sas_code);
}
let mut greeter = Arc::<Mutex<PtySession>>::try_unwrap(p_greeter)
.ok()
Expand Down
2 changes: 1 addition & 1 deletion libparsec/crates/client/src/invite/claimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl ShamirRecoveryClaimPickRecipientCtx {
self.shamir_recovery_created_on
}

pub fn yet_to_contact_recipients(&self) -> Vec<&ShamirRecoveryRecipient> {
pub fn recipients_without_a_share(&self) -> Vec<&ShamirRecoveryRecipient> {
self.recipients
.iter()
.filter(|r| !self.shares.contains_key(&r.user_id))
Expand Down

0 comments on commit b41fb88

Please sign in to comment.