From 0a79fb368742d01caedcc3eee3c0872e6810c93f Mon Sep 17 00:00:00 2001 From: ChristianVisintin Date: Fri, 18 Dec 2020 11:40:51 +0100 Subject: [PATCH] Scp: when username was not provided, it didn't fallback to current username --- CHANGELOG.md | 1 + src/utils.rs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb87c87..c947f16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Released on ?? - MacOS: `/Users/Alice/Library/Application Support/termscp/bookmarks.toml` - Bugfix: - File mode of file on remote is now reported on local file after being downloaded (unix, linux, macos only) + - Scp: when username was not provided, it didn't fallback to current username ## 0.1.3 diff --git a/src/utils.rs b/src/utils.rs index ead6324..fa3b68d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -99,8 +99,8 @@ pub fn parse_remote_opt( } _ => return Err(String::from("Bad syntax")), // Too many tokens... } - // Set username to default if sftp - if protocol == FileTransferProtocol::Sftp { + // Set username to default if sftp or scp + if matches!(protocol, FileTransferProtocol::Sftp | FileTransferProtocol::Scp) { // Set username to current username username = Some(whoami::username()); } @@ -312,6 +312,14 @@ mod tests { assert_eq!(result.2, FileTransferProtocol::Ftp(false)); assert!(result.3.is_none()); // Doesn't fall back // Protocol + let result: (String, u16, FileTransferProtocol, Option) = + parse_remote_opt(&String::from("sftp://172.26.104.1")) + .ok() + .unwrap(); + assert_eq!(result.0, String::from("172.26.104.1")); + assert_eq!(result.1, 22); // Fallback to sftp default + assert_eq!(result.2, FileTransferProtocol::Sftp); + assert!(result.3.is_some()); // Doesn't fall back let result: (String, u16, FileTransferProtocol, Option) = parse_remote_opt(&String::from("scp://172.26.104.1")) .ok() @@ -319,7 +327,7 @@ mod tests { assert_eq!(result.0, String::from("172.26.104.1")); assert_eq!(result.1, 22); // Fallback to scp default assert_eq!(result.2, FileTransferProtocol::Scp); - assert!(result.3.is_none()); // Doesn't fall back + assert!(result.3.is_some()); // Doesn't fall back // Protocol + user let result: (String, u16, FileTransferProtocol, Option) = parse_remote_opt(&String::from("ftps://anon@172.26.104.1")) @@ -417,5 +425,10 @@ mod tests { align_text_center("hello world!", 24), String::from(" hello world!") ); + // Bad case + assert_eq!( + align_text_center("hello world!", 8), + String::from("hello world!") + ); } }