Add clean ups based on review feedback (#351)

* Add clean ups based on charcols suggestions
This commit is contained in:
Firstyear 2021-02-09 10:25:02 +10:00 committed by GitHub
parent 8006142c9e
commit a3d7401d03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 13 deletions

View file

@ -765,20 +765,19 @@ fn test_server_rest_totp_auth_lifecycle() {
.auth_password_totp("demo_account", "sohdi3iuHo6mai7noh0a", totp) .auth_password_totp("demo_account", "sohdi3iuHo6mai7noh0a", totp)
.is_ok()); .is_ok());
// Check a bad auth - needs to be second to prevent slocking // Check a bad auth - needs to be second as we are going to trigger the slock.
// Get a new connection // Get a new connection
let mut rsclient_bad = rsclient.new_session().unwrap(); let mut rsclient_bad = rsclient.new_session().unwrap();
assert!(rsclient_bad assert!(rsclient_bad
.auth_password_totp("demo_account", "sohdi3iuHo6mai7noh0a", 0) .auth_password_totp("demo_account", "sohdi3iuHo6mai7noh0a", 0)
.is_err()); .is_err());
// Delay by one second to allow the account to recover from the softlock.
std::thread::sleep(std::time::Duration::from_millis(1100));
// Remove TOTP on the account. // Remove TOTP on the account.
rsclient rsclient
.idm_account_primary_credential_remove_totp("demo_account") .idm_account_primary_credential_remove_totp("demo_account")
.unwrap(); // the result .unwrap();
// Delay by one second to allow the account to recover from the
// softlock.
std::thread::sleep(std::time::Duration::from_millis(1100));
// Check password auth. // Check password auth.
let mut rsclient_good = rsclient.new_session().unwrap(); let mut rsclient_good = rsclient.new_session().unwrap();
assert!(rsclient_good assert!(rsclient_good

View file

@ -307,8 +307,8 @@ impl AccountOpt {
} }
}; };
// display the tok. // display the token.
eprintln!("You should scan the follow QR code with your OTP App."); eprintln!("Scan the following QR code with your OTP app.");
let code = match QrCode::new(tok.to_uri().as_str()) { let code = match QrCode::new(tok.to_uri().as_str()) {
Ok(c) => c, Ok(c) => c,
@ -324,7 +324,7 @@ impl AccountOpt {
.build(); .build();
eprintln!("{}", image); eprintln!("{}", image);
eprintln!("Alternately, you can manually enter the following OTP details:"); eprintln!("Alternatively, you can manually enter the following OTP details:");
println!("Account Name: {}", tok.accountname); println!("Account Name: {}", tok.accountname);
println!("Issuer: {}", tok.issuer); println!("Issuer: {}", tok.issuer);
println!("Algorithm: {}", tok.algo.to_string()); println!("Algorithm: {}", tok.algo.to_string());

View file

@ -139,7 +139,13 @@ impl LoginOpt {
error!("Error during authentication init phase: Server offered no authentication mechanisms"); error!("Error during authentication init phase: Server offered no authentication mechanisms");
std::process::exit(1); std::process::exit(1);
} }
1 => unsafe { mechs.get_unchecked(0) }, 1 =>
{
#[allow(clippy::expect_used)]
mechs
.get(0)
.expect("can not fail - bounds already checked.")
}
len => { len => {
println!("Please choose how you want to authenticate:"); println!("Please choose how you want to authenticate:");
for (i, val) in mechs.iter().enumerate() { for (i, val) in mechs.iter().enumerate() {
@ -152,7 +158,10 @@ impl LoginOpt {
std::process::exit(1); std::process::exit(1);
} }
}; };
unsafe { mechs.get_unchecked(mech_idx as usize) } #[allow(clippy::expect_used)]
mechs
.get(mech_idx as usize)
.expect("can not fail - bounds already checked.")
} }
}; };
@ -175,7 +184,13 @@ impl LoginOpt {
); );
std::process::exit(1); std::process::exit(1);
} }
1 => unsafe { allowed.get_unchecked(0) }, 1 =>
{
#[allow(clippy::expect_used)]
allowed
.get(0)
.expect("can not fail - bounds already checked.")
}
len => { len => {
println!("Please choose what credential to provide:"); println!("Please choose what credential to provide:");
for (i, val) in allowed.iter().enumerate() { for (i, val) in allowed.iter().enumerate() {
@ -188,7 +203,10 @@ impl LoginOpt {
std::process::exit(1); std::process::exit(1);
} }
}; };
unsafe { allowed.get_unchecked(idx as usize) } #[allow(clippy::expect_used)]
allowed
.get(idx as usize)
.expect("can not fail - bounds already checked.")
} }
}; };

View file

@ -255,7 +255,7 @@ impl Account {
Ok(ModifyList::new_purge_and_set("primary_credential", vcred)) Ok(ModifyList::new_purge_and_set("primary_credential", vcred))
} }
None => { None => {
// No credential exists, we can't supplementy it. // No credential exists, we can't remove what is not real.
Err(OperationError::InvalidState) Err(OperationError::InvalidState)
} }
} }