Scp: when username was not provided, it didn't fallback to current username

This commit is contained in:
ChristianVisintin
2020-12-18 11:40:51 +01:00
parent 900d9ac3c6
commit 0a79fb3687
2 changed files with 17 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ Released on ??
- MacOS: `/Users/Alice/Library/Application Support/termscp/bookmarks.toml` - MacOS: `/Users/Alice/Library/Application Support/termscp/bookmarks.toml`
- Bugfix: - Bugfix:
- File mode of file on remote is now reported on local file after being downloaded (unix, linux, macos only) - 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 ## 0.1.3

View File

@@ -99,8 +99,8 @@ pub fn parse_remote_opt(
} }
_ => return Err(String::from("Bad syntax")), // Too many tokens... _ => return Err(String::from("Bad syntax")), // Too many tokens...
} }
// Set username to default if sftp // Set username to default if sftp or scp
if protocol == FileTransferProtocol::Sftp { if matches!(protocol, FileTransferProtocol::Sftp | FileTransferProtocol::Scp) {
// Set username to current username // Set username to current username
username = Some(whoami::username()); username = Some(whoami::username());
} }
@@ -312,6 +312,14 @@ mod tests {
assert_eq!(result.2, FileTransferProtocol::Ftp(false)); assert_eq!(result.2, FileTransferProtocol::Ftp(false));
assert!(result.3.is_none()); // Doesn't fall back assert!(result.3.is_none()); // Doesn't fall back
// Protocol // Protocol
let result: (String, u16, FileTransferProtocol, Option<String>) =
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<String>) = let result: (String, u16, FileTransferProtocol, Option<String>) =
parse_remote_opt(&String::from("scp://172.26.104.1")) parse_remote_opt(&String::from("scp://172.26.104.1"))
.ok() .ok()
@@ -319,7 +327,7 @@ mod tests {
assert_eq!(result.0, String::from("172.26.104.1")); assert_eq!(result.0, String::from("172.26.104.1"));
assert_eq!(result.1, 22); // Fallback to scp default assert_eq!(result.1, 22); // Fallback to scp default
assert_eq!(result.2, FileTransferProtocol::Scp); 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 // Protocol + user
let result: (String, u16, FileTransferProtocol, Option<String>) = let result: (String, u16, FileTransferProtocol, Option<String>) =
parse_remote_opt(&String::from("ftps://anon@172.26.104.1")) parse_remote_opt(&String::from("ftps://anon@172.26.104.1"))
@@ -417,5 +425,10 @@ mod tests {
align_text_center("hello world!", 24), align_text_center("hello world!", 24),
String::from(" hello world!") String::from(" hello world!")
); );
// Bad case
assert_eq!(
align_text_center("hello world!", 8),
String::from("hello world!")
);
} }
} }