mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Scp: when username was not provided, it didn't fallback to current username
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
19
src/utils.rs
19
src/utils.rs
@@ -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!")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user