mirror of
https://github.com/veeso/termscp.git
synced 2026-04-02 08:12:19 -07:00
test: add parser and bookmark regression coverage
This commit is contained in:
@@ -839,6 +839,59 @@ mod tests {
|
||||
assert!(client.decrypt_str("bidoof").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_return_bookmark_when_password_decryption_fails() {
|
||||
let tmp_dir: tempfile::TempDir = TempDir::new().ok().unwrap();
|
||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||
let mut client =
|
||||
BookmarksClient::new(cfg_path.as_path(), key_path.as_path(), 16, true).unwrap();
|
||||
let mut bookmark = Bookmark::from(make_generic_ftparams(
|
||||
FileTransferProtocol::Sftp,
|
||||
"192.168.1.31",
|
||||
22,
|
||||
"pi",
|
||||
Some("mypassword"),
|
||||
));
|
||||
bookmark.password = Some(String::from("not-valid-base64"));
|
||||
client
|
||||
.hosts
|
||||
.bookmarks
|
||||
.insert(String::from("raspberry"), bookmark);
|
||||
|
||||
let bookmark = ftparams_to_tup(client.get_bookmark("raspberry").unwrap());
|
||||
|
||||
assert_eq!(bookmark.0, String::from("192.168.1.31"));
|
||||
assert_eq!(bookmark.1, 22);
|
||||
assert_eq!(bookmark.2, FileTransferProtocol::Sftp);
|
||||
assert_eq!(bookmark.3, String::from("pi"));
|
||||
assert_eq!(bookmark.4.as_deref(), Some("not-valid-base64"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_return_s3_bookmark_when_secret_decryption_fails() {
|
||||
let tmp_dir: tempfile::TempDir = TempDir::new().ok().unwrap();
|
||||
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||
let mut client =
|
||||
BookmarksClient::new(cfg_path.as_path(), key_path.as_path(), 16, true).unwrap();
|
||||
let mut bookmark = Bookmark::from(make_s3_ftparams());
|
||||
let s3 = bookmark.s3.as_mut().unwrap();
|
||||
s3.access_key = Some(String::from("bad-access-key"));
|
||||
s3.secret_access_key = Some(String::from("bad-secret-key"));
|
||||
client
|
||||
.hosts
|
||||
.bookmarks
|
||||
.insert(String::from("my-bucket"), bookmark);
|
||||
|
||||
let bookmark = client.get_bookmark("my-bucket").unwrap();
|
||||
let params = bookmark.params.s3_params().unwrap();
|
||||
|
||||
assert_eq!(bookmark.protocol, FileTransferProtocol::AwsS3);
|
||||
assert_eq!(params.bucket_name.as_str(), "omar");
|
||||
assert_eq!(params.region.as_deref(), Some("eu-west-1"));
|
||||
assert_eq!(params.access_key.as_deref(), Some("bad-access-key"));
|
||||
assert_eq!(params.secret_access_key.as_deref(), Some("bad-secret-key"));
|
||||
}
|
||||
|
||||
/// Get paths for configuration and key for bookmarks
|
||||
fn get_paths(dir: &Path) -> (PathBuf, PathBuf) {
|
||||
let k: PathBuf = PathBuf::from(dir);
|
||||
|
||||
@@ -382,6 +382,21 @@ mod tests {
|
||||
assert_eq!(params.password.as_str(), "password");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_should_parse_webdav_opt_with_at_in_password() {
|
||||
let result =
|
||||
parse_remote_opt("https://omar:p@ssword@myserver:4445/myshare/dir/subdir").unwrap();
|
||||
|
||||
let params = result.params.webdav_params().unwrap();
|
||||
assert_eq!(params.uri.as_str(), "https://myserver:4445");
|
||||
assert_eq!(params.username.as_str(), "omar");
|
||||
assert_eq!(params.password.as_str(), "p@ssword");
|
||||
assert_eq!(
|
||||
result.remote_path.as_deref().unwrap(),
|
||||
std::path::Path::new("/myshare/dir/subdir")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_reject_malformed_webdav_options() {
|
||||
let result = parse_remote_opt("https://omar@myserver:4445/myshare");
|
||||
@@ -389,6 +404,12 @@ mod tests {
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_reject_webdav_options_with_missing_credentials() {
|
||||
assert!(parse_remote_opt("https://:password@myserver:4445/myshare").is_err());
|
||||
assert!(parse_remote_opt("https://omar:@myserver:4445/myshare").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_aws_s3_opt() {
|
||||
// Simple
|
||||
|
||||
Reference in New Issue
Block a user