Skip to content

Commit f0bded5

Browse files
committed
format
1 parent a0a4cf0 commit f0bded5

File tree

4 files changed

+86
-36
lines changed

4 files changed

+86
-36
lines changed

crates/atuin-desktop-runtime/src/ssh/integration_tests.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,7 @@ async fn test_auth_certificate_valid() {
552552
let key_path = test_keys_dir().join("id_ed25519_cert_only");
553553

554554
let mut session = Session::open(&host).await.expect("Failed to open session");
555-
let auth_result = session
556-
.key_auth(&test_user(), &test_host(), key_path)
557-
.await;
555+
let auth_result = session.key_auth(&test_user(), &test_host(), key_path).await;
558556

559557
assert!(
560558
auth_result.is_ok(),
@@ -588,9 +586,7 @@ async fn test_auth_certificate_expired_fallback() {
588586
let key_path = test_keys_dir().join("id_ed25519_expired_cert");
589587

590588
let mut session = Session::open(&host).await.expect("Failed to open session");
591-
let auth_result = session
592-
.key_auth(&test_user(), &test_host(), key_path)
593-
.await;
589+
let auth_result = session.key_auth(&test_user(), &test_host(), key_path).await;
594590

595591
assert!(
596592
auth_result.is_ok(),
@@ -606,9 +602,10 @@ async fn test_auth_certificate_expired_fallback() {
606602
);
607603

608604
// Check the warning type
609-
let has_expired_warning = auth_result.warnings.iter().any(|w| {
610-
matches!(w, SshWarning::CertificateExpired { .. })
611-
});
605+
let has_expired_warning = auth_result
606+
.warnings
607+
.iter()
608+
.any(|w| matches!(w, SshWarning::CertificateExpired { .. }));
612609
assert!(
613610
has_expired_warning,
614611
"Should have CertificateExpired warning, got: {:?}",
@@ -625,9 +622,7 @@ async fn test_auth_certificate_not_yet_valid_fallback() {
625622
let key_path = test_keys_dir().join("id_ed25519_future_cert");
626623

627624
let mut session = Session::open(&host).await.expect("Failed to open session");
628-
let auth_result = session
629-
.key_auth(&test_user(), &test_host(), key_path)
630-
.await;
625+
let auth_result = session.key_auth(&test_user(), &test_host(), key_path).await;
631626

632627
assert!(
633628
auth_result.is_ok(),
@@ -643,9 +638,10 @@ async fn test_auth_certificate_not_yet_valid_fallback() {
643638
);
644639

645640
// Check the warning type
646-
let has_future_warning = auth_result.warnings.iter().any(|w| {
647-
matches!(w, SshWarning::CertificateNotYetValid { .. })
648-
});
641+
let has_future_warning = auth_result
642+
.warnings
643+
.iter()
644+
.any(|w| matches!(w, SshWarning::CertificateNotYetValid { .. }));
649645
assert!(
650646
has_future_warning,
651647
"Should have CertificateNotYetValid warning, got: {:?}",
@@ -672,9 +668,7 @@ async fn test_auth_certificate_auto_detection() {
672668
let mut session = Session::open(&host).await.expect("Failed to open session");
673669

674670
// key_auth should automatically detect and use the certificate
675-
let auth_result = session
676-
.key_auth(&test_user(), &test_host(), key_path)
677-
.await;
671+
let auth_result = session.key_auth(&test_user(), &test_host(), key_path).await;
678672

679673
assert!(
680674
auth_result.is_ok(),

crates/atuin-desktop-runtime/src/ssh/pool.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ impl Pool {
9292
let async_session = async {
9393
let mut session = Session::open_with_config(host, ssh_config_override).await?;
9494
let auth_result = session
95-
.authenticate_with_config(auth, Some(&username), identity_key_config, certificate_config)
95+
.authenticate_with_config(
96+
auth,
97+
Some(&username),
98+
identity_key_config,
99+
certificate_config,
100+
)
96101
.await?;
97102
Ok::<_, eyre::Report>((session, auth_result))
98103
};

crates/atuin-desktop-runtime/src/ssh/session.rs

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,12 @@ impl Session {
659659
/// Public key or certificate authentication
660660
/// If a companion certificate file exists (e.g., id_ed25519-cert.pub), uses certificate auth
661661
/// Returns AuthResult containing any warnings from the authentication process
662-
pub async fn key_auth(&mut self, username: &str, host: &str, key_path: PathBuf) -> Result<AuthResult> {
662+
pub async fn key_auth(
663+
&mut self,
664+
username: &str,
665+
host: &str,
666+
key_path: PathBuf,
667+
) -> Result<AuthResult> {
663668
// Check if there's a companion certificate for this key
664669
if let Some(cert_path) = Self::find_certificate_for_key(&key_path).await {
665670
return self.cert_auth(username, host, key_path, cert_path).await;
@@ -739,11 +744,16 @@ impl Session {
739744
};
740745

741746
// Read certificate file content
742-
let cert_content = std::fs::read_to_string(&cert_path)
743-
.map_err(|e| eyre::eyre!("Failed to read certificate file {}: {e}", cert_path.display()))?;
747+
let cert_content = std::fs::read_to_string(&cert_path).map_err(|e| {
748+
eyre::eyre!(
749+
"Failed to read certificate file {}: {e}",
750+
cert_path.display()
751+
)
752+
})?;
744753

745754
let cert_source = cert_path.display().to_string();
746-
self.cert_auth_impl(username, host, key_pair, &cert_content, &cert_source).await
755+
self.cert_auth_impl(username, host, key_pair, &cert_content, &cert_source)
756+
.await
747757
}
748758

749759
/// Attempt public key authentication with an already-loaded key.
@@ -784,7 +794,9 @@ impl Session {
784794
.map_err(|e| eyre::eyre!("Failed to write temp certificate: {e}"))?;
785795

786796
// Guard ensures temp file is cleaned up on any exit path
787-
let _temp_guard = TempFileGuard { path: temp_cert_path.clone() };
797+
let _temp_guard = TempFileGuard {
798+
path: temp_cert_path.clone(),
799+
};
788800

789801
// Load the certificate
790802
let cert = match russh::keys::load_openssh_certificate(&temp_cert_path) {
@@ -886,10 +898,16 @@ impl Session {
886898

887899
match auth_res {
888900
russh::client::AuthResult::Success => {
889-
tracing::info!("✓ Certificate authentication successful with {}", cert_source);
901+
tracing::info!(
902+
"✓ Certificate authentication successful with {}",
903+
cert_source
904+
);
890905
Ok(AuthResult::default())
891906
}
892-
russh::client::AuthResult::Failure { remaining_methods, partial_success } => {
907+
russh::client::AuthResult::Failure {
908+
remaining_methods,
909+
partial_success,
910+
} => {
893911
tracing::warn!(
894912
"Server rejected certificate {} (remaining methods: {:?}, partial: {})",
895913
cert_source,
@@ -1014,7 +1032,10 @@ impl Session {
10141032
identity_files.len()
10151033
);
10161034
for identity_file in &identity_files {
1017-
if let Ok(auth_result) = self.key_auth(username, &hostname, identity_file.clone()).await {
1035+
if let Ok(auth_result) = self
1036+
.key_auth(username, &hostname, identity_file.clone())
1037+
.await
1038+
{
10181039
return Ok(auth_result);
10191040
}
10201041
}
@@ -1121,7 +1142,12 @@ impl Session {
11211142
tracing::info!("Step 0: Trying block-provided pasted key");
11221143
// For pasted key content with explicit certificate, use cert_auth_from_content
11231144
match self
1124-
.key_auth_from_content_with_cert(username, &hostname, content, certificate_config)
1145+
.key_auth_from_content_with_cert(
1146+
username,
1147+
&hostname,
1148+
content,
1149+
certificate_config,
1150+
)
11251151
.await
11261152
{
11271153
Ok(auth_result) => {
@@ -1139,7 +1165,12 @@ impl Session {
11391165
SshIdentityKeyConfig::Path { path } => {
11401166
tracing::info!("Step 0: Trying block-provided key path: {}", path);
11411167
match self
1142-
.key_auth_with_cert_config(username, &hostname, PathBuf::from(path), certificate_config)
1168+
.key_auth_with_cert_config(
1169+
username,
1170+
&hostname,
1171+
PathBuf::from(path),
1172+
certificate_config,
1173+
)
11431174
.await
11441175
{
11451176
Ok(auth_result) => {
@@ -1238,11 +1269,16 @@ impl Session {
12381269
cert_path: PathBuf,
12391270
) -> Result<AuthResult> {
12401271
// Read certificate file content and delegate to impl
1241-
let cert_content = std::fs::read_to_string(&cert_path)
1242-
.map_err(|e| eyre::eyre!("Failed to read certificate file {}: {e}", cert_path.display()))?;
1272+
let cert_content = std::fs::read_to_string(&cert_path).map_err(|e| {
1273+
eyre::eyre!(
1274+
"Failed to read certificate file {}: {e}",
1275+
cert_path.display()
1276+
)
1277+
})?;
12431278

12441279
let cert_source = cert_path.display().to_string();
1245-
self.cert_auth_impl(username, host, key_pair, &cert_content, &cert_source).await
1280+
self.cert_auth_impl(username, host, key_pair, &cert_content, &cert_source)
1281+
.await
12461282
}
12471283

12481284
/// Certificate auth with an already-loaded key pair and pasted certificate content
@@ -1254,7 +1290,8 @@ impl Session {
12541290
cert_content: &str,
12551291
) -> Result<AuthResult> {
12561292
// Delegate directly to impl with pasted content indicator
1257-
self.cert_auth_impl(username, host, key_pair, cert_content, "(pasted content)").await
1293+
self.cert_auth_impl(username, host, key_pair, cert_content, "(pasted content)")
1294+
.await
12581295
}
12591296

12601297
pub async fn disconnect(&self) -> Result<()> {

crates/atuin-desktop-runtime/src/ssh/ssh_pool.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ pub enum SshPoolMessage {
116116
// The actual result of the open_pty command
117117
// returns a channel to send input to the pty, plus any auth warnings
118118
#[allow(clippy::type_complexity)]
119-
reply_to: oneshot::Sender<Result<(mpsc::Sender<Bytes>, mpsc::Sender<(u16, u16)>, Vec<SshWarning>)>>,
119+
reply_to: oneshot::Sender<
120+
Result<(
121+
mpsc::Sender<Bytes>,
122+
mpsc::Sender<(u16, u16)>,
123+
Vec<SshWarning>,
124+
)>,
125+
>,
120126
},
121127
ClosePty {
122128
channel: String,
@@ -319,7 +325,11 @@ impl SshPoolHandle {
319325
output_stream: mpsc::Sender<String>,
320326
width: u16,
321327
height: u16,
322-
) -> Result<(mpsc::Sender<Bytes>, mpsc::Sender<(u16, u16)>, Vec<SshWarning>)> {
328+
) -> Result<(
329+
mpsc::Sender<Bytes>,
330+
mpsc::Sender<(u16, u16)>,
331+
Vec<SshWarning>,
332+
)> {
323333
self.open_pty_with_config(host, username, channel, output_stream, width, height, None)
324334
.await
325335
}
@@ -334,7 +344,11 @@ impl SshPoolHandle {
334344
width: u16,
335345
height: u16,
336346
ssh_config: Option<DocumentSshConfig>,
337-
) -> Result<(mpsc::Sender<Bytes>, mpsc::Sender<(u16, u16)>, Vec<SshWarning>)> {
347+
) -> Result<(
348+
mpsc::Sender<Bytes>,
349+
mpsc::Sender<(u16, u16)>,
350+
Vec<SshWarning>,
351+
)> {
338352
let (reply_sender, reply_receiver) = oneshot::channel();
339353

340354
let msg = SshPoolMessage::OpenPty {

0 commit comments

Comments
 (0)